Creating Buckets with AWS CLI & Optional Object Lock Activation

The AWS CLI allows you to interact comfortably with your plusserver S3 resources via the command line. Follow the steps below to create buckets and optionally activate Object Lock.

Step 1: Create a Bucket

To create a bucket, use the following command:

aws s3api create-bucket --bucket <bucketname> --endpoint-url=https://<endpoint-url> --region <region> --create-bucket-configuration LocationConstraint=<region>

Replace with the desired name for your bucket and with the corresponding endpoint. For example:

aws s3api create-bucket --bucket mynewbucket --endpoint-url=https://s3.de-west-1.psmanaged.com --region de-west-1 --create-bucket-configuration LocationConstraint=de-west-1

Step 2: Create a Bucket with Object Lock and Versioning Activation

If you want to use Object Lock, you need to activate both Versioning and Object Lock. Use the following command:

The “–object-lock-enabled-for-bucket” parameter automatically enables both Versioning and Object Lock.

aws s3api create-bucket --bucket <bucketname> --object-lock-enabled-for-bucket --endpoint-url=https://<endpoint-url> --region <region> --create-bucket-configuration LocationConstraint=<region>

Replace <bucketname> and <endpoint-url> accordingly. For example:

aws s3api create-bucket --bucket mylockedbucket --object-lock-enabled-for-bucket --endpoint-url=https://s3.de-west-1.psmanaged.com --region de-west-1 --create-bucket-configuration LocationConstraint=de-west-1

Step 3: Check Bucket Settings

Use the command aws s3api get-bucket-versioning to display the versioning settings of a bucket:

aws s3api get-bucket-versioning --bucket <bucketname> --endpoint-url=https://<endpoint-url>

This command indicates whether versioning is enabled for the specified bucket.

Example output:

{
    "Status": "Enabled"
}

To check the Object Lock settings, use the command aws s3api get-object-lock-configuration:

aws s3api get-object-lock-configuration --bucket <bucketname> --endpoint-url=https://<endpoint-url>

This command provides information about whether Object Lock is enabled for the specified bucket.

Example output for an enabled Object Lock:

{
    "ObjectLockConfiguration": 
    {
        "ObjectLockEnabled": "Enabled"
    }
}

Example output for a disabled Object Lock:

An error occurred (ObjectLockConfigurationNotFoundError) when calling the GetObjectLockConfiguration operation: Object Lock configuration does not exist for this bucket
Last modified 03.05.2024: dos2unix mansvc files (d79b1ea)