go/s3/README.md
These examples demonstrates how to perform several Amazon S3 operations.
You must have an AWS account, and have your default credentials and AWS Region configured as described in Configuring the AWS SDK for Go in the AWS SDK for Go Developer Guide.
This example copies an item from one Amazon S3 bucket to another.
go run CopyObject.go -f FROM-BUCKET -t TO-BUCKET -i ITEM
The unit test accepts similar values from config.json.
This example creates an Amazon S3 bucket.
go run CreateBucket.go -b BUCKET
The unit test accepts a similar value from config.json.
This example creates an Amazon S3 bucket and a dummy object in that bucket.
go run CreateBucketAndObject.go -b BUCKET [-k KEY]
The unit test accepts similar values from config.json.
This example creates, reads, updates, and deletes an Amazon S3 bucket.
go run S3CrudOps.go -b BUCKET
The unit test accepts a similar value from config.json.
This example either creates a custom HTTP client and uses it to get an Amazon S3 bucket object, or gets the S3 bucket object using a custom timeout of 20 seconds.
go run CustomHTTPClient.go -b BUCKET -o OBJECT [-s] [-t]
The unit test accepts similar values from config.json.
This example deletes an Amazon S3 bucket.
go run DeleteBucket.go -b BUCKET
The unit test accepts a similar value from config.json.
This example removes the policy for an Amazon S3 bucket.
go run DeleteBucketPolicy.go -b BUCKET
The unit test accepts a similar value from config.json.
This example removes the website configuration for an Amazon S3 bucket.
go run DeleteBucketWebsite.go -b BUCKET
The unit test accepts a similar value from config.json.
This example deletes an item from an Amazon S3 bucket.
go run DeleteObject -b BUCKET -i ITEM
The unit test accepts similar values from config.json.
This example deletes all of the objects in an Amazon S3 bucket.
go run DeleteObjects.go -b BUCKET
The unit test accepts a similar value from config.json.
This example downloads a file from an Amazon S3 bucket.
go run DownloadObject.go -b BUCKET -f FILENAME
The unit test accepts similar values from config.json.
This example adds an object to an Amazon S3 bucket with encryption based on an AWS Key Management Service (AWS KMS) key.
go run EncryptOnServerWithKms.go -b BUCKET -o OBJECT -k KEY
The unit test accepts similar values from config.json.
This example enforces an MD5 checksum on the object uploaded to an Amazon S3 bucket.
go run EnforceMD5Content.go -b BUCKET -k KEY
The unit test accepts similar values from config.json.
This example creates a presigned URL for an Amazon S3 bucket object.
go run GeneratePresignedURL.go -b BUCKET -k KEY
The unit test accepts similar values from config.json.
This example creates a presigned URL for an Amazon S3 bucket object with specific content.
go run GeneratePresignedURLSpecificPayload.go -b BUCKET -k KEY -c CONTENT
The unit test accepts similar values from config.json.
This example gets the ACL for an Amazon S3 bucket.
go run GetBucketAcl.go -b BUCKET
The unit test accepts a similar value from config.json.
This example retrieves the policy for an Amazon S3 bucket.
go run GetBucketPolicy.go -b BUCKET
The unit test accepts a similar value from config.json.
This example retrieves the Amazon S3 bucket's website configuration.
go run GetBucketWebsite.go -b BUCKET
The unit test accepts a similar value from config.json.
This example gets the ACL for an Amazon S3 bucket object.
go run GetObjectAcl.go -b BUCKET -k KEY
The unit test accepts similar values from config.json.
This example lists all Amazon S3 buckets.
go run ListBuckets.go
This example lists all of the objects in an Amazon S3 bucket.
go run ListObjects.go -b BUCKET
The unit test accepts a similar value from config.json.
This example gives everyone access to an Amazon S3 bucket.
go run MakeBucketPublic.go -b BUCKET
The unit test accepts similar values from config.json.
This example gives a user access to an Amazon S3 bucket.
`go run PutBucketAcl.go -b BUCKET -e ADDRESS -p PERMISSION
The unit test accepts similar values from config.json.
This example gives a person read access to an object in an Amazon S3 bucket.
`go run PutObjectAcl.go -b BUCKET -k KEY -a ADDRESS
The unit test accepts similar values from config.json.
This example uploads a file to an Amazon S3 bucket using setters.
go run PutObjectWithSetters.go -b BUCKET -k KEY
The unit test accepts similar values from config.json.
This example adds a policy to enable AWS Key Management Service (AWS KMS) encryption by default on an Amazon S3 bucket.
go run RequireServerEncryption.go -b BUCKET
The unit test accepts a similar value from config.json.
This example restores an item to an Amazon S3 bucket for a number of days.
go run RestoreObject.go -b BUCKET -i ITEM [-d DAYS]
The unit test accepts similar values from config.json.
This example applies a policy to an Amazon S3 bucket.
go run SetBucketPolicy.go -b BUCKET
The unit test accepts a similar value from config.json.
This example sets up an Amazon S3 bucket as a static website.
go run SetBucketWebsite.go -b BUCKET -i INDEX [-e ERROR]
The unit test accepts similar values from config.json.
This example configures CORS rules for an Amazon S3 bucket by setting the allowed HTTP methods.
go run SetCors.go -b BUCKET
The unit test accepts a similar value from config.json.
This example enforces encryption using an AWS Key Management Service (AWS KMS) key on an Amazon S3 bucket.
go run SetDefaultEncryption.go -b BUCKET -k KMS-KEY-ID
The unit test accepts similar values from config.json.
This example creates a custom HTTP client using TLS version 1.2 and uses it to attempt to access an item in an Amazon S3 bucket.
go run s3SetTls12 -b BUCKET -o OBJECT [-r REGION] [-v]
The unit test accepts similar values from config.json.
This example uploads the files in a directory to an Amazon S3 bucket.
go run UploadDirectory.go -b BUCKET -d DIRECTORY
The unit test accepts similar values from config.json.
This example uploads a file to an Amazon S3 bucket.
go run UploadObject.go -b BUCKET -f FILENAME
The unit test accepts similar values from config.json.
This example uploads a stream for a file to an Amazon S3 bucket.
go run UploadStream.go -b BUCKET -f FILENAME -k KEY
The unit test accepts similar values from config.json.
Unit tests should delete any resources they create. However, they might result in charges to your AWS account.
To run a unit test, enter the following:
go test
You should see something like the following, where PATH is the path to folder containing the Go files:
PASS
ok PATH 6.593s
If you want to see any log messages, enter the following.
go test -test.v
You should see some additional log messages. The last two lines should be similar to the previous output shown.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0