The v2 version of awscli
, the official AWS command-line tool, provides a large number of "aws s3api ...
" commands exposing most S3 features. awscli
is no longer installed with pip, see:
https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
To configure just create a ~/.aws/credentials
file with a Swarm S3 token and secret, which you can create in the Gateway Content Portal e.g. http://mydomain.example.com/_admin/portal.
[default] aws_access_key_id = 538310d5a74754af308c2fbe0b2cbb1a aws_secret_access_key = secret
Tip: add multiple profiles besides [default]
that use different Swarm clusters or domains then refer to it using aws --profile devswarm …
. Unfortunately the domain, which must resolve to your Gateway S3 endpoint, must always be specified on the command-line with --endpoint-url
.
This will show the buckets in your domain:
aws s3 --endpoint-url http://mydomain.example.com:8090 ls
Tip: use aws --debug
to see full HTTP request and response details, including the request-id for searching cloudgateway_server.log. Long listings might require --cli-read-timeout 300
.
The s3api
subcommand provides most of the AWS S3 features. E.g. these commands create a bucket with a locking and retention configuration. Note this feature requires the upcoming Gateway 7.6 release! An object is created then locked with a “legal hold” preventing that version from being deleted. Finally the lock is removed so the version can be deleted.
aws s3api --endpoint-url http://mydomain.example.com:8090 create-bucket --bucket locker --object-lock-enabled-for-bucket aws s3api --endpoint-url http://mydomain.example.com:8090 put-bucket-versioning --bucket locker --versioning-configuration Status=Enabled aws --debug s3api --endpoint-url http://mydomain.example.com:8090 put-object-lock-configuration --bucket locker --object-lock-configuration '{ "ObjectLockEnabled": "Enabled", "Rule": { "DefaultRetention": { "Mode": "GOVERNANCE", "Days": 1 } } }' aws s3api --endpoint-url http://mydomain.example.com:8090 put-object --bucket locker --key incriminating.log VERSION_ID=$(aws s3api --endpoint-url http://mydomain.example.com:8090 list-object-versions --bucket locker | jq -r '.Versions|map(select(.Key=="incriminating.log"))[0].VersionId') aws s3api --endpoint-url http://mydomain.example.com:8090 put-object-legal-hold --bucket locker --key incriminating.log --version-id ${VERSION_ID} --legal-hold Status=ON aws s3api --endpoint-url http://mydomain.example.com:8090 delete-object --bucket locker --key incriminating.log --version-id ${VERSION_ID} || echo "Good, expected failure" aws s3api --endpoint-url http://mydomain.example.com:8090 put-object-legal-hold --bucket locker --key incriminating.log --version-id ${VERSION_ID} --legal-hold Status=OFF aws s3api --endpoint-url http://mydomain.example.com:8090 delete-object --bucket locker --key incriminating.log --version-id ${VERSION_ID} test $(aws s3api --endpoint-url http://mydomain.example.com:8090 list-object-versions --bucket locker | jq -r '.Versions|map(select(.Key=="incriminating.log"))|length') -eq 0 || echo "Expected zero objects"