aws

package
v2.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 35 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package aws resolves AWS credentials the way the AWS CLI and SDKs do, and signs requests with them by SigV4

Index

Constants

This section is empty.

Variables

View Source
var BedrockControl = Service{ID: "bedrock", Title: "the Bedrock control plane", Prefix: "bedrock", FIPSPrefix: "bedrock-fips",
	FIPS: []string{"us-east-1", "us-east-2", "us-west-1", "us-west-2", "ca-central-1", "ca-west-1", "us-gov-east-1", "us-gov-west-1"}}

Bedrock's control plane, which lists the models and resolves the inference profiles; FIPS hosts in the regions AWS lists, no dual-stack host

View Source
var BedrockMantle = Service{Title: "Bedrock Mantle", Prefix: "bedrock-mantle", FIPSPrefix: "bedrock-mantle-fips", Stacked: true}

Bedrock Mantle, which serves OpenAI's models over the Responses API: its hosts are on the dual-stack domain and none is FIPS, and no configured endpoint of AWS names it

View Source
var BedrockRuntime = Service{ID: "bedrock_runtime", Title: "Bedrock Runtime", Prefix: "bedrock-runtime", FIPSPrefix: "bedrock-runtime-fips",
	FIPS: []string{"us-east-1", "us-east-2", "us-west-2", "ca-central-1", "us-gov-east-1", "us-gov-west-1"}}

Bedrock's runtime, which serves the models; FIPS hosts in the regions AWS lists, no dual-stack host

View Source
var ErrNoCredentials = errors.New("No AWS sign-in was found. Run `aws sso login` or `aws configure`, or set AWS_PROFILE.")

The chain walked to its end with no source answering

View Source
var SSO = Service{ID: "sso", Title: "the IAM Identity Center portal", Prefix: "portal.sso", FIPSPrefix: "portal.sso-fips",
	DualStack: identityRegions, Both: identityFIPS}

The portal of IAM Identity Center, which gives the keys of an AWS SSO sign-in; its FIPS hosts are dual-stack only

View Source
var SSOOIDC = Service{ID: "sso_oidc", Title: "IAM Identity Center OIDC", Prefix: "oidc", FIPSPrefix: "oidc-fips", DualStack: identityRegions,
	Both: identityFIPS}

IAM Identity Center's OIDC service, which renews an AWS SSO sign-in; its FIPS hosts are dual-stack only

View Source
var STS = Service{ID: "sts", Title: "AWS STS", Prefix: "sts", FIPSPrefix: "sts-fips", FIPS: identityFIPS, DualStack: identityRegions,
	Both: identityFIPS, Hosts: map[string]map[Variant]string{"us-gov-east-1": {{FIPS: true}: "sts.us-gov-east-1.amazonaws.com"},
		"us-gov-west-1": {{FIPS: true}: "sts.us-gov-west-1.amazonaws.com"}}}

AWS STS, which signs in with roles and web identities and says whose keys sign; its FIPS host in GovCloud is its ordinary one

Functions

func ApplicationProfile

func ApplicationProfile(model string) bool

Whether the model id is an application inference profile, which wraps the model it serves

func Call

func Call(ctx context.Context, client *http.Client, operation, method, address string, in any, sign func(*http.Request, []byte) error, bearer string,
	out any) error

Calls a JSON operation of an AWS service at the address, the request signed by sign, else carrying the bearer key, the answer decoded into out; an answer that isn't a success as a ServiceError

func ControlURL

func ControlURL(region string) string

Address of the ordinary host of the Bedrock control plane of a region

func Domain

func Domain(host string) bool

Whether the host is one of AWS's, under the ordinary or the dual-stack domain of one of its partitions

func EndpointRegion

func EndpointRegion(address string) string

Region a Bedrock address names, empty for any other

func ErrorOf

func ErrorOf(header http.Header, status int, body []byte) (string, string)

Code and message of an AWS JSON error answer: the code from x-amzn-ErrorType, else __type, else code, without its namespace

func Flag

func Flag(where, value string) (bool, error)

Switch a variable or a key of an AWS profile sets: true or false in any case, as AWS reads them; an error naming where it was read for any other value, which is never taken as off

func Getenv

func Getenv(lookup func(name string) (string, bool)) httpx.Env

Variable reader of a lookup, empty for one it has no value of: the environment the requests of a chain are made in

func Identity

func Identity(ctx context.Context, env httpx.Env, keys Keys, at Endpoint) (string, error)

ARN of the principal the keys sign as, from STS GetCallerIdentity at the STS endpoint given, signed for its region, asked through the proxy and authorities of the environment, the profile's

func MantleURL

func MantleURL(region string) string

Address of the OpenAI compatible Responses API Bedrock Mantle serves in a region

func ModelPath

func ModelPath(model, operation string) string

Runtime path of an operation on a model, the model id percent encoded as the SDKs do it, every reserved byte but the colon

func NoMFA

func NoMFA(context.Context, string) (string, error)

Refusal of the MFA code a role names, for a chain that signs requests where no terminal is its own to ask on, such as the server's under the windows it serves: the code is typed at the AWS CLI instead, whose kept keys of the role the chain takes

func Sections

func Sections(text string) (map[string]map[string]string, error)

Values of each section of an INI text by configparser's rules, the AWS config's format and gcloud's, the names of values lowercased

func SharedProfiles

func SharedProfiles(getenv func(string) string) []string

Names of the profiles of the shared config and credentials files, those the variables name or else those in ~/.aws, in order of the alphabet; none when neither can be read

func Sign

func Sign(req *http.Request, body []byte, keys Keys, service, region string, now time.Time) error

Signs the request in place: its date, the session token and the Authorization header over the exact body given

func Signer

func Signer(keys Provider, service, region string) func(request *http.Request, body []byte) error

Signs each request by SigV4 for the service with the provider's keys, in the region the request's Bedrock address names, else the one given

func Suffix

func Suffix(region string) string

DNS suffix of the ordinary hosts of the partition the region is in

func Title

func Title(link string) string

What a link of the chain signs in through, as a sentence names it after "through" or "the sign-in of"

func Viewing

func Viewing(ctx context.Context) context.Context

Context of a look at a sign-in, such as the page of a provider, under which an SSO token about to expire is read as it is kept and never renewed, so a look never spends a refresh token the AWS CLI or another icebath shares, the next request renewing it

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

The default chain of one session: walked once, then renewed through the source that answered

func NewChain

func NewChain(opts Options) *Chain

func (*Chain) Choice

func (c *Chain) Choice() (Choice, error)

What the chain asks of AWS's hosts, FIPS and dual-stack, and where each ask was read

func (*Chain) Endpoint

func (c *Chain) Endpoint(service Service, region string) (Endpoint, error)

Address of the service in the region as the chain's settings have it, its configured endpoint winning over FIPS and dual-stack as AWS orders them; an error in words when a switch does not read or AWS publishes no host of what is asked

func (*Chain) Planned

func (c *Chain) Planned() (string, bool)

Link of the chain a request would take, named as the walk of Retrieve names it, read from the variables and the shared files alone: no service is asked and no program runs, so a look at a sign-in never waits on the network or spends a renewal. The link the walk took once a request walked it. Maybe while only the instance metadata service could answer, which only the walk of a request asks; empty when no link would

func (*Chain) Profile

func (c *Chain) Profile() string

Profile in use

func (*Chain) Region

func (c *Chain) Region() string

Region the session's environment or profile names, empty when neither does

func (*Chain) Retrieve

func (c *Chain) Retrieve(ctx context.Context) (Keys, error)

func (*Chain) SSO

func (c *Chain) SSO() (Endpoint, Endpoint, error)

Addresses an AWS SSO sign-in of the chain's profile calls in its sso_region: the portal that gives its keys and the OIDC service that renews it; an error in words when the profile names no sso_region or AWS publishes no host of what is asked

func (*Chain) STS

func (c *Chain) STS() (Endpoint, error)

STS endpoint the chain's requests go to, with the region they are signed for

func (*Chain) Stale

func (c *Chain) Stale() bool

Whether a shared file changed since the chain read them, so a chain built again reads what they say now

type Choice

type Choice struct {
	Variant
	FIPSFrom, DualStackFrom string
}

What is asked of AWS's hosts, and where each ask was read: a variable, the key of an AWS profile, or the switch of the caller's own setting; empty where nothing asked

type Endpoint

type Endpoint struct {
	Service Service
	// Region the address serves, which requests to it are signed for
	Region string
	// Scheme and host, and the path a configured address has, without a trailing slash
	URL string
	// Kind of host AWS publishes it as, zero for a configured address
	Variant Variant
	// Where a configured address came from, such as AWS_ENDPOINT_URL_BEDROCK_RUNTIME; empty for a host AWS publishes
	Configured string
}

Address a service of AWS is called at

func Resolve

func Resolve(service Service, region string, asked Choice, configured, from string) (Endpoint, error)

Address of the service in the region: the configured address when one is given, since AWS's configured endpoints win over FIPS and dual-stack, else the host AWS publishes of the variant asked; an *EndpointError where it publishes none, never another host

func (Endpoint) Host

func (e Endpoint) Host() string

Host of the address

type EndpointError

type EndpointError struct {
	Service Service
	Region  string
	Asked   Choice
}

A host asked of a service in a region where AWS publishes none of that kind

func (*EndpointError) Error

func (e *EndpointError) Error() string

type Error

type Error struct {
	Source  string
	Message string
	Err     error
}

Failure of one source of the chain, naming it

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Keys

type Keys struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
	Expires         time.Time
	// Where in the chain the keys came from, such as env, sso or iam-role
	Source string
}

One set of AWS keys, with when it expires; zero Expires never does

func (Keys) Valid

func (k Keys) Valid() bool

Whether the keys can sign

type LoginNeeded

type LoginNeeded struct {
	Profile string
	Err     error
}

An SSO token that aws sso login renews: missing, unreadable, expired or refused

func (*LoginNeeded) Error

func (e *LoginNeeded) Error() string

func (*LoginNeeded) Unwrap

func (e *LoginNeeded) Unwrap() error

type Options

type Options struct {
	// Profile of the shared config, AWS_PROFILE and then default when empty; naming one turns the environment's keys off
	Profile string
	// Leaves the instance metadata service out
	NoIMDS bool
	// Asks for an MFA code a role names, nil to refuse one as NoMFA does
	MFA func(ctx context.Context, prompt string) (string, error)
	// Reads a variable of the profile's environment, such as its config.View's LookupEnv, which also names the proxy and authorities of the
	// chain's requests; none for nil
	Lookup func(name string) (string, bool)
	// Every variable a credential_process is given, the profile's on purpose since it signs in for the profile; this machine's alone when
	// nil
	Environ func() map[string]string
	// The caller's own switches of FIPS and dual-stack hosts, which win over AWS's variables and profile keys as a setting of the client
	// does; nil leaves each to them. Switch names where they are set, as a sentence says it after "asked by"
	FIPS, DualStack *bool
	Switch          string
}

What a chain is asked for, as an AWS SDK session takes it

type Partition

type Partition struct {
	Name            string
	DNSSuffix       string
	DualStackSuffix string
	// contains filtered or unexported fields
}

One partition of AWS: the regions it holds and the domains of its ordinary and dual-stack hosts, as AWS's partition data writes them

func PartitionOf

func PartitionOf(region string) Partition

Partition of the region, the aws partition for one that no other partition's regions match

type Profiles

type Profiles struct {
	// contains filtered or unexported fields
}

Inference profiles resolved to the models they wrap, each looked up once

func (*Profiles) Resolve

func (p *Profiles) Resolve(ctx context.Context, client *http.Client, model, region string, control func(region string) (string, error),
	sign func(*http.Request, []byte) error, bearer string) string

Model an application inference profile wraps, looked up with the control plane of its region at the address control gives for it (AWS's ordinary host for nil); the profile itself when the lookup fails, no address of the control plane may be used, or the model isn't one

type Provider

type Provider interface {
	Retrieve(ctx context.Context) (Keys, error)
}

Source of keys, renewing them as they near expiry

type Service

type Service struct {
	// Identifier of its configured endpoints, after AWS_ENDPOINT_URL_ in upper case and as the key under a services section of the AWS
	// config, such as bedrock_runtime; empty for a service whose address nothing configures
	ID string
	// Name a person reads, such as Bedrock Runtime
	Title string
	// First labels of its ordinary hosts and of its FIPS hosts, such as bedrock-runtime and bedrock-runtime-fips
	Prefix, FIPSPrefix string
	// Its ordinary hosts are on the dual-stack domain of their partition, as Bedrock Mantle's are, so asking for dual-stack changes nothing
	Stacked bool
	// Regions AWS publishes a host of each variant in: FIPS, dual-stack, and FIPS that is dual-stack. A region of none has none
	FIPS, DualStack, Both []string
	// Hosts of a variant in a region that differ from the pattern, such as STS's FIPS host in GovCloud, which is its ordinary one
	Hosts map[string]map[Variant]string
}

A service of AWS icebath calls, with the hosts AWS publishes for it

func (Service) Owns

func (s Service) Owns(address string) (string, Variant, bool)

Region and variant of an address that is a host AWS publishes of the service, a host of a region that differs from the pattern read first, so GovCloud's STS host, its ordinary and its FIPS one, reads as FIPS; false for any other address, one a person configured among them

func (Service) Publishes

func (s Service) Publishes(region string, v Variant) bool

Whether AWS publishes a host of the variant of the service in the region

func (Service) Variable

func (s Service) Variable() string

Variable that configures the address of the service, such as AWS_ENDPOINT_URL_BEDROCK_RUNTIME; empty for a service of none

type ServiceError

type ServiceError struct {
	Operation  string
	StatusCode int
	Code       string
	Message    string
}

Error answer of an AWS API

func (*ServiceError) Error

func (e *ServiceError) Error() string

type Variant

type Variant struct {
	FIPS, DualStack bool
}

Kind of host asked of AWS: FIPS, whose TLS library is validated against FIPS 140, and dual-stack, which answers over IPv4 and IPv6; neither is the ordinary host

func (Variant) String

func (v Variant) String() string

The variant as a sentence names it, such as a FIPS host that is dual-stack

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL