AWS CLI for S3 Lab Guide
- Create a bucket:
- Syntax:
aws s3api create-bucket --bucket <bucket-name> --region <region-name>
- Example:
aws s3api create-bucket --bucket my-bucket --region us-west-2
- List all buckets:
- Syntax:
aws s3api list-buckets
- Example:
aws s3api list-buckets
- Upload a file:
- Syntax:
aws s3 cp <file-path> s3://<bucket-name>/<object-key>
- Example:
aws s3 cp /path/to/local/file s3://my-bucket/my-file
- Download a file:
- Syntax:
aws s3 cp s3://<bucket-name>/<object-key> <file-path>
- Example:
aws s3 cp s3://my-bucket/my-file /path/to/local/file
- Copy a file:
- Syntax:
aws s3 cp s3://<source-bucket>/<source-object-key> s3://<destination-bucket>/<destination-object-key>
- Example:
aws s3 cp s3://my-source-bucket/my-source-file s3://my-destination-bucket/my-destination-file
- Move a file:
- Syntax:
aws s3 mv s3://<source-bucket>/<source-object-key> s3://<destination-bucket>/<destination-object-key>
- Example:
aws s3 mv s3://my-source-bucket/my-source-file s3://my-destination-bucket/my-destination-file
- Delete a file:
- Syntax:
aws s3 rm s3://<bucket-name>/<object-key>
- Example:
aws s3 rm s3://my-bucket/my-file
- List files in a bucket:
- Syntax:
aws s3 ls s3://<bucket-name>
- Example:
aws s3 ls s3://my-bucket
- Create a folder:
- Syntax:
aws s3api put-object --bucket <bucket-name> --key <folder-name>/ --content-length 0
- Example:
aws s3api put-object --bucket my-bucket --key my-folder/ --content-length 0
- Set an object’s ACL:
- Syntax:
aws s3api put-object-acl --bucket <bucket-name> --key <object-key> --acl <acl-value>
- Example:
aws s3api put-object-acl --bucket my-bucket --key my-file --acl public-read