Working with AWS CLI and S3 Buckets

Ed Phillis
Ed Phillis

If you haven't installed AWS CLI then check out the instructions for doing that here

 

Using a non default AWS Profile

I manage a few AWS user accounts so I have a few profiles. You can use the profile name as an argument for the CLI command you are using but often I need to do a number of things with one profile before using another profile so it makes sense to export the profile and run commands without the argument.

export AWS_PROFILE=client123

and check which profile you are using

echo $AWS_PROFILE

If you're familiar with bash commands then alot of the basic AWS CLI commands will seem familiar.

List the buckets available to this profile/account

aws s3 ls 

List the objects within a particular bucket

aws s3 ls s3://mybucket

List the buckets available to this profile/account

aws s3 mb s3://mybucket

Remove a bucket

aws s3 rb s3://mybucket

Move an object from one bucket to another

aws s3 mv s3://bucket-name/example s3://my-bucket/

Recursively remove an object from a bucket

aws s3 rm s3://mybucket/folder --recursive

Recursively copy a local folder to within an object in a bucket

aws s3 cp myfolder s3://mybucket/folder --recursive

Sync a local folder with the contents of an object in an S3 bucket (with an argument excluding a file pattern

aws s3 sync myfolder s3://mybucket/folder --exclude *.tmp