All documentation

S3 storage

Amazon S3 compatible buckets for files: access keys, public links, CORS, linking to an app, and examples for aws-cli, Node.js and Python.

S3 storage keeps your app's files apart from the container: user uploads, images, exports, copies. It is compatible with Amazon S3, so any library or tool that speaks S3 works.

  • Bucket — a container for files with its own space limit. The name is shared by all clients of the cloud: lowercase letters, digits and hyphen, 3–63 characters.
  • Access key works only with its own bucket: other buckets do not exist for it. Permissions are "read only" or "read and write". The secret is shown once, when the key is created.
  • Endpoint — https://s3.<apps domain>, region us-east-1. Path-style addressing is required: https://s3.<domain>/<bucket>/<file>. The https://<bucket>.s3.<domain> form also works, but the first request to a new bucket may take a few seconds while its certificate is issued.

Create a bucket and a key

  1. “S3 storage” in the menu → “Create bucket”. Enter a name and a space limit.
  2. “Access keys” tab → “Create key”. Save the Access key ID and the Secret access key: the secret is not shown again.

From the command line:

uc s3 mb photos --quota 10
uc s3 keys photos create          # read and write; --read for read only
uc s3 cp ./logo.png s3://photos/img/logo.png
uc s3 ls s3://photos/img/

Link to an app

“Links” tab → choose a resource. It gets its own key and the variables:

VariableValue
S3_ENDPOINThttps://s3.<apps domain>
S3_BUCKETbucket name
S3_ACCESS_KEY_IDthe resource's key
S3_SECRET_ACCESS_KEYits secret (masked in deploy logs)
S3_REGIONus-east-1

Unlinking revokes the resource's key and removes these variables.

Examples

aws-cli

export AWS_ACCESS_KEY_ID=UC...
export AWS_SECRET_ACCESS_KEY=...
aws --endpoint-url https://s3.<domain> --region us-east-1 s3 cp report.pdf s3://photos/docs/report.pdf
aws --endpoint-url https://s3.<domain> --region us-east-1 s3 ls s3://photos/docs/

Node.js (@aws-sdk/client-s3)

import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';

const s3 = new S3Client({
  endpoint: process.env.S3_ENDPOINT,
  region: process.env.S3_REGION,
  forcePathStyle: true,
  credentials: { accessKeyId: process.env.S3_ACCESS_KEY_ID, secretAccessKey: process.env.S3_SECRET_ACCESS_KEY },
});

await s3.send(new PutObjectCommand({ Bucket: process.env.S3_BUCKET, Key: 'avatars/1.png', Body: buffer, ContentType: 'image/png' }));
// A download link valid for 15 minutes.
const url = await getSignedUrl(s3, new GetObjectCommand({ Bucket: process.env.S3_BUCKET, Key: 'avatars/1.png' }), { expiresIn: 900 });

Python (boto3)

import os, boto3
from botocore.config import Config

s3 = boto3.client(
    "s3",
    endpoint_url=os.environ["S3_ENDPOINT"],
    region_name=os.environ["S3_REGION"],
    aws_access_key_id=os.environ["S3_ACCESS_KEY_ID"],
    aws_secret_access_key=os.environ["S3_SECRET_ACCESS_KEY"],
    config=Config(s3={"addressing_style": "path"}),
)
s3.upload_file("report.pdf", os.environ["S3_BUCKET"], "docs/report.pdf")
url = s3.generate_presigned_url("get_object", Params={"Bucket": os.environ["S3_BUCKET"], "Key": "docs/report.pdf"}, ExpiresIn=900)

Public read and CORS

  • A bucket is private by default. “Public read” on the “Access and limit” tab opens any file by its direct link without a key; the file list stays closed.
  • To let a website upload files straight from the browser, add a CORS rule with your site's origin and the methods it needs. Uploads from the panel work without rules.

Limit, size and billing

  • Over its space limit a bucket becomes read only until space is freed or the limit is raised.
  • One upload request is up to 5 GB; upload larger files in parts (multipart: aws-cli and the SDKs do it for you).
  • You pay for used space by GB-hours and for outgoing traffic; prices are shown in “S3 storage”.
  • With a negative balance buckets become read only. If the debt is not paid by the deletion date, buckets are deleted together with resources. Deleting the account deletes its buckets and keys.