Skip to content
This repository was archived by the owner on Mar 12, 2026. It is now read-only.

Commit 73e3615

Browse files
mattellisaknysh
authored andcommitted
Add aws_session_token argument, to enable use of temp AWS credentials (#26)
* - Add `aws_session_token` argument to program, to enable use of temporary AWS credentials * Fix spacing * Whitespace should be tab
1 parent 69a11e0 commit 73e3615

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
var (
1919
awsAccessKeyId = flag.String("aws_access_key_id", os.Getenv("AWS_ACCESS_KEY_ID"), "AWS access key Id with permissions to publish CloudWatch metrics")
2020
awsSecretAccessKey = flag.String("aws_secret_access_key", os.Getenv("AWS_SECRET_ACCESS_KEY"), "AWS secret access key with permissions to publish CloudWatch metrics")
21+
awsSessionToken = flag.String("aws_session_token", os.Getenv("AWS_SESSION_TOKEN"), "AWS session token with permissions to publish CloudWatch metrics")
2122
cloudWatchNamespace = flag.String("cloudwatch_namespace", os.Getenv("CLOUDWATCH_NAMESPACE"), "CloudWatch Namespace")
2223
cloudWatchRegion = flag.String("cloudwatch_region", os.Getenv("CLOUDWATCH_REGION"), "CloudWatch Region")
2324
cloudWatchPublishTimeout = flag.String("cloudwatch_publish_timeout", os.Getenv("CLOUDWATCH_PUBLISH_TIMEOUT"), "CloudWatch publish timeout in seconds")
@@ -172,6 +173,7 @@ func main() {
172173
PrometheusSkipServerCertCheck: skipCertCheck,
173174
AwsAccessKeyId: *awsAccessKeyId,
174175
AwsSecretAccessKey: *awsSecretAccessKey,
176+
AwsSessionToken: *awsSessionToken,
175177
AdditionalDimensions: additionalDimensions,
176178
ReplaceDimensions: replaceDims,
177179
IncludeMetrics: includeMetricsList,

prometheus_to_cloudwatch.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ type Config struct {
6464
// AWS secret access key with permissions to publish CloudWatch metrics
6565
AwsSecretAccessKey string
6666

67+
// AWS session token with permissions to publish CloudWatch metrics
68+
AwsSessionToken string
69+
6770
// Required. The CloudWatch namespace under which metrics should be published
6871
CloudWatchNamespace string
6972

@@ -174,7 +177,8 @@ func NewBridge(c *Config) (*Bridge, error) {
174177
// If credentials are not provided in the variables, the chain of credential providers will search for credentials
175178
// in environment variables, the shared credential file, and EC2 Instance Roles
176179
if c.AwsAccessKeyId != "" && c.AwsSecretAccessKey != "" {
177-
config.Credentials = credentials.NewStaticCredentials(c.AwsAccessKeyId, c.AwsSecretAccessKey, "")
180+
// Utilise AWS session token if one is provided (Required for temporary AWS credentials)
181+
config.Credentials = credentials.NewStaticCredentials(c.AwsAccessKeyId, c.AwsSecretAccessKey, c.AwsSessionToken)
178182
}
179183

180184
sess, err := session.NewSession(config)

0 commit comments

Comments
 (0)