Create immutable buckets with AWS CLI
Glesys Object Storage buckets support Object Lock and versioning, also referred to as immutable buckets. To manage these features, you need to use a tool like the AWS CLI.
To manage more advanced features of a bucket, like Object Lock and object versioning, you need to use the AWS CLI tool. The easiest way to get started with AWS CLI is to install it in a Python virtual environment.
Installing Python and necessary tools
Python is pre-installed in most Linux distributions. If it's not installed on your particular distribution, you can easily install it using the distribution's package manager. For example:
Debian/Ubuntu:
sudo apt install python3Fedora/AlmaLinux:
dnf install python3
Python should already be installed in newer versions of macOS.
Open a terminal window by searching for Terminal in the Start menu.
Execute
python3in the Terminal. If Python is not already installed, the Windows Store will open with Python pre-loaded.Click Get or Install in the Windows Store to install Python.
Once the installation in the Windows Store finishes, execute
python3again in the Terminal. This will do the actual installation and open a Python prompt.When you see the prompt change to
>>>you know that Python is properly installed and working. Exit from Python by executing the commandquit().You will also need Microsoft Visual C++ 14 or greater to build the AWS CLI tool. Start by downloading and installing Microsoft Visual Studio Build Tools from https://visualstudio.microsoft.com/visual-cpp-build-tools. When the installer reaches the screen where you are asked to select tools and workloads, select Desktop Development with C++. Then proceed with the installation.

Installing AWS CLI
Open a terminal window. The first step is to create a directory for AWS CLI and enter that directory.
mkdir awscli
cd awscliNow you need to create a Python virtual environment:
python3 -m venv envActivate the environment:
source env/bin/activate.\env\Scripts\Activate.ps1If you get an error about scripts being disabled due to the execution policy, allow your own user to execute scripts by first executing:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned The prompt should now change to (env). If so, everything is set up correctly so far.
Now it's time to install the AWS CLI tool in the Python virtual environment:
Once the installation is finished, test the tool so it's working by executing aws --version:
If you close the terminal, make sure you activate the Python virtual environment again when you want to use the AWS CLI tool. The virtual environment is active when you see the (env) prompt.
Setting up AWS CLI with Glesys Object Storage
To set up the AWS CLI tool with your Glesys Object Storage, run aws configure and follow the guide, for example (change dc-fbg1 to dc-sto1 if your Object Storage instance is in Stockholm):
You also need to set the endpoint URL (change the URL to https://objects.dc-sto1.glesys.net if your Object Storage instance is in Stockholm):
Everything is now set up and ready for use.
Making a bucket immutable
Start by listing your current buckets.
This object storage instance contains two buckets: cold-bread and warm-coat. In this example, we will make warm-coat an immutable bucket by activating versioning and Object Lock, and setting a default retention period of 60 days on it. We also set the retention mode to COMPLIANCE. During the retention period (in COMPLIANCE mode), no one can delete or modify locked object versions—not even the bucket owner.
Start by enabling versioning on the bucket.
Let's verify it's enabled.
For better readability and easier editing, create a JSON file with the Object Lock rules. In this example, we name the file lock.json and give it the following content.
Now it's time to activate Object Lock using the above file.
Let's verify it before moving on.
Testing and using the immutable bucket
Start by uploading a new file.
Verify the retention of the file.
In the output above, you can see for how long the file is locked.
If you upload a modified version of the same file, the upload will succeed. A new version of the file will be created automatically.
Let's list the file's versions.
There are two versions of this file: the initial one and the modified one. Each version has a timestamp, size, id, and an IsLatest field, making it easy to find the correct version.
To download a different version than the latest, use its VersionId. For example:
The original image is now downloaded to the local computer with the name original-forest.jpg.
Even if the file is deleted, its versions remain intact, even if the file no longer shows up in file listings.
The file is missing from the file listing above, but its data is still intact. Let's list the versions for forest.jpg again.
In the output above, you can see that the file versions are intact. There is also a delete marker for the file, which is now the latest version of the file ("IsLatest": true).
But if you try to delete a version—any version—it will be denied. This is where the Object Lock comes into play.
However, it's possible to delete the delete marker from the file, making it appear in the file listing again (since this doesn't affect the file's data, the delete marker isn't locked).
Locking existing files
In the output above, there are three more files besides forest.jpg: hunt, phantasia, and robots. These files existed before Object Lock was activated; hence, they lack any protection.
Individual files (objects) can't be locked for a specific number of days. Instead, you must supply a specified date to the command.
Double-check that it worked.
Last updated
Was this helpful?