Services >> Cloud >> AWS >> Service >> S3 >> Example aws cli commands for S3 service

 

IMPORTANT: bucket names cannot have UPPERCASE letters

command purpose remarks
aws s3api get-bucket-versioning --bucket mybucket to check versioning status (enabled or disabled)  
aws s3api put-bucket-versioning --bucket mybucket --versioning-configuration Status=Enabled to enable versioning  
aws s3 sync files s3://mybucket/subfolder to synchronize between source (local directory named files) and destination (s3 bucket named mybucket)  
aws s3 sync files s3://mybucket/files --delete to synchronize and delete files at the destination that are not found at the source  
aws s3api list-object-versions --bucket mybucket to list the object version information at the S3 bucket, includes information such as VersionId  
aws s3api get-object --bucket mybucket --key files/file1.txt --version-id <versionid for object files/file1.txt>  files/file1.txt
 

To recover files/file1.txt locally from the versioned copy in s3 bucket

source is the object files/file1.txt with a particular version

save to the local destination path files/file1.txt

 
aws s3 ls s3://mybucket/files/ to list the contents of a folder in a bucket  
aws s3 cp test.txt s3://mybucket/test2.txt


copy local file test.txt to s3 bucket mybucket and name it as test2.txt  
aws s3 ls list your buckets  
aws s3 ls s3://mybucket --recursive --human-readable --summarize list recursively and in human readable format  
aws s3 mb s3://mynewerbucket create new bucket named mynewerbucket  
aws s3 mb s3://mynewerbucket --region us-west-1 create the bucket in a specific region.
Note S3 service is Global, but buckets are region specific