From 5bdc3a70253d2023d8833068bb7860f328cf40c7 Mon Sep 17 00:00:00 2001 From: Howard Wu Date: Wed, 7 Oct 2026 15:15:59 +1300 Subject: [PATCH] feat: anonymous access to S3 buckets when needed --- aws/s3/s3.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/aws/s3/s3.go b/aws/s3/s3.go index 6e33cd3..1ee7a6c 100644 --- a/aws/s3/s3.go +++ b/aws/s3/s3.go @@ -39,6 +39,19 @@ func New() (S3, error) { return S3{client: newFromConfig(cfg)}, nil } +// NewAnonymous returns an S3 struct which wraps an S3 client using anonymous credentials. +// This is useful for accessing public S3 buckets that don't require authentication. +// It is an error if the AWS_REGION environment variable is not set. +// Requests with recoverable errors will be retried with the default retrier. +func NewAnonymous() (S3, error) { + cfg, err := getConfig() + if err != nil { + return S3{}, err + } + cfg.Credentials = aws.AnonymousCredentials{} + return S3{client: newFromConfig(cfg)}, nil +} + // NewWithMaxRetries returns the same as New(), but with the // back off set to up to maxRetries times. func NewWithMaxRetries(maxRetries int) (S3, error) {