S3 request presigner — @aws-sdk/s3-request-presigner
Generates presigned URLs for any S3 operation using Signature Version 4.
getSignedUrl(client, command, options?)
An initialized
S3Client instance. The signer inherits its region, credentials, and endpoint configuration.Any S3 command instance:
GetObjectCommand, PutObjectCommand, DeleteObjectCommand, HeadObjectCommand, etc.Number of seconds until the URL expires. Maximum is 604800 (7 days) for IAM role credentials.
Override the date used for signing. Defaults to now.
Override the signing region. Defaults to the client’s region.
Headers to enforce as required in the presigned request. Useful for non-
x-amz-* headers like content-type.Force
x-amz-* headers to remain as request headers rather than being moved to query parameters. Required when signing headers like x-amz-checksum-sha256.Override the default behavior and move specific
x-amz-* headers into query parameters. Useful for SSE headers.Promise<string> — the presigned URL.
Examples
S3RequestPresigner class
For presigning arbitrary HttpRequest objects without constructing S3 commands:
S3 presigned POST — @aws-sdk/s3-presigned-post
Generates a URL and form fields for browser-based POST uploads directly to S3. Unlike presigned GET/PUT URLs, presigned POST allows attaching upload policies (size limits, key prefixes, ACLs).
createPresignedPost(client, options)
An initialized
S3Client instance.Target S3 bucket name.
Object key or key prefix. Use
${filename} as a placeholder for the original filename.Array of POST policy conditions. Supported formats:
- Exact match:
{ "fieldName": "value" } - Starts-with:
["starts-with", "$fieldName", "prefix"] - Range:
["content-length-range", minBytes, maxBytes]
Key-value pairs to include as hidden form fields. Values must satisfy the conditions in
Conditions.Seconds until the presigned POST expires.
Promise<{ url: string; fields: Record<string, string> }>
Examples
CloudFront signer — @aws-sdk/cloudfront-signer
Signs CloudFront URLs and generates signed cookies to restrict access to private CloudFront distributions. Uses your CloudFront key pair (trusted key group), not IAM credentials.
CloudFront signing is fundamentally different from S3 presigning. CloudFront uses a private RSA key from a CloudFront key group, not AWS SigV4.
getSignedUrl(options) — canned policy
The simplest form signs a URL with a canned policy (expiration time only).
The full CloudFront URL to sign. Required for canned policy. Can be omitted when using a custom
policy (the URL is extracted from the policy).The public key ID of your CloudFront trusted key group key pair.
The RSA private key contents (PEM format). Load from a secure source such as AWS Secrets Manager.
Expiration date/time. Accepts any value compatible with the
Date constructor.Start date/time for access (custom policy only). Content is inaccessible before this time.
Restrict access to a specific IP address or CIDR range (custom policy only). Example:
"198.51.100.0/24".A pre-built custom policy JSON string. When provided,
dateLessThan, dateGreaterThan, and ipAddress are ignored — include them in the policy instead.getSignedUrl(options) — custom policy
Use a custom policy to restrict access by IP address or time window:
getSignedCookies(options)
Returns cookies that grant access to all URLs matching a pattern. Useful when you want to restrict an entire section of a distribution.
Domain and Path matching your distribution:
getSignedCookies accepts the same options as getSignedUrl, including the custom policy parameter.
Polly presigner — @aws-sdk/polly-request-presigner
Generates a presigned URL for a Polly SynthesizeSpeech request so browsers can play audio directly without sending AWS credentials.
getSynthesizeSpeechUrl(options)
An initialized
PollyClient (bare-bones) or Polly (aggregated) instance.Parameters for the
SynthesizeSpeech operation.The text to synthesize. Up to 3000 characters (billed characters).
Audio format:
"mp3", "ogg_vorbis", "pcm", or "json".The Polly voice ID (e.g.,
"Joanna", "Matthew", "Kimberly").Seconds until the presigned URL expires.
Promise<string> — a presigned URL. Use as the src attribute of an <audio> element or a direct HTTP GET request.
Example with a browser audio element:
SigV4a — multi-region signing
SigV4a is required for services with multi-region endpoints, most notably S3 Multi-Region Access Points (MRAP). A SigV4a signature is valid across all AWS regions, unlike standard SigV4 which is region-specific.Choosing an implementation
@aws-sdk/signature-v4a
Pure JavaScript implementation. Works in both Node.js and browsers. Larger bundle size — evaluate whether your use case requires SigV4a in the browser before adding this dependency.
@aws-sdk/signature-v4-crt
AWS Common Runtime (CRT) native binding. Node.js only. Better performance. Required for S3 MRAP and S3 Object Integrity with CRC checksums.
JS implementation (@aws-sdk/signature-v4a)
CRT implementation (@aws-sdk/signature-v4-crt)
authSchemePreference for explicit SigV4a
If a service supports both sigv4 and sigv4a, you can express a preference at the client level:
sigv4aSigningRegionSet
Override the signing region set for SigV4a requests (default is ["*"]):
Values other than
["*"] have limited service support. This configuration is rarely needed.Services requiring SigV4a
| Service / Feature | Package |
|---|---|
| S3 Multi-Region Access Points (MRAP) | @aws-sdk/signature-v4-crt or @aws-sdk/signature-v4a |
| S3 Object Integrity (CRC checksums) | @aws-sdk/signature-v4-crt |
| CloudFront KeyValueStore | @aws-sdk/signature-v4-crt |
| S3 CRC64-NVME checksums (optional perf) | @aws-sdk/crc64-nvme-crt |