Create and manage objects in Object Storage
Last updated on
Objects are the individual files and data you store inside a bucket. You manage objects using the S3-compatible API through the AWS CLI or s5cmd.
Prerequisites
Section titled “Prerequisites”- A bucket in your project: Create and manage buckets
- AWS CLI or s5cmd configured with your credentials: Set up the AWS CLI
Upload an object
Section titled “Upload an object”aws s3 cp ./example.txt s3://my-bucket/ \ --endpoint-url https://object.storage.eu01.onstackit.cloudThe output confirms the upload:
upload: ./example.txt to s3://my-bucket/example.txtTo upload an entire directory recursively, use the --recursive flag:
aws s3 cp ./my-folder/ s3://my-bucket/my-folder/ --recursive \ --endpoint-url https://object.storage.eu01.onstackit.clouds5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ cp ./example.txt s3://my-bucket/The output confirms the upload:
cp example.txt s3://my-bucket/example.txtTo upload an entire directory recursively:
s5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ cp ./my-folder/* s3://my-bucket/my-folder/Download an object
Section titled “Download an object”aws s3 cp s3://my-bucket/example.txt ./example.txt \ --endpoint-url https://object.storage.eu01.onstackit.cloudThe output confirms the download:
download: s3://my-bucket/example.txt to ./example.txtTo download an entire prefix recursively:
aws s3 cp s3://my-bucket/my-folder/ ./my-folder/ --recursive \ --endpoint-url https://object.storage.eu01.onstackit.clouds5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ cp s3://my-bucket/example.txt ./example.txtThe output confirms the download:
cp s3://my-bucket/example.txt example.txtTo download an entire prefix recursively:
s5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ cp "s3://my-bucket/my-folder/*" ./my-folder/List objects
Section titled “List objects”aws s3 ls s3://my-bucket/ \ --endpoint-url https://object.storage.eu01.onstackit.cloudThe output lists the objects and their metadata:
2024-01-01 10:00:00 1024 example.txt2024-01-02 11:30:00 20480 archive.zipTo list objects under a specific prefix or recursively across all prefixes, add --recursive:
aws s3 ls s3://my-bucket/my-folder/ --recursive \ --endpoint-url https://object.storage.eu01.onstackit.clouds5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ ls s3://my-bucket/The output lists the objects:
2024/01/01 10:00:00 1024 example.txt2024/01/02 11:30:00 20480 archive.zipTo list objects under a specific prefix:
s5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ ls s3://my-bucket/my-folder/Delete an object
Section titled “Delete an object”aws s3 rm s3://my-bucket/example.txt \ --endpoint-url https://object.storage.eu01.onstackit.cloudThe output confirms the deletion:
delete: s3://my-bucket/example.txtTo delete all objects under a prefix:
aws s3 rm s3://my-bucket/my-folder/ --recursive \ --endpoint-url https://object.storage.eu01.onstackit.clouds5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ rm s3://my-bucket/example.txtThe output confirms the deletion:
rm s3://my-bucket/example.txtTo delete all objects under a prefix:
s5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ rm "s3://my-bucket/my-folder/*"Sync a directory
Section titled “Sync a directory”Sync transfers only the files that differ between the source and destination, making it efficient for incremental backups and deployments.
aws s3 sync ./my-folder/ s3://my-bucket/my-folder/ \ --endpoint-url https://object.storage.eu01.onstackit.cloudThe output lists each file transferred:
upload: my-folder/file1.txt to s3://my-bucket/my-folder/file1.txtupload: my-folder/file2.txt to s3://my-bucket/my-folder/file2.txtTo sync from the bucket back to a local directory:
aws s3 sync s3://my-bucket/my-folder/ ./my-folder/ \ --endpoint-url https://object.storage.eu01.onstackit.clouds5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ sync ./my-folder/ s3://my-bucket/my-folder/The output lists each file transferred:
cp my-folder/file1.txt s3://my-bucket/my-folder/file1.txtcp my-folder/file2.txt s3://my-bucket/my-folder/file2.txtTo sync from the bucket back to a local directory:
s5cmd --endpoint-url https://object.storage.eu01.onstackit.cloud \ sync s3://my-bucket/my-folder/ ./my-folder/