@@ -62,7 +62,7 @@ func (bk *customTemplateS3Bucket) Update(ctx context.Context) {
6262func NewS3Providers (options * types.Options ) ([]* customTemplateS3Bucket , error ) {
6363 providers := []* customTemplateS3Bucket {}
6464 if options .AwsBucketName != "" && ! options .AwsTemplateDisableDownload {
65- s3c , err := getS3Client (context .TODO (), options .AwsAccessKey , options .AwsSecretKey , options .AwsRegion )
65+ s3c , err := getS3Client (context .TODO (), options .AwsAccessKey , options .AwsSecretKey , options .AwsRegion , options . AwsProfile )
6666 if err != nil {
6767 return nil , errorutil .NewWithErr (err ).Msgf ("error downloading s3 bucket %s" , options .AwsBucketName )
6868 }
@@ -104,10 +104,24 @@ func downloadToFile(downloader *manager.Downloader, targetDirectory, bucket, key
104104 return err
105105}
106106
107- func getS3Client (ctx context.Context , accessKey string , secretKey string , region string ) (* s3.Client , error ) {
108- cfg , err := config .LoadDefaultConfig (ctx , config .WithCredentialsProvider (credentials .NewStaticCredentialsProvider (accessKey , secretKey , "" )), config .WithRegion (region ))
109- if err != nil {
110- return nil , err
107+ func getS3Client (ctx context.Context , accessKey string , secretKey string , region string , profile string ) (* s3.Client , error ) {
108+ var cfg aws.Config
109+ var err error
110+ if profile != "" {
111+ cfg , err = config .LoadDefaultConfig (ctx , config .WithSharedConfigProfile (profile ))
112+ if err != nil {
113+ return nil , err
114+ }
115+ } else if accessKey != "" && secretKey != "" {
116+ cfg , err = config .LoadDefaultConfig (ctx , config .WithCredentialsProvider (credentials .NewStaticCredentialsProvider (accessKey , secretKey , "" )), config .WithRegion (region ))
117+ if err != nil {
118+ return nil , err
119+ }
120+ } else {
121+ cfg , err = config .LoadDefaultConfig (ctx )
122+ if err != nil {
123+ return nil , err
124+ }
111125 }
112126 return s3 .NewFromConfig (cfg ), nil
113127}
0 commit comments