awsx

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

awsx

Tiny shared plumbing for the AWS SDK for Go v2: one place to resolve credentials and build the per-service clients an app actually uses, so callers don't each reinvent it.

  • Explicit or ambient credentials. Pass a static access/secret key (a scoped, non-interactive identity injected as config), or supply nothing and fall back to the AWS default chain (SSO in dev, instance role in production). An unset pair is a no-op.
  • Service client builders with sensible defaults — e.g. the Price List client pins the global us-east-1 endpoint and uses adaptive retry (that API throttles a broad sweep).

Install

go get github.com/getotium/awsx

Usage

// Resolve a config (static creds if given, else the default chain).
cfg, err := awsx.LoadConfig(ctx, "us-east-1", awsx.WithStaticCredentials(accessKey, secretKey))

ec2Client     := awsx.EC2(cfg, "eu-west-1") // per-region EC2 client
pricingClient := awsx.Pricing(cfg)          // Price List client (global, adaptive retry)

Provenance

Extracted from Otium, where it backs the AWS pricing and capacity sources. Deliberately minimal — credential resolution + client construction, nothing more.

License

Apache-2.0.

Documentation

Overview

Package awsx holds the tiny shared AWS plumbing for Otium's provider sources: how to resolve credentials and build per-region EC2 clients. It exists so pkg/pricing/aws and pkg/inventory/aws don't each reinvent client construction.

Credentials are supplied explicitly via WithStaticCredentials — the per-identity OTIUM_AWS_*_ACCESS_KEY / _SECRET_KEY a caller reads from config (a read-only pricing user for otium-ops, a write provisioning user for otium-scheduler). When none are given it falls back to the AWS default credential chain (SSO profile in local dev, instance role in production), so an unset pair is a no-op. See docs/pricing-indexer.md.

Index

Constants

View Source
const PricingRegion = "us-east-1"

PricingRegion is the region the AWS Price List Query API is pinned to. The service is global but reachable only from a few regions; us-east-1 is the canonical one. On-demand prices are region-level data carried in the response regardless of this client region.

Variables

This section is empty.

Functions

func EC2

func EC2(cfg aws.Config, region string) *ec2.Client

EC2 builds an EC2 client from cfg pinned to region (overriding cfg's default region). Spot prices are region-scoped, so the per-region sources build one client each.

func LoadConfig

func LoadConfig(ctx context.Context, region string, opts ...Option) (aws.Config, error)

LoadConfig resolves AWS configuration. region sets the default region for clients derived from the returned config; pass "" to defer to the environment/profile default. Credentials come from WithStaticCredentials when supplied, otherwise the AWS default credential chain.

func Pricing

func Pricing(cfg aws.Config) *pricing.Client

Pricing builds an AWS Price List Query API client from cfg, pinned to PricingRegion. The on-demand price source asks one global endpoint for every region's prices, so the client region is fixed regardless of which worker regions are enabled.

Types

type Option

type Option func(*loadOptions)

Option configures LoadConfig.

func WithStaticCredentials

func WithStaticCredentials(accessKey, secretKey string) Option

WithStaticCredentials supplies an explicit AWS access key + secret. When BOTH are non-empty LoadConfig uses them (a static credentials provider) instead of the default credential chain; when either is empty the option is a no-op and the chain resolves credentials. IAM-user keys carry no session token, so none is passed.

Jump to

Keyboard shortcuts

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