Skip to content

Commit

Permalink
Support setting the S3 Storage Class during upload using the environm…
Browse files Browse the repository at this point in the history
…ent variable AWS_S3_STORAGE_CLASS. (#422)

See s3.StorageClass* constants for possible values.

#43

Co-authored-by: Robert Cunius Jr <[email protected]>
  • Loading branch information
recunius and recunius authored May 26, 2022
1 parent 8e3187d commit 2d4534b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions backends/aws_s3_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ func (a *AWSS3Backend) Upload(ctx context.Context, vol *files.VolumeInfo) error

// Do a MultiPart Upload - force the s3manager to compute each chunks md5 hash
_, err := a.uploader.UploadWithContext(ctx, &s3manager.UploadInput{
Bucket: aws.String(a.bucketName),
Key: aws.String(key),
Body: r,
Bucket: aws.String(a.bucketName),
Key: aws.String(key),
Body: r,
StorageClass: getS3EnvironmentOverride("AWS_S3_STORAGE_CLASS"),
}, s3manager.WithUploaderRequestOptions(options...))

if err != nil {
Expand Down Expand Up @@ -383,3 +384,11 @@ func (a *AWSS3Backend) List(ctx context.Context, prefix string) ([]string, error

return l, nil
}

func getS3EnvironmentOverride(envVar string) *string {
storageClass := os.Getenv(envVar)
if storageClass != "" {
return aws.String(storageClass)
}
return nil
}

0 comments on commit 2d4534b

Please sign in to comment.