Skip to main content

Create and delete Amazon S3 buckets and edit bucket properties.

# To create a bucket:
aws s3api create-bucket --bucket <bucket_name>

# To delete a bucket:
aws s3api delete-bucket --bucket <bucket_name>

# To list buckets:
aws s3api list-buckets

# To list the objects inside of a bucket and only show each object's key and size:
aws s3api list-objects --bucket <bucket_name> --query '<Contents[].{Key: Key, Size: Size>}'

# To add an object to a bucket:
aws s3api put-object --bucket <bucket_name> --key <object_key> --body <path/to/file>

# To download object from a bucket (The output file is always the last argument):
aws s3api get-object --bucket <bucket_name> --key <object_key> <path/to/output_file>

# To apply an Amazon S3 bucket policy to a specified bucket:
aws s3api put-bucket-policy --bucket <bucket_name> --policy file://<path/to/bucket_policy.json>

# To download the Amazon S3 bucket policy from a specified bucket:
aws s3api get-bucket-policy --bucket <bucket_name> --query Policy --output <json|table|text|yaml|yaml-stream> > <path/to/bucket_policy>