Skip to content

Public buckets and presigned URLs

Share objects with people who have no EZGH account, and allow browser requests with CORS.

Updated View as Markdown

Public read

With Public read on, anyone can GET and HEAD objects in the bucket, without a key. Listing stays private, and writes still need a key.

  1. Open the bucket and select Permissions.
  2. Turn on Public read. This needs objects.buckets.update.

Objects are then at either URL:

https://my-bucket.s3.us-west-1.ezghapps.com/report.pdf
https://s3.us-west-1.ezghapps.com/my-bucket/report.pdf

Public reads serve current objects only. Reading a version by its ID needs a key.

Turning it off applies to the next request.

CDN distributions

A CDN distribution in the same organization can read a bucket’s objects while the bucket stays private. Add the distribution’s ID under CDN distributions on the bucket’s Permissions tab. See Serve a private bucket.

Presigned URLs

A presigned URL lets anyone with the link make the S3 request it was signed for, until it expires. Your access key signs it.

  • It lasts at most 7 days. A longer expiry is refused.
  • It acts with the key owner’s access at the time of the request, so a GET needs objects.objects.download.
  • It stops working when the key is revoked.
  • It must be signed with SigV4.

generate_presigned_url in boto3 signs with SigV2 on a custom endpoint unless told otherwise, and SigV2 is refused. Set signature_version:

import boto3
from botocore.config import Config

s3 = boto3.client(
    "s3",
    endpoint_url="https://s3.us-west-1.ezghapps.com",
    region_name="us-west-1",
    config=Config(signature_version="s3v4"),
)

url = s3.generate_presigned_url(
    "get_object",
    Params={"Bucket": "my-bucket", "Key": "report.pdf"},
    ExpiresIn=3600,
)

With the AWS CLI, use aws s3 presign.

CORS

Browsers need a bucket’s CORS rules to call it from another site. Edit them on the bucket’s CORS tab, or with S3’s PutBucketCors.

Limit Value
Rules per bucket 100
Allowed methods GET, PUT, POST, DELETE, HEAD
Maximum age 0 to 86,400 seconds

CORS rules grant no access: a request still needs public read, a presigned URL or a signature.

Browser uploads

To let a browser upload an object, your server signs a presigned PUT and the browser sends the file to it. The bucket’s CORS rules must allow your site’s origin, the PUT method and the content-type header.

With the AWS SDK for JavaScript v3, a URL for an upload with a ContentType needs signableHeaders. Without it, the upload is refused:

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

const s3 = new S3Client({
  endpoint: "https://s3.us-west-1.ezghapps.com",
  region: "us-west-1",
})

const url = await getSignedUrl(
  s3,
  new PutObjectCommand({ Bucket: "my-bucket", Key: "photo.png", ContentType: "image/png" }),
  { expiresIn: 3600, signableHeaders: new Set(["content-type"]) },
)

The browser sends the same Content-Type:

await fetch(url, { method: "PUT", headers: { "Content-Type": "image/png" }, body: file })

Sign on your server. Never put an access key’s secret in a web page.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close