diff --git a/commands/check.go b/commands/check.go index 646ffba..92876ce 100644 --- a/commands/check.go +++ b/commands/check.go @@ -49,7 +49,7 @@ func (c *Check) Execute() error { return fmt.Errorf("invalid payload: %s", err) } - if req.Source.AwsAccessKeyId != "" && req.Source.AwsSecretAccessKey != "" && req.Source.AwsRegion != "" { + if req.Source.AwsRegion != "" { if !req.Source.AuthenticateToECR() { return fmt.Errorf("cannot authenticate with ECR") } diff --git a/commands/in.go b/commands/in.go index cbffa4e..c6e7143 100644 --- a/commands/in.go +++ b/commands/in.go @@ -65,7 +65,7 @@ func (i *In) Execute() error { dest := i.args[1] - if req.Source.AwsAccessKeyId != "" && req.Source.AwsSecretAccessKey != "" && req.Source.AwsRegion != "" { + if req.Source.AwsRegion != "" { if !req.Source.AuthenticateToECR() { return fmt.Errorf("cannot authenticate with ECR") } diff --git a/commands/out.go b/commands/out.go index 6ce2a3d..3fd699f 100644 --- a/commands/out.go +++ b/commands/out.go @@ -63,7 +63,7 @@ func (o *Out) Execute() error { src := o.args[1] - if req.Source.AwsAccessKeyId != "" && req.Source.AwsSecretAccessKey != "" && req.Source.AwsRegion != "" { + if req.Source.AwsRegion != "" { if !req.Source.AuthenticateToECR() { return fmt.Errorf("cannot authenticate with ECR") } diff --git a/types.go b/types.go index 9f77514..446c175 100644 --- a/types.go +++ b/types.go @@ -285,10 +285,18 @@ func (source *Source) AuthenticateToECR() bool { return false } - mySession := session.Must(session.NewSession(&aws.Config{ - Region: aws.String(source.AwsRegion), - Credentials: credentials.NewStaticCredentials(source.AwsAccessKeyId, source.AwsSecretAccessKey, source.AwsSessionToken), - })) + var sessionConfig aws.Config + if source.AwsAccessKeyId != "" && source.AwsSecretAccessKey != "" { + sessionConfig = aws.Config{ + Region: aws.String(source.AwsRegion), + Credentials: credentials.NewStaticCredentials(source.AwsAccessKeyId, source.AwsSecretAccessKey, ""), + } + } else { + sessionConfig = aws.Config{ + Region: aws.String(source.AwsRegion), + } + } + mySession := session.Must(session.NewSession(&sessionConfig)) // Note: This implementation gives precedence to `aws_role_arn` since it // assumes that we've errored if both `aws_role_arn` and `aws_role_arns`