The aws s3api command is a part of the AWS Command Line Interface (CLI) and provides a low-level interface to interact with Amazon S3 (Simple Storage Service). It allows you to create and delete S3 buckets, as well as edit various properties of an S3 bucket.
Here’s an overview of the aws s3api command and its functionality:
- Creating Buckets: The aws s3api command allows you to create S3 buckets. You can specify the bucket name, region, and optional parameters such as access control settings or object lock configuration during the bucket creation process.
- Deleting Buckets: With the aws s3api command, you can delete S3 buckets. However, note that the bucket must be empty before you can delete it. You can use other commands, such as aws s3 rm, to delete the objects within the bucket before deleting the bucket itself.
- Editing Bucket Properties: The aws s3api command provides the capability to edit various properties of an S3 bucket. You can modify settings such as bucket policies, CORS (Cross-Origin Resource Sharing) configuration, lifecycle rules, logging configurations, and versioning settings using this command.
- Fine-grained Control: The aws s3api command offers more granular control and flexibility compared to higher-level S3 commands. It allows you to interact with individual S3 API actions and parameters, providing detailed control over the configuration and management of your S3 buckets.
- Automating S3 Operations: The low-level nature of the aws s3api command makes it suitable for scripting and automation purposes. You can use this command in combination with other scripting tools or AWS services to automate S3-related operations and workflows.
The aws s3api command complements the aws s3 command by providing a lower-level interface to interact with Amazon S3. It allows you to perform advanced operations, configure bucket properties in detail, and automate S3 operations in your scripts or workflows.
aws s3api Command Examples
1. Create bucket in a specific region:
# aws s3api create-bucket --bucket bucket_name --region region --create-bucket-configuration LocationConstraint=region
2. Delete a bucket:
# aws s3api delete-bucket --bucket bucket_name
3. List buckets:
# aws s3api list-buckets
4. 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'
5. Add an object to a bucket:
# aws s3api put-object --bucket bucket_name --key object_key --body /path/to/file
6. 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
7. 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
8. 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