From 5875d4a78c17eed7cd3a38d80f40560ec5d8b1e2 Mon Sep 17 00:00:00 2001 From: Greg Tyler Date: Tue, 11 Jun 2024 09:29:14 +0100 Subject: [PATCH] Migrate AWS endpoint configuration (#213) V1 endpoint resovlers are being deprecated, so instead set a BaseEndpoint in config and use path style URLs. #patch --- internal/objectstore/client.go | 4 +++- lambda/create/main.go | 16 +++++----------- lambda/get/main.go | 16 +++++----------- lambda/getlist/main.go | 16 +++++----------- lambda/update/main.go | 16 +++++----------- 5 files changed, 23 insertions(+), 45 deletions(-) diff --git a/internal/objectstore/client.go b/internal/objectstore/client.go index ac60e69d..c3c8e068 100644 --- a/internal/objectstore/client.go +++ b/internal/objectstore/client.go @@ -79,7 +79,9 @@ func (c *S3Client) UploadFile(ctx context.Context, file shared.FileUpload, path } func NewS3Client(awsConfig aws.Config, bucketName string) *S3Client { - awsClient := s3.NewFromConfig(awsConfig) + awsClient := s3.NewFromConfig(awsConfig, func(o *s3.Options) { + o.UsePathStyle = true + }) return &S3Client{ bucketName: bucketName, diff --git a/lambda/create/main.go b/lambda/create/main.go index 378fbe64..911bac23 100644 --- a/lambda/create/main.go +++ b/lambda/create/main.go @@ -157,21 +157,15 @@ func main() { // set endpoint to "" outside dev to use default AWS resolver endpointURL := os.Getenv("AWS_BASE_URL") - cfg, err := config.LoadDefaultConfig(ctx, func(o *config.LoadOptions) error { - if endpointURL != "" { - o.EndpointResolverWithOptions = aws.EndpointResolverWithOptionsFunc( - func(service, region string, options ...interface{}) (aws.Endpoint, error) { - return aws.Endpoint{URL: endpointURL, HostnameImmutable: true}, nil - }, - ) - } - - return nil - }) + cfg, err := config.LoadDefaultConfig(ctx) if err != nil { logger.Error("failed to load aws config", slog.Any("err", err)) } + if endpointURL != "" { + cfg.BaseEndpoint = aws.String(endpointURL) + } + l := &Lambda{ eventClient: event.NewClient(cfg, os.Getenv("EVENT_BUS_NAME")), store: ddb.New( diff --git a/lambda/get/main.go b/lambda/get/main.go index 9f8376f4..f70019f6 100644 --- a/lambda/get/main.go +++ b/lambda/get/main.go @@ -83,21 +83,15 @@ func main() { // set endpoint to "" outside dev to use default AWS resolver endpointURL := os.Getenv("AWS_BASE_URL") - cfg, err := config.LoadDefaultConfig(ctx, func(o *config.LoadOptions) error { - if endpointURL != "" { - o.EndpointResolverWithOptions = aws.EndpointResolverWithOptionsFunc( - func(service, region string, options ...interface{}) (aws.Endpoint, error) { - return aws.Endpoint{URL: endpointURL, HostnameImmutable: true}, nil - }, - ) - } - - return nil - }) + cfg, err := config.LoadDefaultConfig(ctx) if err != nil { logger.Error("failed to load aws config", slog.Any("err", err)) } + if endpointURL != "" { + cfg.BaseEndpoint = aws.String(endpointURL) + } + l := &Lambda{ store: ddb.New( cfg, diff --git a/lambda/getlist/main.go b/lambda/getlist/main.go index 1e22ac46..aec06895 100644 --- a/lambda/getlist/main.go +++ b/lambda/getlist/main.go @@ -88,21 +88,15 @@ func main() { // set endpoint to "" outside dev to use default AWS resolver endpointURL := os.Getenv("AWS_BASE_URL") - cfg, err := config.LoadDefaultConfig(ctx, func(o *config.LoadOptions) error { - if endpointURL != "" { - o.EndpointResolverWithOptions = aws.EndpointResolverWithOptionsFunc( - func(service, region string, options ...interface{}) (aws.Endpoint, error) { - return aws.Endpoint{URL: endpointURL, HostnameImmutable: true}, nil - }, - ) - } - - return nil - }) + cfg, err := config.LoadDefaultConfig(ctx) if err != nil { logger.Error("failed to load aws config", slog.Any("err", err)) } + if endpointURL != "" { + cfg.BaseEndpoint = aws.String(endpointURL) + } + l := &Lambda{ store: ddb.New( cfg, diff --git a/lambda/update/main.go b/lambda/update/main.go index 0f5de232..0a5b5d36 100644 --- a/lambda/update/main.go +++ b/lambda/update/main.go @@ -128,21 +128,15 @@ func main() { // set endpoint to "" outside dev to use default AWS resolver endpointURL := os.Getenv("AWS_BASE_URL") - cfg, err := config.LoadDefaultConfig(ctx, func(o *config.LoadOptions) error { - if endpointURL != "" { - o.EndpointResolverWithOptions = aws.EndpointResolverWithOptionsFunc( - func(service, region string, options ...interface{}) (aws.Endpoint, error) { - return aws.Endpoint{URL: endpointURL, HostnameImmutable: true}, nil - }, - ) - } - - return nil - }) + cfg, err := config.LoadDefaultConfig(ctx) if err != nil { logger.Error("failed to load aws config", slog.Any("err", err)) } + if endpointURL != "" { + cfg.BaseEndpoint = aws.String(endpointURL) + } + l := &Lambda{ eventClient: event.NewClient(cfg, os.Getenv("EVENT_BUS_NAME")), store: ddb.New(