aws-core
AWS core types, authentication (SigV4), and utilities shared by all AWS packages.
Configuration
AWS packages read these context variables, unless a call passes credentials in opts. A call with no credentials from either gets an Err naming them.
aws.access-key-id- AWS access key IDaws.secret-access-key- AWS secret access keyaws.session-token- Session token for temporary credentials (STS, IAM roles)aws.region- AWS region (defaults tous-east-1)aws.endpoint- Base URL replacing the AWS endpoints, for LocalStack or an S3-compatible store
Per-call credentials
Every function in the AWS service packages takes opts as its last argument. resolve(opts) turns it into the credentials, region and endpoint for that call: opts first, then context, then defaults. Nothing is written to context, so one run can serve many tenants, in parallel flows too.
A per-call credential is masked in the run's call records, including inside strings like Bearer ${key}. A secret shorter than 8 bytes is masked only as a whole value. Records of your own calls that finished before this one may already be written, so mark a credential your code fetches with ::hot::ctx/mark-secret as soon as you have it.
::core ::aws::core
resolved ::core/resolve({
access-key-id: "AKIAEXAMPLE",
secret-access-key: "tenant-secret",
session-token: "optional-for-temporary-credentials",
region: "eu-west-1"
})
resolved.credentials.access_key_id // "AKIAEXAMPLE"
resolved.region // "eu-west-1"
access-key-id,secret-access-key,session-token: whenoptshas credentials, the context credentials are ignored for the call, session token included. A null or blanksession-tokenmeans no session token.credentials: a readyCredentialsvalue, instead of those keys.region: signing and endpoint region. It goes into a hostname, so it must be a plain AWS region name likeus-east-1, fromoptsor context. With a custom endpoint it only signs, so a store's own name likeautois fine.endpoint: base URL replacing the AWS endpoint.
These are errors, so that a tenant with a missing key never runs on the project's credentials:
access-key-id,secret-access-keyorcredentialsinoptsbut null or blank (leave it out to use context)- half a key pair, or a session token alone
- an
endpointinoptswithout credentials inopts: the project's access key id and signatures never go to a host set per call - a region, bucket or endpoint that could change where the request goes, such as one with
/,@, a backslash or a control character. The error doesn't repeat the value.
Provided Functions
resolve(opts)- Credentials, region and endpoint for one callget-credentials()- Retrieve AWS credentials from contextget-region()- Get the configured AWS regionsign-request()- Sign requests with AWS Signature V4; pass anamz-dateto pin the timesign-url()- Presign a URL with AWS Signature V4send-signed()- Sign and send a request with resolved settingsuri-encode(),uri-encode-path()- Encode values and paths for a request URL
sign-request and sign-url take the URL as it will be sent: encode path segments and query values first. S3 signs the path as sent; other services encode it once more, as SigV4 requires.
Types
Credentials- AWS credential containerAwsError- Standard error type for AWS API failures, withcode,messageandrequest_idread from the response
Documentation
Full documentation available at hot.dev/pkg/aws-core
License
Apache-2.0 - see LICENSE