Environment setup

To be able to access the evroc API you need to log in and setup your environment. The steps required are described in the IAM chapter.

Storage API

Generate Credentials

You can generate credentials for usage with existing S3 Compatible SDKs or XML APIs. For this you need to use the evroc CLI and do the following:

1. Create a Service Account

The credentials are tied to a Service Account. Here we create a new Service Account called sa-external with the evroc CLI.

$ evroc iam serviceaccount create sa-external
sa-external created

2. Create the bucket and set the Service Account as owner

$ evroc storage bucket new real-bucket --owner ServiceAccount.sa-external
real-bucket creation requested

3. Extract the credentials

$ evroc storage bucket get-s3-credentials -n sa-external
[sa-external]
aws_access_key_id = <ACCESS_KEY_ID>
aws_secret_access_key = <SECRET_ACCESS_KEY>

After your credentials have been successfully extracted, review your Secret Access Key and Access Key ID values.

You will also need to configure the endpoint in your S3 client to https://storage.services.evroc.cloud/

Examples

AWS - Boto3

import io
import boto3

bucket_name = "real-bucket"
access_key_id = '<ACCESS_KEY_ID>'
secret_access_key = '<SECRET_ACCESS_KEY>'

s3 = boto3.client('s3',
  endpoint_url = 'https://storage.services.evroc.cloud/',
  aws_access_key_id = access_key_id,
  aws_secret_access_key = secret_access_key
)

# Upload/Update single file
s3.upload_fileobj(io.BytesIO(b"The quick brown fox"), Bucket=bucket_name, Key="thefox")

# Get object information
object_information = s3.head_object(Bucket=bucket_name, Key="thefox")

# List objects
objects = s3.list_objects(Bucket=bucket_name)

# Delete object
s3.delete_object(Bucket=bucket_name, Key="thefox")

aws-sdk-go

package main

import (
        "context"
        "encoding/json"
        "fmt"
        "log"

        "github.com/aws/aws-sdk-go-v2/aws"
        "github.com/aws/aws-sdk-go-v2/config"
        "github.com/aws/aws-sdk-go-v2/credentials"
        "github.com/aws/aws-sdk-go-v2/service/s3"
)

func main() {
        var bucketName = "real-bucket"
        var accessKeyId = "<ACCESS_KEY_ID>"
        var accessKeySecret = "<SECRET_ACCESS_KEY>"

        resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
                return aws.Endpoint{
                    URL: "https://storage.services.evroc.cloud/",
                    HostnameImmutable: true,
                }, nil
        })

        cfg, err := config.LoadDefaultConfig(context.TODO(),
                config.WithEndpointResolverWithOptions(resolver),
                config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKeyId, accessKeySecret, "")),
                config.WithRegion("sto-1"),
        )
        if err != nil {
                log.Fatal(err)
        }

        client := s3.NewFromConfig(cfg)

        listObjectsOutput, err := client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{
                Bucket: &bucketName,
        })
        if err != nil {
                log.Fatal(err)
        }

        for _, object := range listObjectsOutput.Contents {
                obj, _ := json.MarshalIndent(object, "", "\t")
                fmt.Println(string(obj))
        }
}