Documentation
¶
Overview ¶
Package aws resolves AWS credentials the way the AWS CLI and SDKs do, and signs requests with them by SigV4
Index ¶
- Variables
- func ApplicationProfile(model string) bool
- func Call(ctx context.Context, client *http.Client, operation, method, address string, ...) error
- func ControlURL(region string) string
- func Domain(host string) bool
- func EndpointRegion(address string) string
- func ErrorOf(header http.Header, status int, body []byte) (string, string)
- func Flag(where, value string) (bool, error)
- func Getenv(lookup func(name string) (string, bool)) httpx.Env
- func Identity(ctx context.Context, env httpx.Env, keys Keys, at Endpoint) (string, error)
- func MantleURL(region string) string
- func ModelPath(model, operation string) string
- func NoMFA(context.Context, string) (string, error)
- func Sections(text string) (map[string]map[string]string, error)
- func SharedProfiles(getenv func(string) string) []string
- func Sign(req *http.Request, body []byte, keys Keys, service, region string, ...) error
- func Signer(keys Provider, service, region string) func(request *http.Request, body []byte) error
- func Suffix(region string) string
- func Title(link string) string
- func Viewing(ctx context.Context) context.Context
- type Chain
- func (c *Chain) Choice() (Choice, error)
- func (c *Chain) Endpoint(service Service, region string) (Endpoint, error)
- func (c *Chain) Planned() (string, bool)
- func (c *Chain) Profile() string
- func (c *Chain) Region() string
- func (c *Chain) Retrieve(ctx context.Context) (Keys, error)
- func (c *Chain) SSO() (Endpoint, Endpoint, error)
- func (c *Chain) STS() (Endpoint, error)
- func (c *Chain) Stale() bool
- type Choice
- type Endpoint
- type EndpointError
- type Error
- type Keys
- type LoginNeeded
- type Options
- type Partition
- type Profiles
- type Provider
- type Service
- type ServiceError
- type Variant
Constants ¶
This section is empty.
Variables ¶
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
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
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
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
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
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
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 ¶
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 ¶
Address of the ordinary host of the Bedrock control plane of a region
func Domain ¶
Whether the host is one of AWS's, under the ordinary or the dual-stack domain of one of its partitions
func EndpointRegion ¶
Region a Bedrock address names, empty for any other
func ErrorOf ¶
Code and message of an AWS JSON error answer: the code from x-amzn-ErrorType, else __type, else code, without its namespace
func Flag ¶
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 ¶
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 ¶
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 ModelPath ¶
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 ¶
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 ¶
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 ¶
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 ¶
Signs the request in place: its date, the session token and the Authorization header over the exact body given
func Signer ¶
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 Title ¶
What a link of the chain signs in through, as a sentence names it after "through" or "the sign-in of"
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 (*Chain) Choice ¶
What the chain asks of AWS's hosts, FIPS and dual-stack, and where each ask was read
func (*Chain) Endpoint ¶
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 ¶
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) SSO ¶
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
type Choice ¶
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
type EndpointError ¶
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 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
type LoginNeeded ¶
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 ¶
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 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 ¶
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
type ServiceError ¶
Error answer of an AWS API
func (*ServiceError) Error ¶
func (e *ServiceError) Error() string