How to perform basic Object Storage operations
Lets look at some basic AWS CLI commands and their uses:
Create a bucket
aws s3api create-bucket --bucket {bucket-name} --profile={profile}
aws s3api create-bucket --bucket the-holy-pail --profile=objectstorage-v2
Upload a local file (object) to a bucket
aws s3 cp {file-name} s3://{bucket-name} --profile={profile}
aws s3 cp The_Sacred_Script.txt s3://the-holy-pail --profile=objectstorage-v2
List objects within a bucket
aws s3api list-objects --bucket {bucket-name} --profile={profile}
aws s3api list-objects --bucket the-holy-pail --profile=objectstorage-v2
Generate a pre-signed URL
aws s3 presign s3://{bucket-name}/{file-name} --expires-in {time-in-seconds} --profile={profile}
aws s3 presign s3://the-holy-pail/The_Sacred_Script.txt --expires-in 300 --profile=objectstorage-v2
This creates a time-limited link, known as a pre-signed URL for a specific object in an S3 bucket. The pre-signed URL allows temporary access to an object without requiring credentials.
When the time limit is reached, the link expires and can’t be used to access the file anymore.
Delete a specific file (object) from a bucket
aws s3 rm s3://{bucket-name}/{file-name} --profile={profile}
aws s3 rm s3://the-holy-pail/The_Sacred_Script.txt --profile=objectstorage-v2
Delete all files (objects) from a bucket
aws s3 rm s3://{bucket-name} --recursive --profile={profile}
aws s3 rm s3://the-holy-pail --recursive --profile=objectstorage-v2
Delete a bucket
aws s3api delete-bucket --bucket {bucket-name} --profile={profile}
aws s3api delete-bucket --bucket the-holy-pail --profile=objectstorage-v2