Values
AWS_REGION_PATTERN
AWS_REGION_PATTERN: Str "^[a-z]{2,}(-[a-z]+)+-[0-9]+$"
BUCKET_PATTERN
BUCKET_PATTERN: Str "^[A-Za-z0-9][A-Za-z0-9._-]{1,253}[A-Za-z0-9]$"
CREDENTIAL_OPTS
CREDENTIAL_OPTS: Vec [
"credentials",
"access-key-id",
"secret-access-key"
]
HOST_PATTERN
HOST_PATTERN: Str "^([A-Za-z0-9._-]+|\\[[0-9A-Fa-f:.]+\\])(:[0-9]+)?$"
MISSING_CREDENTIALS
MISSING_CREDENTIALS: Str "aws: credentials are not set. Set aws.access-key-id and aws.secret-access-key in Context Variables, or pass {access-key-id: ..., secret-access-key: ...} in the call's opts."
STORE_REGION_PATTERN
STORE_REGION_PATTERN: Str "^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$"
UNSAFE_URL_PATTERN
UNSAFE_URL_PATTERN: Str "[\\x00-\\x1F\\x7F\\\\]"
VIRTUAL_HOST_BUCKET_PATTERN
VIRTUAL_HOST_BUCKET_PATTERN: Str "^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$"
Functions
bedrock-endpoint
fn (region: Str): Str
Get the Bedrock control plane endpoint URL for a given region
bedrock-runtime-endpoint
fn (region: Str): Str
Get the Bedrock runtime endpoint URL for model invocation
canonical-headers
fn (headers: Map): Str
Create canonical headers string for AWS Signature V4: lowercase names sorted by name, values trimmed with runs of spaces collapsed.
canonical-uri
fn (path: Str, service: Str): Str
The canonical URI of a request path. S3 signs the path as sent, single-encoded.
Every other service encodes the sent path again, so a path segment a%3Ab signs
as a%253Ab. / is never encoded in either case.
check-bucket
fn (bucket: Any): Any
bucket when it is a valid S3 bucket name (3 to 255 letters, numbers, dots, hyphens and underscores, starting and ending with a letter or number, no ..), else an Err that doesn't echo the value. Dotted names are valid; see is-virtual-host-bucket.
check-region
fn (region: Any, source: Str, has-endpoint: Bool): Any
region when it is safe to use, else an Err naming source and not echoing the value.
Without a custom endpoint it goes into an AWS hostname and must be a plain AWS region
name like us-east-1. With one (has-endpoint) it only signs, so a store's own name
like auto passes, but still nothing that could leave its place.
check-signing-target
fn (url: Str, region: Any): Any
Null when url and region are safe to sign for: a plain host with no user info, no backslash or control characters in the URL, and a region that stays one segment of the signing scope. Else an Err that doesn't echo them.
collapse-spaces
fn (value: Str): Str
create-canonical-request
fn (method: Str, path: Str, query: Str, headers-str: Str, signed-headers-str: Str, payload-hash: Str): Str
Create AWS Signature V4 canonical request string
create-string-to-sign
fn (amz-date: Str, date-stamp: Str, region: Str, service: Str, canonical-request-hash: Str): Str
Create AWS Signature V4 string to sign
credentials-from-ctx
fn (ctx-values: Map): Credentials
credentials-from-opts
fn (opts: Map): Any
credentials-from-value
fn (value: Any): Credentials
derive-signing-key
fn (secret_key: Str, date_stamp: Str, region: Str, service: Str): Bytes
Derive AWS signing key using HMAC-SHA256 chain
dynamodb-endpoint
fn (region: Str): Str
Get the DynamoDB endpoint URL for a given region
encode-query-param
fn (param: Str): Str
URL-encode the name and value of a query parameter, keeping existing %XX escapes. A parameter with no = gets an empty value (uploads becomes uploads=).
error-code-name
fn (code: Str?): Str?
error-fields
fn (body: Any): Map
The code, message and request_id an AWS error body carries, from JSON (__type, code, message) or XML (<Code>, <Message>, <RequestId>). A field the body doesn't carry is missing. Exposed for testing.
get-amz-date
fn (): Str
Get current UTC timestamp in AWS format (YYYYMMDD'T'HHMMSS'Z')
get-credentials
fn (): Credentials
Get AWS credentials from context (aws.access-key-id, aws.secret-access-key, aws.session-token). Returns an Err naming the variables when they aren't set.
aws.access-key-id, aws.secret-access-key, aws.session-token
get-date-stamp
fn (): Str
Get current UTC date in AWS format (YYYYMMDD)
get-region
fn (): Str
Get AWS region from context (aws.region). Defaults to us-east-1 if not set. An Err when it isn't a plain region name; see check-region.
aws.region, aws.endpoint
hex-prefix
fn (s: Str): Str?
is-virtual-host-bucket
fn (bucket: Str): Bool
True when a bucket can be a hostname label: 3 to 63 lowercase letters, numbers and hyphens. Dotted names don't match the TLS wildcard certificate, and uppercase legacy names don't survive a hostname, so those use path-style.
lambda-endpoint
fn (region: Str): Str
Get the Lambda endpoint URL for a given region
mark-opts-credentials
fn (opts: Map?): Null
non-blank
fn (value: Any): Any
normalize-encoding
fn (s: Str): Str
URI encode s, keeping valid %XX escapes (in uppercase) so already-encoded input isn't encoded twice. A % that doesn't start an escape becomes %25.
normalize-endpoint
fn (endpoint: Any, source: Str): Any
opt-str
fn (value: Any): Str?
Str(value), keeping null as null. For JSON fields that AWS sends as numbers (epoch dates) and the response types declare Str?.
parse-int
fn (value: Any): Int?
A whole non-negative number from a header or XML text, or null when it is absent or isn't one. Never fails.
parse-json-body
fn (response: Result): Any
Return response as an HttpResponse, with a JSON body parsed when the runtime left it
as Bytes (application/x-amz-json-1.0 and -1.1 responses). A transport in opts can
return a plain Map, so the result is typed here for AwsError(response) to run its arrow.
parse-url
fn (url: Str): Map
Parse a URL into components: {host, path, query}
regional-url
fn (prefix: Str, region: Str): Str
https://<prefix>.<region>.amazonaws.com, or an Err when region isn't a plain AWS region name.
replace-all-char
fn (s: Str, from: Str, to: Str): Str
Replace all occurrences of char in string
request
fn (method: Str, url: Str, service: Str, region: Str, headers: Map, body: Str | Bytes): ::hot::http/HttpResponse
fn (method: Str, url: Str, service: Str, region: Str, headers: Map, body: Str | Bytes, credentials: Credentials): ::hot::http/HttpResponse
fn (method: Str, url: Str, service: Str, region: Str, headers: Map, body: Str | Bytes, opts: Map): ::hot::http/HttpResponse
Make an authenticated request to an AWS service endpoint.
Handles credential retrieval and Signature V4 signing automatically. Used internally by all AWS service packages.
resolve
fn (opts: Map?): Map
fn (): Map
Settings for one call: opts over the context variables, over the defaults.
Returns {credentials, region, endpoint?, transport?, path-style?}, or an Err
when no credentials are available.
opts keys, all optional:
access-key-id,secret-access-key,session-token: per-call credentials. When they are given the context credentials are ignored for that call. An access key or secret that is present but null or blank is an Err: leave it out instead. A null or blanksession-tokenmeans no session token.credentials: a readyCredentialsvalue, instead of the three keys.region: signing region and endpoint region. It goes into a hostname, so it must be a plain AWS region name likeus-east-1, or an Err comes back. With a custom endpoint it only signs, so a store's own name likeautois fine.endpoint: base URL replacing the AWS endpoint (LocalStack, a VPC endpoint, an S3-compatible store). It needs credentials in the same opts, so the project's access key id and signatures never go to a host set per call. Theaws.endpointcontext variable sets one for the project, used with any credentials.path-style: aws-s3 only, see its README.transport: a function taking the signedHttpRequestand returning anHttpResponse, used instead of the network. For tests.
Per-call credentials stay in the call. Nothing is written to ctx, so parallel flows and tenants never share them, and they are masked in the run's call records.
Example
resolved ::aws::core/resolve({access-key-id: "AKIAEXAMPLE", secret-access-key: "secret", region: "eu-west-1"})
resolved.region // "eu-west-1"
aws.access-key-id, aws.secret-access-key, aws.session-token, aws.region, aws.endpoint
resolve-from
fn (opts: Map?, ctx-values: Map): Map
The one resolver, pure: settings for a call from opts first, then
ctx-values (a Map of context variables), then defaults. Returns
{credentials, region, endpoint?, transport?, path-style?}, or an Err when
credentials are missing or only partly given, or when access-key-id,
secret-access-key or credentials is present in opts but null or blank
(naming the key; it never falls back to context), when opts sets endpoint
without credentials of its own, or when the region, from either place, isn't
a plain region name (check-region).
Credentials in opts mean the context credentials, session token included,
are ignored for the call.
Nothing is written to ctx. Exposed for testing; resolve feeds it the context.
response-header
fn (response: Any, name: Str): Str?
Read a header from an HTTP response by name, in any case. HTTP responses carry lowercase header names.
s3-endpoint
fn (bucket: Str, region: Str): Str
Get the S3 URL of a bucket in a region: virtual-hosted, https://<bucket>.s3.<region>.amazonaws.com,
the standard form in every region including us-east-1. A bucket that can't be a hostname label
(dots, legacy uppercase names) gets the path-style form, https://s3.<region>.amazonaws.com/<bucket>.
An Err when the bucket or region isn't valid.
secrets-manager-endpoint
fn (region: Str): Str
Get the Secrets Manager endpoint URL for a given region
send-signed
fn (method: Str, url: Str, service: Str, resolved: Map, headers: Map, body: Str | Bytes): ::hot::http/HttpResponse
Sign a request with resolved (from resolve) and send it, through
resolved.transport when set. The Host header comes from url. JSON bodies
are parsed whatever the JSON content type. Used by all AWS service packages.
service-url
fn (resolved: Map, prefix: Str): Str
Base URL (no trailing slash) for a service host prefix such as sqs or bedrock-runtime: resolved.endpoint when set, else https://<prefix>.<region>.amazonaws.com.
ses-endpoint
fn (region: Str): Str
Get the SES endpoint URL for a given region
sign-request
fn (method: Str, url: Str, region: Str, service: Str, credentials: Credentials, headers: Map, payload: Str | Bytes | Null): Map
fn (method: Str, url: Str, region: Str, service: Str, credentials: Credentials, headers: Map, payload: Str | Bytes | Null, amz-date: Str): Map
Sign a request using AWS Signature V4. Returns headers map with Authorization header.
url is the URL as it will be sent, with path segments and query values already
encoded (uri-encode, uri-encode-path). The Host header always comes from url:
the HTTP client sends that host whatever the headers say. The arity with amz-date
(YYYYMMDD'T'HHMMSS'Z') signs at that time instead of now. An Err when the URL's host or
the region isn't plain; see check-signing-target.
sign-url
fn (method: Str, url: Str, region: Str, service: Str, credentials: Credentials, expires_in: Int): Str
fn (method: Str, url: Str, region: Str, service: Str, credentials: Credentials, expires_in: Int, amz-date: Str): Str
fn (method: Str, url: Str, region: Str, service: Str, credentials: Credentials): Str
Sign a URL using AWS Signature V4 query string signing.
This is used for presigned URLs where the signature goes in the query string instead of headers. The returned URL can be used by anyone without credentials.
Parameters:
- method: HTTP method (GET, PUT, etc.)
- url: Base URL to sign
- region: AWS region
- service: AWS service name (s3, etc.)
- credentials: AWS credentials
- expires_in: URL expiration time in seconds (default 3600 = 1 hour, max 604800 = 7 days)
- amz-date: signing time (YYYYMMDD'T'HHMMSS'Z'), default now
An Err when the URL's host or the region isn't plain; see check-signing-target.
signature-for
fn (canonical-request: Str, amz-date: Str, region: Str, service: Str, secret-access-key: Str): Str
The hex SigV4 signature of a canonical request at amz-date, in region and service.
signed-headers
fn (headers: Map): Str
Create signed headers list (semicolon-separated lowercase header names)
sort-query-params
fn (query: Str?): Str
The canonical query string: each name and value URL-encoded, sorted by encoded name, then by encoded value.
sqs-endpoint
fn (region: Str): Str
Get the SQS endpoint URL for a given region
str-or-null
fn (value: Any): Str?
uri-encode
fn (s: Str): Str
URI encode a string for an AWS request: every byte except A-Z a-z 0-9 - _ . ~ becomes %XX (uppercase hex, UTF-8), / and % included.
uri-encode-path
fn (path: Str): Str
URI encode a path or S3 object key for a request URL: uri-encode on each /-separated segment.
url-encode-path
fn (path: Str): Str
URL-encode a URI path once for an AWS request, keeping / and existing %XX escapes. This is the S3 canonical URI; see canonical-uri for other services.
url-encode-value
fn (value: Str): Str
URL-encode a value for an AWS query string. The same as uri-encode.
wire-path
fn (path: Str): Str
The path as the HTTP client sends it: spaces, quotes, angle brackets, braces, backticks and non-ASCII characters escaped, everything else (existing %XX included) unchanged.
xml-child-text
fn (elem: Any, name: Str): Str?
xml-error-fields
fn (root: Result): Map
Types
AwsError
AwsError type {
status: Int,
code: Str?,
message: Str?,
request_id: Str?,
body: Any
}
Error response from an AWS service request.
Credentials
Credentials type {
access_key_id: Str,
secret_access_key: Str,
session_token: Str?
}
AWS credentials used for signing requests.
Region
Region type {
name: Str
}
AWS region identifier.