Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nuzur/aws

A small, self-contained AWS client for S3 and Secrets Manager, built on aws-sdk-go-v2. It has no dependency on any service's config package, so it can be shared across repos.

Install

go get github.com/nuzur/aws

Configuration

Config holds the credentials and target settings. It is provided explicitly — there is no implicit config-file fallback.

cfg := &aws.Config{
    Region:   "us-east-1",
    KeyID:    "AKIA...",
    Secret:   "...",
    Bucket:   "my-bucket",
    KmsKeyID: "arn:aws:kms:...", // optional; used for server-side encryption
}

Usage

client, err := aws.New(aws.Params{Config: cfg})
if err != nil {
    log.Fatal(err)
}

// Upload (server-side encrypted with the configured KMS key when encrypt=true).
out, err := client.UploadToS3(ctx, "path/file.png", data, nil, true)

// Presigned GET URL.
url, err := client.GetSignedS3URL(ctx, "path/file.png", 15*time.Minute)

// Download.
bytes, err := client.FetchFromS3(ctx, "path/file.png")

// Secrets Manager.
secret, err := client.FetchSecret(ctx, "my/secret")
_, err = client.CreateSecret(ctx, "my/secret", `{}`, &cfg.KmsKeyID)
_, err = client.UpdateSecret(ctx, "my/secret", `{"k":"v"}`, nil)

All request methods take a context.Context. New performs a one-time config load and is safe to wire as an fx provider:

fx.Provide(
    func() *aws.Config { return cfg },
    aws.New,
)

Building other service clients

Use AWSConfig() to construct additional aws-sdk-go-v2 service clients from the same credentials (for example, SES):

ses := sesv2.NewFromConfig(client.AWSConfig())

HTTP upload handler

UploadHandler returns an http.HandlerFunc that accepts a multipart file form field, uploads it under keyPrefix, and returns the resulting file path as JSON:

mux.Handle("/upload", aws.UploadHandler(client, "nem/"))

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages