Skip to content

Commit

Permalink
Migrate AWS endpoint configuration (#213)
Browse files Browse the repository at this point in the history
V1 endpoint resovlers are being deprecated, so instead set a BaseEndpoint in config and use path style URLs.

#patch
  • Loading branch information
gregtyler authored Jun 11, 2024
1 parent d341955 commit 5875d4a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 45 deletions.
4 changes: 3 additions & 1 deletion internal/objectstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 5 additions & 11 deletions lambda/create/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 5 additions & 11 deletions lambda/get/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 5 additions & 11 deletions lambda/getlist/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 5 additions & 11 deletions lambda/update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5875d4a

Please sign in to comment.