Examples of using the AWS CLI for Ozone S3 Gateway
You can use the Amazon Web Services (AWS) command-line interface (CLI) to interact with S3 Gateway and work with various Ozone storage elements.
Defining an alias for the S3 Gateway endpoint
alias ozones3api='aws s3api --ca-bundle --endpoint https://localhost:9879'
alias ozones3api='aws s3api --ca-bundle --endpoint http://localhost:9878'
Examples of using the AWS CLI to work with the Ozone storage elements
The following examples show how you can use the AWS CLI to perform various
operations on the Ozone storage elements. All the examples specify the alias
ozones3api
:
Operations | Examples |
---|---|
Creating a bucket |
ozones3api create-bucket --bucket buck1 This command creates a bucket buck1. |
Adding objects to a bucket |
ozones3api put-object --bucket buck1 --key Doc1 --body ./Doc1.md This command adds the key Doc1 containing data from Doc1.md to the bucket buck1. |
Listing objects in a bucket |
ozones3api list-objects --bucket buck1 This command lists the objects in the bucket buck1. An example output of the command is as follows: { "Contents": [ { "LastModified": "2018-11-02T21:57:40.875Z", "ETag": "1541195860875", "StorageClass": "STANDARD", "Key": "Doc1", "Size": 2845 }, { "LastModified": "2018-11-02T22:36:23.358Z", "ETag": "1541198183358", "StorageClass": "STANDARD", "Key": "Doc2", "Size": 5615 }, { "LastModified": "2018-11-02T21:56:47.370Z", "ETag": "1541195807370", "StorageClass": "STANDARD", "Key": "Doc3", "Size": 1780 } ] } |
Downloading an object from a bucket | ozones3api get-object --bucket buck1 --key Doc1 ./Dpc1This command downloads the key Doc1 from the bucket buck1 as a file Dpc1. An example output of the command is as follows: { "ContentType": "application/octet-stream", "ContentLength": 2845, "Expires": "Fri, 02 Nov 2018 22:39:00 GMT", "CacheControl": "no-cache", "Metadata": {} } |
Verifying access to a bucket | ozones3api head-bucket --bucket buck1This command verifies whether the bucket buck1 exists and whether the current user has access to buck1. If both the requirements are satisfied, the command returns no output. Otherwise, it displays an error message. |
Returning object metadata | ozones3api head-object --bucket buck1 --key Doc1This command returns the metadata of key Doc1 present in bucket buck1. An example output of the command is as follows: { "ContentType": "binary/octet-stream", "LastModified": "Fri, 2 Nov 2018 21:57:40 GMT", "ContentLength": 2845, "Expires": "Fri, 02 Nov 2018 22:41:55 GMT", "ETag": "1541195860875", "CacheControl": "no-cache", "Metadata": {} } |
Copy a key from one bucket to another | ozones3api copy-object --bucket buck2 --key Doc1 --copy-source buck1/Doc1This command copies the key Doc1 from bucket buck1 to buck2. The following example shows the result of a copy operation: { "CopyObjectResult": { "LastModified": "2018-11-02T22:49:20.061Z", "ETag": "21df0aee-26a9-464c-9a81-620f7cd1fc13" } }To verify whether the specified object is copied, you can run the list-object command on the destination
bucket. |
Deleting an object from a bucket |
ozones3api delete-object --bucket buck1 --key Doc1 This command deletes the key Doc1 from bucket buck1. |
Deleting multiple objects from a bucket |
ozones3api delete-objects --bucket buck1 --delete 'Objects=[{Key=Doc1},{Key=Doc2},{Key=Doc3}] This command deletes the keys Doc1, Doc2, and Doc3 from bucket buck1. |