awsx

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package awsx is a small SigV4 client for AWS JSON 1.1 and Query APIs. It adds no SDK service modules and does nothing until a call is made.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CodeOf

func CodeOf(err error) string

CodeOf returns the AWS error code of err, or empty.

Types

type Class

type Class string

Class groups AWS error codes into the few outcomes callers act on.

const (
	ClassThrottle Class = "throttle"
	ClassAuth     Class = "auth"
	ClassNotFound Class = "not_found"
	ClassConflict Class = "conflict"
	ClassInvalid  Class = "invalid"
	ClassServer   Class = "server"
	ClassOther    Class = "other"
)

Error classes.

func ClassOf

func ClassOf(err error) Class

ClassOf returns the class of err, or ClassOther.

type Client

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

Client sends signed requests.

func New

func New(o Options) (*Client, error)

New builds a client. HTTP, Now and Sleep default to real ones.

func (*Client) JSON

func (c *Client) JSON(ctx context.Context, svc Service, region, op string, in, out any) error

JSON sends one JSON 1.1 call and decodes the response into out (may be nil).

func (*Client) Query

func (c *Client) Query(ctx context.Context, svc Service, region, action, version string, params url.Values, out any) error

Query sends one Query API call (EC2 style) and decodes the XML response.

func (*Client) REST

func (c *Client) REST(ctx context.Context, svc Service, host, region, method, path string, body []byte, out any) error

REST sends one REST/XML call. A non empty host overrides the regional endpoint for global services; signing still uses region. A nil body sends no payload.

func (*Client) RESTGet

func (c *Client) RESTGet(ctx context.Context, svc Service, host, region, path string, out any) error

RESTGet is REST with GET and no body.

type Credentials

type Credentials struct {
	AccessKeyID, SecretAccessKey, SessionToken string
}

Credentials uses the same keys as the stored AWS cloud account.

func FromMap

func FromMap(m map[string]string) (Credentials, error)

FromMap reads access_key_id, secret_access_key and session_token.

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer is the HTTP seam; *http.Client satisfies it.

type EpochTime

type EpochTime struct{ time.Time }

EpochTime decodes the JSON 1.1 timestamp, seconds since epoch as a number.

func (*EpochTime) UnmarshalJSON

func (t *EpochTime) UnmarshalJSON(b []byte) error

UnmarshalJSON accepts a number or null.

type Error

type Error struct {
	Service string
	Op      string
	Code    string
	Message string
	Status  int
	Class   Class
}

Error is one AWS service error. Error() omits Message on purpose, because some services echo request values back.

func (*Error) Error

func (e *Error) Error() string

type Options

type Options struct {
	Credentials Credentials
	HTTP        Doer
	Now         func() time.Time
	Sleep       func(ctx context.Context, d time.Duration) error
	// BaseURL replaces the regional endpoint, for fake servers.
	BaseURL          string
	MaxAttempts      int
	BaseDelay        time.Duration
	MaxResponseBytes int64
}

Options configures a Client. Zero fields take the DefaultOptions values.

func DefaultOptions

func DefaultOptions(c Credentials) Options

DefaultOptions seeds limits from APP_AWSX_MAX_ATTEMPTS, APP_AWSX_BASE_DELAY_MS and APP_AWSX_MAX_RESPONSE_BYTES.

type Secret

type Secret string

Secret holds a value that must never reach logs, errors or JSON output.

func (Secret) GoString

func (Secret) GoString() string

GoString keeps %#v from printing the value.

func (Secret) MarshalJSON

func (Secret) MarshalJSON() ([]byte, error)

MarshalJSON writes a placeholder, never the value.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the raw value for the one place that needs it.

func (Secret) String

func (Secret) String() string

String implements fmt.Stringer.

func (*Secret) UnmarshalJSON

func (s *Secret) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a plain JSON string into the secret.

type Service

type Service struct {
	Name         string
	Prefix       string
	SigningName  string
	TargetPrefix string
}

Service names one AWS API. TargetPrefix is empty for Query services.

func (Service) Endpoint

func (s Service) Endpoint(region string) string

Endpoint resolves the regional endpoint host for a service.

type Tag

type Tag struct {
	Key   string `json:"Key"`
	Value string `json:"Value"`
}

Tag is one AWS key and value pair.

func TagList

func TagList(m map[string]string) []Tag

TagList converts a map to a stable list.

Directories

Path Synopsis
Package acm requests and reads ACM certificates with DNS validation.
Package acm requests and reads ACM certificates with DNS validation.
Package awsxtest gives service tests a fake AWS endpoint.
Package awsxtest gives service tests a fake AWS endpoint.
Package cloudfront reads distributions and creates cache invalidations over signed REST/XML.
Package cloudfront reads distributions and creates cache invalidations over signed REST/XML.
Package cloudtrail reads the CloudTrail event history for an audit feed.
Package cloudtrail reads the CloudTrail event history for an audit feed.
Package cloudwatch reads CloudWatch metrics (Query API 2010-08-01) and CloudWatch Logs (JSON 1.1).
Package cloudwatch reads CloudWatch metrics (Query API 2010-08-01) and CloudWatch Logs (JSON 1.1).
Package ec2snap manages EBS snapshots over the signed EC2 Query API (version 2016-11-15).
Package ec2snap manages EBS snapshots over the signed EC2 Query API (version 2016-11-15).
Package ecr talks to Elastic Container Registry over signed JSON 1.1.
Package ecr talks to Elastic Container Registry over signed JSON 1.1.
Package elasticache talks to ElastiCache (Redis and Valkey) over the signed Query API (version 2015-02-02).
Package elasticache talks to ElastiCache (Redis and Valkey) over the signed Query API (version 2015-02-02).
Package iam reads IAM role policy attachments over the signed IAM Query API (version 2010-05-08).
Package iam reads IAM role policy attachments over the signed IAM Query API (version 2010-05-08).
Package lightsail talks to Amazon Lightsail over the signed JSON 1.1 API (target prefix Lightsail_20161128).
Package lightsail talks to Amazon Lightsail over the signed JSON 1.1 API (target prefix Lightsail_20161128).
Package rds talks to RDS and Aurora over the signed Query API (version 2014-10-31).
Package rds talks to RDS and Aurora over the signed Query API (version 2014-10-31).
Package secrets reads and writes SSM Parameter Store and Secrets Manager.
Package secrets reads and writes SSM Parameter Store and Secrets Manager.
Package ssm reads managed instance status and runs allowlisted commands over signed JSON 1.1.
Package ssm reads managed instance status and runs allowlisted commands over signed JSON 1.1.

Jump to

Keyboard shortcuts

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