ballerinax/aws.auth Ballerina library

0.1.0

Overview

The auth submodule of the ballerinax/aws package provides AWS authentication: credential resolution across all standardized AWS credential sources (with automatic refresh) and AWS Signature Version 4 (SigV4) request signing. It is the authentication foundation used by the ballerinax/aws.* connectors, and can be used directly to call AWS services that do not have a dedicated connector yet.

Region and endpoint utilities live in the package's root module, ballerinax/aws.

Credential sources

The AuthConfig union covers all standardized AWS credential sources:

Config typeSourceTypical use
StaticAuthConfigExplicit access keys (+ optional session token)Tests, CI-injected secrets
ProfileAuthConfigA named profile in ~/.aws/credentialsDeveloper machines
AssumeRoleConfigSTS assume-role, composable over any base identityCross-account access, least privilege
WebIdentityConfigAn OIDC token exchanged via STSEKS IRSA, CI/CD OIDC
SsoAuthConfigAn IAM Identity Center session (aws sso login)Enterprise developer machines
ProcessAuthConfigAn external credential_process commandIAM Roles Anywhere, credential brokers
DEFAULT_CREDENTIALSThe default provider chain (env vars, SSO, profile, container, EC2 IMDS, …)Production on AWS

Quickstart

Step 1: Import the module

Copy
import ballerinax/aws.auth;

Step 2: Create a credential provider

Create a CredentialProvider once, at initialization. On AWS infrastructure the default provider chain resolves credentials automatically:

Copy
auth:CredentialProvider credProvider = check new (auth:DEFAULT_CREDENTIALS);

Other credential sources use the same API with a different configuration — for example, STS assume-role composed over any base identity:

Copy
auth:CredentialProvider credProvider = check new ({
    roleArn: "arn:aws:iam::123456789012:role/reporting-read-only",
    sourceCredentials: auth:DEFAULT_CREDENTIALS
});

Step 3: Resolve credentials

Fetch credentials per request; expiring temporary credentials (STS, SSO, instance profile) are renewed transparently:

Copy
auth:Credentials credentials = check credProvider.getCredentials();

Release the provider's resources when it is no longer needed:

Copy
check credProvider.close();

Step 4: Sign a request

Sign requests to any AWS service — including services without a dedicated Ballerina connector. getSignedHeaders returns the headers to attach to the outbound request:

Copy
map<string> signedHeaders = check auth:getSignedHeaders({
    method: "POST",
    host: "sns.us-east-1.amazonaws.com",
    headers: {"content-type": "application/x-www-form-urlencoded"},
    payload: "Action=CreateTopic&Name=orders".toBytes()
}, credentials, "us-east-1", "sns");

Import

import ballerinax/aws.auth;Copy

Other versions

Metadata

Released date: 13 days ago

Version: 0.1.0

License: Apache-2.0


Compatibility

Platform: java21

Ballerina version: 2201.12.0

GraalVM compatible: Yes


Pull count

Total: 510

Current verison: 135


Weekly downloads


Source repository


Keywords

Security/Authentication

Vendor/Amazon

Type/Library

AWS

SigV4

credentials


Contributors