bugfix s3 bucket name

This commit is contained in:
kkb0318
2024-04-24 22:45:24 +09:00
parent 3473c3de2d
commit a3146982cb
5 changed files with 34 additions and 21 deletions
+1
View File
@@ -113,6 +113,7 @@ func (a *AwsS3Client) PutObjectPublic(ctx context.Context, input ObjectInput) er
// CreateBucketPublic creates a new S3 bucket with public access settings in the specified region.
// The function configures the bucket to have its ownership controlled by the bucket creator.
func (a *AwsS3Client) CreateBucketPublic(ctx context.Context) error {
log.Printf("creating S3 bucket... Name: %s, Region: %s \n", a.bucketName, a.Region())
bucket := aws.String(a.bucketName)
_, err := a.Client.CreateBucket(ctx, &s3.CreateBucketInput{
Bucket: bucket,
+13 -4
View File
@@ -3,8 +3,11 @@ package client
import (
"context"
"fmt"
"os"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/sts"
@@ -35,6 +38,12 @@ func NewAwsClientFactory(ctx context.Context) (*AwsClientFactory, error) {
if err != nil {
return nil, fmt.Errorf("unable to load SDK config, %w", err)
}
roleArn := os.Getenv("AWS_ROLE_ARN")
if roleArn != "" {
stsSvc := sts.NewFromConfig(cfg)
creds := stscreds.NewAssumeRoleProvider(stsSvc, roleArn)
cfg.Credentials = aws.NewCredentialsCache(creds)
}
return &AwsClientFactory{config: cfg}, nil
}
@@ -50,10 +59,10 @@ func (a *AwsClientFactory) StsClient() *AwsStsClient {
}
}
func (a *AwsClientFactory) S3Client(bucketName, region string) *AwsS3Client {
func (a *AwsClientFactory) S3Client(region, bucketName string) *AwsS3Client {
return &AwsS3Client{
s3.NewFromConfig(a.config),
region,
bucketName,
Client: s3.NewFromConfig(a.config),
region: region,
bucketName: bucketName,
}
}