Tutorial

Presigned URLs with ACS

Learn how to generate and use presigned URLs for secure, temporary access to ACS's global infrastructure.

Overview

Presigned URLs provide secure, temporary access to objects in your ACS buckets without exposing credentials. They're ideal for one‑time downloads, direct‑to‑storage uploads, and safely sharing private resources over ACS's accelerated infrastructure.

How Presigned URLs Work

You generate a URL with your ACS credentials and an expiration. The URL embeds a SigV4 cryptographic signature and expiry time. Users access the object directly via the URL. ACS validates the signature and serves the object. The URL expires automatically after the set duration.

1) Setup Environment and Install SDK

setup.sh
# Create virtual environment with UV
uv venv
# Activate virtual environment
source .venv/bin/activate # On macOS/Linux
# or
.venv\Scripts\activate # On Windows
# Install boto3 using UV
uv pip install boto3

2) Set Credentials

Export environment variables:

env.sh
# Required: S3-compatible endpoint and region
export S3_ENDPOINT="https://acceleratedprod.com" # ACS endpoint
export AWS_REGION="global" # ACS region
# Required: S3-compatible credentials (standard AWS env vars)
export AWS_ACCESS_KEY_ID="YOUR_ACS_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="YOUR_ACS_SECRET_ACCESS_KEY"
# Optional: Addressing style
export S3_ADDRESSING_STYLE="virtual"

3) Create Client (ACS Endpoint)

client.py
import os
import boto3
from botocore.config import Config
# ACS client configuration
endpoint = "https://acceleratedprod.com"
region = "global"
addressing_style = "virtual"
s3 = boto3.client(
"s3",
endpoint_url=endpoint,
region_name=region,
config=Config(signature_version="s3v4", s3={"addressing_style": addressing_style}),
)

Generate a Download (GET) URL

get_url.py
# get_url.py
url = s3.generate_presigned_url(
"get_object",
Params={}"Bucket": "your-bucket", "Key": "path/to/file.txt"},
ExpiresIn=expires_in_seconds # Set your desired expiration time
)
print(url)

Generate an Upload (PUT) URL

put_url.py
# put_url.py
upload = s3.generate_presigned_url(
"put_object",
Params={}"Bucket": "your-bucket", "Key": "uploads/new.txt"},
ExpiresIn=expires_in_seconds # Set your desired expiration time
)
print(upload)

Generate a Form Upload (POST)

form_post.py
# form_post.py
form = s3.generate_presigned_post(
Bucket="your-bucket",
Key="uploads/$${filename}",
ExpiresIn=expires_in_seconds # Set your desired expiration time
)
print(form["url"])
print(form["fields"])

Check Object Metadata (HEAD)

head_url.py
# head_url.py
head_url = s3.generate_presigned_url(
"head_object",
Params={"Bucket": "your-bucket", "Key": "path/to/file.txt"},
ExpiresIn=expires_in_seconds
)
print(head_url)

List Bucket Contents

list_url.py
# list_url.py
list_url = s3.generate_presigned_url(
"list_objects_v2",
Params={"Bucket": "your-bucket"},
ExpiresIn=expires_in_seconds
)
print(list_url)

Batch Download URLs

batch_download.py
# batch_download.py
files = ["file1.txt", "file2.txt", "file3.txt"]
batch_urls = {}
for key in files:
url = s3.generate_presigned_url(
"get_object",
Params={"Bucket": "your-bucket", "Key": key},
ExpiresIn=expires_in_seconds
)
batch_urls[key] = {"url": url, "status": "success"}
print(batch_urls)