Skip to content

Commit 0e7f5a1

Browse files
aveprjprobinson
authored andcommitted
Add AWS_SESSION_TOKEN into aws.Config to allow using temporary credentials (#154)
* Add AWS_SESSION_TOKEN to allow using temp credentials Currently, using temp credentials is only possible via environment. If one requires to configure the client in code, there is no way to specify session token. * Update NewPublisher to make use of session token Subscriber constructor was modified to make use of newly added SessionToken field in the config. The publisher was missed out. Fixing this injustice...
1 parent ec37f5d commit 0e7f5a1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

config/aws/aws.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ const (
2222
type (
2323
// Config holds common AWS credentials and keys.
2424
Config struct {
25-
AccessKey string `envconfig:"AWS_ACCESS_KEY"`
25+
AccessKey string `envconfig:"AWS_ACCESS_KEY"`
2626
MFASerialNumber string `envconfig:"AWS_MFA_SERIAL_NUMBER"`
27-
Region string `envconfig:"AWS_REGION"`
28-
RoleARN string `envconfig:"AWS_ROLE_ARN"`
29-
SecretKey string `envconfig:"AWS_SECRET_KEY"`
27+
Region string `envconfig:"AWS_REGION"`
28+
RoleARN string `envconfig:"AWS_ROLE_ARN"`
29+
SecretKey string `envconfig:"AWS_SECRET_KEY"`
30+
SessionToken string `envconfig:"AWS_SESSION_TOKEN"`
3031
}
3132

3233
// S3 holds the info required to work with Amazon S3.

pubsub/aws/aws.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewPublisher(cfg SNSConfig) (pubsub.Publisher, error) {
4545

4646
var creds *credentials.Credentials
4747
if cfg.AccessKey != "" {
48-
creds = credentials.NewStaticCredentials(cfg.AccessKey, cfg.SecretKey, "")
48+
creds = credentials.NewStaticCredentials(cfg.AccessKey, cfg.SecretKey, cfg.SessionToken)
4949
} else {
5050
creds = credentials.NewEnvCredentials()
5151
}
@@ -202,7 +202,7 @@ func NewSubscriber(cfg SQSConfig) (pubsub.Subscriber, error) {
202202

203203
var creds *credentials.Credentials
204204
if cfg.AccessKey != "" {
205-
creds = credentials.NewStaticCredentials(cfg.AccessKey, cfg.SecretKey, "")
205+
creds = credentials.NewStaticCredentials(cfg.AccessKey, cfg.SecretKey, cfg.SessionToken)
206206
} else {
207207
creds = credentials.NewEnvCredentials()
208208
}

0 commit comments

Comments
 (0)