Black Eight - Ben's space

Kategorie: IT

Create public buckets in Strato HiDrive S3

Currently there is no documented way to create public buckets in Strato HiDrive S3. But it can be done very easily using the AWS CLI. To set up the CLI just follow my post here.

Let’s assume you already have a bucket called demobucket and you can access it using the AWS CLI. Now we upload a basic html page (or any other file):

% cat index.html 
<!DOCTYPE html>
<html>
    <head>
        <title>Hello World!</title>
    </head>
    <body>
Hello World!
    </body>
</html>

% strato s3 cp index.html s3://demobucket
upload: ./index.html to s3://demobucket/index.html 

The next step needs to be done only once for each bucket you want to make public. Please make sure you adjust the bucket name (in bold):

% strato s3api put-bucket-policy --bucket demobucket --policy "{
  \"Version\": \"2012-10-17\",
  \"Statement\": [
      {
          \"Sid\": \"PublicReadGetObject\",
          \"Effect\": \"Allow\",
          \"Principal\": \"*\",
          \"Action\": \"s3:GetObject\",
          \"Resource\": \"arn:aws:s3:::demobucket/*\"
      }
  ]
}"

Now you can reach your file publicly using the URLs https://s3.hidrive.strato.com/demobucket/index.html or https://demobucket.s3.hidrive.strato.com/index.html:

Accessing files in public bucket

If you want to make your bucket privat again, just delete the policy:

% strato s3api delete-bucket-policy --bucket demobucket
Accessing files in private bucket

Use Strato HiDrive S3 with AWS CLI

There may be different reasons why you want to use Strato HiDrive S3. There is a developer API for the REST interface but you can also use the AWS CLI. In my opinion using the CLI is much easier so here are some hints to do so.

Step 1: Download the AWS CLI using the link above for your system. Please follow the installation instructions and test the installation:

$ aws --version
aws-cli/2.4.25 Python/3.8.8 Linux/5.4.0 exe/x86_64.ubuntu.20 prompt/off

Step 2: Create a bucket using the HiDrive S3 console:

Step 3: Create an access key using the console:
Very important: Write down/store the displayed access key somewhere. If you forget it you need to create a new one (which is no problem).

Step 4: Configure the AWI CLI using the newly created access key:
Note: don’t change the default region to another value than eu-central-1!

$ aws configure
AWS Access Key ID [None]: <value>
AWS Secret Access Key [None]: <value>
Default region name [None]: eu-central-1
Default output format [None]: 

Step 5: Make your life a little easier and set an alias as following (so you don’t need to enter the full command each time):

$ alias strato="aws --endpoint-url https://s3.hidrive.strato.com"

Step 6: Now you’re ready to use the AWS CLI with your Strato HiDrive S3:

$ strato s3api list-buckets
{
    "Buckets": [
        {
            "Name": "demobucket",
            "CreationDate": "2022-03-13T19:59:54.616000+00:00"
        }
    ],
    "Owner": {
        "ID": "xyz"
    }
}

$ strato s3 cp file.txt s3://demobucket
upload: ./file.txt to s3://demobucket/file.txt    

$ strato s3 ls s3://demobucket
2022-03-13 21:19:37          5 file.txt

$ strato s3 cp s3://demobucket/file.txt .
download: s3://demobucket/file.txt to ./file.txt   

$ strato s3 rm s3://demobucket/file.txt 
delete: s3://demobucket/file.txt

© 2024 BLK8

Theme von Anders NorénHoch ↑