AWS CLI setup guide for MEGA S4

Using the AWS Command Line Interface (CLI) with MEGA S4 lets you combine the power of automated, scriptable workflows with the reliability and performance of MEGA’s S3-compatible object storage. The AWS CLI provides a familiar, flexible toolset for managing buckets and objects at scale, while MEGA S4 offers secure, high-availability storage with straightforward S3 API compatibility. Together, they make it easy to integrate MEGA S4 into existing tooling and infrastructure.

The following steps will guide you through configuring the AWS CLI so you can start managing your MEGA S4 data from the command line.

Einen neuen Bucket erstellen

  1. Klicken Sie in der linken Leiste auf Objektspeicher.
  2. Klicken Sie auf Bucket erstellen.
  3. Geben Sie dem Bucket einen Namen.
  4. Klicken Sie auf Erstellen.

Zugriffsschlüssel einrichten

  1. Klicken Sie in der linken Leiste auf Objektspeicher.
  2. Klicken Sie in der linken Leiste auf Schlüssel.
  3. Klicken Sie auf Schlüssel erstellen.
  4. Geben Sie dem Schlüssel einen Namen.
  5. Kopieren Sie den Zugriffsschlüssel und den Geheimschlüssel.
  1. Download and install AWS CLI from the Amazon website.
  2. Open a terminal in macOS or Linux, or command prompt in Windows.
  3. Run aws configure and enter your the following information when prompted:
    • AWS Access Key ID: Enter the Access key you copied above.
    • AWS Secret Access Key: Enter the Secret key you copied above.
    • Default region name: Leave this blank.
    • Default output format: Leave this blank.

To test that your AWS CLI is configured correctly

Enter the following command:
aws s3 ls --endpoint-url=https://s3.eu-central-1.s4.mega.io

From now on you can run s3, s3api and iam commands.

Note that it is necessary to add the --endpoint-url subcommand after every command, e.g. https://s3eu-central-1.s4.mega.io. For a list of all the endpoints, see the MEGA S4 settings.

Create a presigned URL

Use the following template for the command:

aws s3 presign s3://your-bucket-name/path/to/your-object --endpoint-url https://your-endpoint-url/
  1. Replace the placeholders with your actual details:
  • Bucket and object: Replace s3://your-bucket-name/path/to/your-object with the path to your file
    • Example: s3://test/images/Done.png
  • Endpoint URL: Use --endpoint-url to specify your S4 endpoint
    • Example: https://s3.eu-central-1.s4.mega.io/
  • Full example: aws s3 presign s3://test/images/Done.png --endpoint-url https://s3.eu-central-1.s4.mega.io/
  1. Press Enter to execute the command.
  2. You should see a presigned URL output, like this:
    https://s3.eu-central-1.s4.mega.io/test/images/Done.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAINZUQVEXKQ3E5RVXZCNCE5B4MUWOVIOTAPKMFRH4%2F20241107%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241107T013010Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=d5a9bef624017c64b57a8a91964249f2e13cd7296bffb7dfb33eba77c7b10c75

Set the time limit for your presigned URL

aws s3 presign s3://test/done.png --endpoint-url https://s3.eu-central-1.s4.mega.io/ --expires-in 604800

Examples are below – note the default is one hour.

--expires-in 604800 The presigned URL will expire in 7 days (the max time)

--expires-in 3600 The presigned URL will expire in 1 hour (the default)

To enable logs

When executing a command add the --debug parameter.

More examples

aws s3 ls --endpoint-url=https://s3.eu-central-1.s4.mega.io

aws s3api list-buckets --endpoint-url=https://s3.eu-central-1.s4.mega.io/

aws iam list-policies --endpoint-url=http://iam.eu-central-1.s4.mega.io/

For a list of all example commands, check the AWS CLI documentation.