Skip to content

Instantly share code, notes, and snippets.

@nkhil
Last active October 8, 2020 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkhil/6444f564d5932555e2b94ac320f258f9 to your computer and use it in GitHub Desktop.
Save nkhil/6444f564d5932555e2b94ac320f258f9 to your computer and use it in GitHub Desktop.
Creating copies of files

Create bucket 'test'

awslocal s3api create-bucket --bucket test --region us-east-1

Copy local file into S3

awslocal s3 cp test.txt s3://test/test.txt

Tag it

awslocal s3api put-object-tagging \
    --bucket test \
    --key test.txt \
    --tagging '{"TagSet": [{ "Key": "secret", "Value": "thank you" }]}'

Check the tag

awslocal s3api get-object-tagging \
--bucket test \
--key test.txt

Copy the file

awslocal s3api copy-object \
--copy-source test/test.txt \
--key test-renamed.txt \
--tagging-directive COPY \
--bucket test

List all objects in bucket

awslocal s3api list-objects --bucket test --query 'Contents[].{Key: Key, Size: Size}'

Check the tag on the copy

awslocal s3api get-object-tagging \
--bucket test \
--key test-renamed.txt

The tags should match

Using the mv command

awslocal s3 mv test.txt s3://test/test2.txt

This method does not copy the existing tags

Using cp

awslocal s3 cp s3://test/test.txt s3://test/test3.txt

This does copy the existing tags on the test.txt object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment