aws-core
| Kind | kit |
|---|---|
| Capabilities | net |
| Categories | cloud web |
| Keywords | aws amazon cloud authentication sigv4 |
AWS core library - credentials, signing, and shared utilities
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
docs/.keep | Placeholder for generated documentation output |
examples/basic.kit | Basic credential, region, and URL encoding example |
examples/regions.kit | AWS region and custom endpoint example |
examples/sign-request.kit | AWS Signature Version 4 request signing example |
kit.toml | Package manifest with metadata, capabilities, tasks, and dependencies |
src/aws.kit | AWS credentials, region helpers, SigV4 signing, and request execution |
tests/aws-core.test.kit | End-to-end tests for the public AWS core API |
tests/types.test.kit | Type and record behavior tests |
Dependencies
crypto- HMAC-SHA256 and SHA256 support for AWS Signature Version 4
Capabilities
This package declares the net capability in kit.toml because AWS.execute can send signed HTTP requests.
The credential, region, URL encoding, and request signing helpers can be used without making network calls.
Installation
kit add gitlab.com/kit-lang/packages/kit-aws-core.gitUsage
import Kit.AwsCore as AWS
main = fn =>
# Credentials can be passed explicitly.
creds = AWS.credentials "AKIAEXAMPLE" "secretkey123"
region = AWS.us-east-1
# Sign a request without sending it.
signed = AWS.sign-request creds region "s3" "GET" "https://bucket.s3.us-east-1.amazonaws.com/key" [] ""
match signed
| Ok req ->
println "Signed ${req.method} request"
println "URL: ${req.url}"
println "Header count: ${Int.to-string (List.length req.headers)}"
| Err err ->
println "Signing failed: ${show err}"
mainLoad credentials and region from the environment:
import Kit.AwsCore as AWS
main = fn =>
match (AWS.credentials-from-env, AWS.region-from-env)
| (Ok creds, Ok region) ->
println "Loaded AWS credentials for ${region.name}"
println "Access key: ${creds.access-key-id}"
| (Err err, _) ->
println "Credential error: ${show err}"
| (_, Err err) ->
println "Region error: ${show err}"
mainEnvironment variables used by this package:
| Variable | Required | Description |
|---|---|---|
AWS_ACCESS_KEY_ID | Yes | AWS access key ID |
AWS_SECRET_ACCESS_KEY | Yes | AWS secret access key |
AWS_SESSION_TOKEN | No | Session token for temporary credentials |
AWS_REGION | No | Preferred region variable |
AWS_DEFAULT_REGION | No | Fallback region variable |
Development
Running Examples
Run examples with the interpreter:
kit run examples/basic.kit
kit run examples/regions.kit
kit run examples/sign-request.kitCompile an example to a native binary:
kit build examples/basic.kit && ./basicThe examples import ../src/aws.kit so they exercise the local workspace source during development.
Running Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning Parity
Check interpreter and compiled output parity for examples:
kit parity --no-spinner --failures-onlyThis is useful after changing examples or shared signing behavior because parity verifies that kit run and kit build produce matching output.
Running kit dev
Run the standard development workflow (format, check, examples, test):
kit devThis will:
- Format and check source files in
src/ - Format and check examples in
examples/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit doc src/aws.kitNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html.
Cleaning Build Artifacts
Remove generated files, caches, coverage reports, parity reports, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis installs the package to ~/.kit/packages/@kit/aws-core/, making it available for import as Kit.AwsCore in other projects.
When editing this package, run examples through the local examples/ files or reinstall with kit install before testing another project that imports Kit.AwsCore.
License
This package is released under the MIT License - see LICENSE for details.
Exported Functions & Types
AWSError
AWS error type with specific variants for different failure modes.
Variants
AWSCredentialError {message}AWSRegionError {message}credentials
Create AWS credentials explicitly from access key and secret key
Use this when you have credentials hardcoded or loaded from a custom source. For temporary credentials, use credentials-with-token instead.
Parameters:
access-key-id- String - AWS access key IDsecret-access-key- String - AWS secret access key
Returns: Credentials - Credentials object with empty session token
String -> String -> Credentials
creds = AWS.credentials "AKIAIOSFODNN7EXAMPLE" "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"credentials-with-token
Create AWS credentials with session token for temporary credentials
Use this for temporary credentials obtained from AWS STS, IAM roles, or federated access.
Parameters:
access-key-id- String - AWS access key IDsecret-access-key- String - AWS secret access keysession-token- String - Session token for temporary credentials
Returns: Credentials - Credentials object with session token
String -> String -> String -> Credentials
creds = AWS.credentials-with-token access-key secret-key session-tokencredentials-from-env
Load AWS credentials from environment variables
Looks for the following environment variables: - AWS_ACCESS_KEY_ID (required) - AWS_SECRET_ACCESS_KEY (required) - AWS_SESSION_TOKEN (optional, for temporary credentials)
Returns: Result Credentials String - Ok with credentials if found, Err if not
Errors: Returns Err if AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY are not set
() -> Result Credentials AWSError
match AWS.credentials-from-env()
| Ok creds -> use-credentials creds
| Err err -> print "Error: ${err}"us-east-1
Pre-configured AWS region: US East (N. Virginia)
us-east-2
Pre-configured AWS region: US East (Ohio)
us-west-1
Pre-configured AWS region: US West (N. California)
us-west-2
Pre-configured AWS region: US West (Oregon)
eu-west-1
Pre-configured AWS region: Europe (Ireland)
eu-west-2
Pre-configured AWS region: Europe (London)
eu-central-1
Pre-configured AWS region: Europe (Frankfurt)
ap-northeast-1
Pre-configured AWS region: Asia Pacific (Tokyo)
ap-southeast-1
Pre-configured AWS region: Asia Pacific (Singapore)
ap-southeast-2
Pre-configured AWS region: Asia Pacific (Sydney)
region
Create a custom AWS region configuration
Use this for regions not pre-defined above or for newer AWS regions.
Parameters:
name- String - AWS region name (e.g., "us-east-1", "eu-central-1")
Returns: Region - Region configuration with standard amazonaws.com endpoint
NonEmptyString -> Region
region = AWS.region "ap-south-1"region-with-endpoint
Create a region with custom endpoint for S3-compatible services
Use this for LocalStack, MinIO, Wasabi, or other S3-compatible services.
Parameters:
name- String - Region name (can be arbitrary for non-AWS services)endpoint- String - Custom endpoint domain (e.g., "localhost:4566" for LocalStack)
Returns: Region - Region configuration with custom endpoint
NonEmptyString -> NonEmptyString -> Region
# LocalStack
region = AWS.region-with-endpoint "us-east-1" "localhost:4566"
# MinIO
region = AWS.region-with-endpoint "us-east-1" "localhost:9000"region-from-env
Load AWS region from environment variables
Looks for the following environment variables in order: 1. AWS_REGION 2. AWS_DEFAULT_REGION
Returns: Result Region String - Ok with region if found, Err if not
Errors: Returns Err if neither AWS_REGION nor AWS_DEFAULT_REGION are set
() -> Result Region AWSError
match AWS.region-from-env()
| Ok region -> use-region region
| Err err -> print "Error: ${err}"sign-request
Sign a request using AWS Signature Version 4. Returns a SignedRequest with Authorization header added.
Credentials -> Region -> String -> String -> NonEmptyString -> List (String, String) -> String -> Result SignedRequest AWSError
execute
Execute a signed request.
SignedRequest -> Result String String
url-encode
URL encode a string (for paths and query params).
String -> String