aws

package
v0.1.94 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 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 is a thin, SDK-free client for the AWS APIs commons-db uses.

A Session carries the region, an optional endpoint override (emulators, VPC endpoints), a SigV4 credentials provider and the commons HTTP client configuration. Typed service clients hang off it and expose only the operations and fields the callers read.

Index

Constants

View Source
const (
	StatusCodeComplete    = "Complete"
	StatusCodePartialData = "PartialData"
)

Metric data status codes.

View Source
const (
	ServiceS3         = "s3"
	ServiceSQS        = "sqs"
	ServiceCloudWatch = "monitoring"
	ServiceLogs       = "logs"
	ServiceSTS        = "sts"
	ServiceKMS        = "kms"
	ServiceEKS        = "eks"
)

Service names, as used by SessionOptions.ServiceEndpoints.

View Source
const (
	// EKSClusterIDHeader names the cluster a token is minted for.
	EKSClusterIDHeader = "x-k8s-aws-id"
)
View Source
const ScanByTimestampAscending = "TimestampAscending"

ScanByTimestampAscending returns the oldest datapoints first.

Variables

View Source
var StandardUnits = []string{
	"Seconds", "Microseconds", "Milliseconds", "Bytes", "Kilobytes", "Megabytes", "Gigabytes", "Terabytes",
	"Bits", "Kilobits", "Megabits", "Gigabits", "Terabits", "Percent", "Count",
	"Bytes/Second", "Kilobytes/Second", "Megabytes/Second", "Gigabytes/Second", "Terabytes/Second",
	"Bits/Second", "Kilobits/Second", "Megabits/Second", "Gigabits/Second", "Terabits/Second",
	"Count/Second", "None",
}

StandardUnits are the units CloudWatch accepts for a MetricStat.

Functions

func EKSToken

func EKSToken(credentials awssigv4.Credentials, cluster string, now time.Time) (string, error)

EKSToken is the bearer token kubectl-style auth sends: "k8s-aws-v1." followed by the base64url of a presigned STS GetCallerIdentity URL that is bound to the cluster through the x-k8s-aws-id header.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err is an AWS response saying the object, bucket or key does not exist: S3 NoSuchKey/NoSuchBucket/404 and KMS NotFoundException.

func PresignGetCallerIdentity

func PresignGetCallerIdentity(credentials awssigv4.Credentials, cluster string, now time.Time) (string, error)

PresignGetCallerIdentity presigns STS GetCallerIdentity with query-string SigV4. The signed headers are host and x-k8s-aws-id; the payload is empty.

Types

type APIError

type APIError struct {
	Service    string
	Operation  string
	StatusCode int
	Code       string
	Message    string
	RequestID  string
}

APIError is a non-2xx response from an AWS service, parsed from either the JSON (`__type`/`message`) or the XML (`<Error><Code>`) error protocol.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Is

func (e *APIError) Is(target error) bool

Is makes a not-found response match fs.ErrNotExist.

type CallerIdentity

type CallerIdentity struct {
	Account string `xml:"Account"`
	ARN     string `xml:"Arn"`
	UserID  string `xml:"UserId"`
}

CallerIdentity is the principal the credentials resolve to.

type CloudWatch

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

CloudWatch is the CloudWatch metrics client (query protocol).

func (*CloudWatch) GetMetricData

func (c *CloudWatch) GetMetricData(ctx context.Context, in GetMetricDataInput) (*GetMetricDataOutput, error)

GetMetricData reads one page of datapoints.

func (*CloudWatch) ListMetrics

func (c *CloudWatch) ListMetrics(ctx context.Context, in ListMetricsInput) (*ListMetricsOutput, error)

ListMetrics lists one page of metrics.

func (*CloudWatch) PutMetricData

func (c *CloudWatch) PutMetricData(ctx context.Context, namespace string, data []MetricDatum) error

PutMetricData publishes datapoints under a namespace.

type Dimension

type Dimension struct {
	Name  string `xml:"Name"`
	Value string `xml:"Value"`
}

Dimension is one name/value pair identifying a metric series.

type EKS

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

EKS is the Elastic Kubernetes Service client (REST-JSON).

func (*EKS) DescribeCluster

func (c *EKS) DescribeCluster(ctx context.Context, name string) (*EKSCluster, error)

DescribeCluster returns the cluster endpoint and CA.

type EKSCluster

type EKSCluster struct {
	Endpoint string
	// CertificateAuthorityData is the base64-encoded PEM cluster CA, as EKS returns it.
	CertificateAuthorityData string
}

EKSCluster is the part of DescribeCluster the kube client needs.

type GetMetricDataInput

type GetMetricDataInput struct {
	StartTime, EndTime time.Time
	ScanBy             string
	Queries            []MetricDataQuery
	NextToken          string
}

GetMetricDataInput is one GetMetricData page request.

type GetMetricDataOutput

type GetMetricDataOutput struct {
	Results   []MetricDataResult `xml:"MetricDataResults>member"`
	Messages  []MetricMessage    `xml:"Messages>member"`
	NextToken string             `xml:"NextToken"`
}

GetMetricDataOutput is one GetMetricData page.

type KMS

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

KMS is the Key Management Service client (JSON 1.1).

func (*KMS) CreateKey

func (c *KMS) CreateKey(ctx context.Context) (string, error)

CreateKey creates a symmetric encryption key and returns its id.

func (*KMS) Decrypt

func (c *KMS) Decrypt(ctx context.Context, in KMSDecryptInput) ([]byte, error)

Decrypt returns the plaintext for a ciphertext blob.

func (*KMS) Encrypt

func (c *KMS) Encrypt(ctx context.Context, in KMSEncryptInput) ([]byte, error)

Encrypt returns the ciphertext blob for the plaintext.

type KMSDecryptInput

type KMSDecryptInput struct {
	CiphertextBlob []byte `json:"CiphertextBlob"`
}

KMSDecryptInput carries ciphertext produced by Encrypt; KMS finds the key from it.

type KMSEncryptInput

type KMSEncryptInput struct {
	KeyID     string `json:"KeyId"`
	Plaintext []byte `json:"Plaintext"`
}

KMSEncryptInput names the key (id, ARN or alias) and the plaintext to encrypt.

type ListMetricsInput

type ListMetricsInput struct {
	Namespace  string
	MetricName string
	Dimensions []Dimension
	NextToken  string
}

ListMetricsInput filters a ListMetrics page. Dimension filters match on name, and on value when it is set.

type ListMetricsOutput

type ListMetricsOutput struct {
	Metrics   []Metric `xml:"Metrics>member"`
	NextToken string   `xml:"NextToken"`
}

ListMetricsOutput is one ListMetrics page.

type ListObjectsInput

type ListObjectsInput struct {
	Bucket            string
	Prefix            string
	ContinuationToken string
	// MaxKeys caps the page size when positive.
	MaxKeys int
}

ListObjectsInput selects one page of a ListObjectsV2 listing.

type ListObjectsOutput

type ListObjectsOutput struct {
	Objects               []S3Object `xml:"Contents"`
	KeyCount              int        `xml:"KeyCount"`
	NextContinuationToken string     `xml:"NextContinuationToken"`
}

ListObjectsOutput is one page of a ListObjectsV2 listing.

type LogEvent

type LogEvent struct {
	Timestamp int64  `json:"timestamp"`
	Message   string `json:"message"`
}

LogEvent is one event for PutLogEvents; Timestamp is epoch milliseconds.

type Logs

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

Logs is the CloudWatch Logs client (JSON 1.1).

func (*Logs) CreateLogGroup

func (c *Logs) CreateLogGroup(ctx context.Context, group string) error

CreateLogGroup creates a log group.

func (*Logs) CreateLogStream

func (c *Logs) CreateLogStream(ctx context.Context, group, stream string) error

CreateLogStream creates a log stream in a group.

func (*Logs) GetQueryResults

func (c *Logs) GetQueryResults(ctx context.Context, queryID string) (*QueryResults, error)

GetQueryResults returns the current status and results of a query.

func (*Logs) PutLogEvents

func (c *Logs) PutLogEvents(ctx context.Context, group, stream string, events []LogEvent) error

PutLogEvents appends events to a log stream.

func (*Logs) StartQuery

func (c *Logs) StartQuery(ctx context.Context, in StartQueryInput) (string, error)

StartQuery starts a query and returns its id.

type Message

type Message struct {
	MessageID         string                      `json:"MessageId"`
	ReceiptHandle     string                      `json:"ReceiptHandle"`
	Body              string                      `json:"Body"`
	Attributes        map[string]string           `json:"Attributes"`
	MessageAttributes map[string]MessageAttribute `json:"MessageAttributes"`
}

Message is a received SQS message.

type MessageAttribute

type MessageAttribute struct {
	DataType    string `json:"DataType"`
	StringValue string `json:"StringValue"`
}

MessageAttribute is a user-defined message attribute.

type Metric

type Metric struct {
	Namespace  string      `xml:"Namespace"`
	MetricName string      `xml:"MetricName"`
	Dimensions []Dimension `xml:"Dimensions>member"`
}

Metric identifies a metric.

type MetricDataQuery

type MetricDataQuery struct {
	ID         string
	Expression string
	// Period applies to expressions; a MetricStat carries its own.
	Period     int32
	MetricStat *MetricStat
}

MetricDataQuery is one GetMetricData query: a MetricStat or an Expression.

type MetricDataResult

type MetricDataResult struct {
	ID         string          `xml:"Id"`
	Label      string          `xml:"Label"`
	StatusCode string          `xml:"StatusCode"`
	Timestamps []time.Time     `xml:"Timestamps>member"`
	Values     []float64       `xml:"Values>member"`
	Messages   []MetricMessage `xml:"Messages>member"`
}

MetricDataResult is one query's datapoints. StatusCode is Complete, PartialData, InternalError or Forbidden.

type MetricDatum

type MetricDatum struct {
	MetricName string
	Dimensions []Dimension
	Timestamp  time.Time
	Value      float64
	Unit       string
}

MetricDatum is one datapoint for PutMetricData.

type MetricMessage

type MetricMessage struct {
	Code  string `xml:"Code"`
	Value string `xml:"Value"`
}

MetricMessage is a diagnostic CloudWatch attaches to a query or response.

type MetricStat

type MetricStat struct {
	Metric Metric
	Period int32
	Stat   string
	// Unit filters the datapoints when set.
	Unit string
}

MetricStat selects a statistic of a metric over a period in seconds.

type QueryResultField

type QueryResultField struct {
	Field string `json:"field"`
	Value string `json:"value"`
}

QueryResultField is one column of one result row.

type QueryResults

type QueryResults struct {
	Status     QueryStatus          `json:"status"`
	Results    [][]QueryResultField `json:"results"`
	Statistics QueryStatistics      `json:"statistics"`
}

QueryResults is the GetQueryResults response.

type QueryStatistics

type QueryStatistics struct {
	RecordsMatched float64 `json:"recordsMatched"`
	RecordsScanned float64 `json:"recordsScanned"`
	BytesScanned   float64 `json:"bytesScanned"`
}

QueryStatistics are the scan statistics of a query.

type QueryStatus

type QueryStatus string

QueryStatus is the state of a Logs Insights query.

const (
	QueryStatusScheduled QueryStatus = "Scheduled"
	QueryStatusRunning   QueryStatus = "Running"
	QueryStatusComplete  QueryStatus = "Complete"
	QueryStatusFailed    QueryStatus = "Failed"
	QueryStatusCancelled QueryStatus = "Cancelled"
	QueryStatusTimeout   QueryStatus = "Timeout"
)

Logs Insights query states.

type ReceiveMessageInput

type ReceiveMessageInput struct {
	QueueURL            string
	MaxNumberOfMessages int
	// WaitTimeSeconds enables long polling when positive.
	WaitTimeSeconds int
	// VisibilityTimeout overrides the queue's timeout when positive.
	VisibilityTimeout int
}

ReceiveMessageInput polls a queue. All message attributes and system attributes are always requested.

type S3

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

S3 is the Simple Storage Service client (REST-XML).

func (*S3) CreateBucket

func (c *S3) CreateBucket(ctx context.Context, bucket string) error

CreateBucket creates a bucket in the session region.

func (*S3) DeleteObject

func (c *S3) DeleteObject(ctx context.Context, ref S3ObjectRef) error

DeleteObject removes an object. S3 answers 204 for a missing key.

func (*S3) GetObject

func (c *S3) GetObject(ctx context.Context, ref S3ObjectRef) (*S3ObjectBody, error)

GetObject opens an object for streaming. The caller closes Body.

func (*S3) HeadBucket

func (c *S3) HeadBucket(ctx context.Context, bucket string) error

HeadBucket fails unless the bucket exists and is accessible.

func (*S3) HeadObject

func (c *S3) HeadObject(ctx context.Context, ref S3ObjectRef) (*S3ObjectHead, error)

HeadObject returns an object's size, modification time and ETag.

func (*S3) ListBuckets

func (c *S3) ListBuckets(ctx context.Context) ([]S3Bucket, error)

ListBuckets lists the account's buckets.

func (*S3) ListObjectsV2

func (c *S3) ListObjectsV2(ctx context.Context, in ListObjectsInput) (*ListObjectsOutput, error)

ListObjectsV2 returns one page of objects.

func (*S3) PutObject

func (c *S3) PutObject(ctx context.Context, ref S3ObjectRef, body io.Reader) error

PutObject uploads body. The SigV4 signer hashes the payload, so the body is read fully before sending.

type S3Bucket

type S3Bucket struct {
	Name         string    `xml:"Name"`
	CreationDate time.Time `xml:"CreationDate"`
}

S3Bucket is one bucket in a ListBuckets response.

type S3Object

type S3Object struct {
	Key          string    `xml:"Key"`
	Size         int64     `xml:"Size"`
	LastModified time.Time `xml:"LastModified"`
	ETag         string    `xml:"ETag"`
}

S3Object is the listing metadata of one object.

type S3ObjectBody

type S3ObjectBody struct {
	S3ObjectHead
	Body io.ReadCloser
}

S3ObjectBody is a streamed object; the caller closes Body.

type S3ObjectHead

type S3ObjectHead struct {
	Size         int64
	LastModified time.Time
	ETag         string
}

S3ObjectHead is the metadata HeadObject returns.

type S3ObjectRef

type S3ObjectRef struct{ Bucket, Key string }

S3ObjectRef names one object.

type S3Options

type S3Options struct {
	// PathStyle sends http://host/BUCKET/KEY instead of http://BUCKET.host/KEY,
	// where host is the session Endpoint or the regional S3 endpoint. Bucket names
	// containing dots always use path style.
	PathStyle bool
}

S3Options selects how bucket names are addressed.

type SQS

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

SQS is the Simple Queue Service client (JSON 1.0).

func (*SQS) ChangeMessageVisibility

func (c *SQS) ChangeMessageVisibility(ctx context.Context, queueURL, receiptHandle string, visibilityTimeoutSeconds int) error

ChangeMessageVisibility sets how long a received message stays hidden; zero makes it visible again immediately (a nack).

func (*SQS) CreateQueue

func (c *SQS) CreateQueue(ctx context.Context, name string) (string, error)

CreateQueue creates a standard queue (or returns the existing one) and returns its URL.

func (*SQS) DeleteMessage

func (c *SQS) DeleteMessage(ctx context.Context, queueURL, receiptHandle string) error

DeleteMessage acknowledges a message by its receipt handle.

func (*SQS) ReceiveMessage

func (c *SQS) ReceiveMessage(ctx context.Context, in ReceiveMessageInput) ([]Message, error)

ReceiveMessage long-polls the queue.

func (*SQS) SendMessage

func (c *SQS) SendMessage(ctx context.Context, queueURL, body string) (string, error)

SendMessage enqueues a message body and returns its id.

type STS

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

STS is the Security Token Service client (query protocol).

func (*STS) GetCallerIdentity

func (c *STS) GetCallerIdentity(ctx context.Context) (*CallerIdentity, error)

GetCallerIdentity returns the account, ARN and user id of the signing principal.

type Session

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

Session is the shared configuration behind every typed service client.

func NewSession

func NewSession(options SessionOptions) (*Session, error)

NewSession validates options. Region and Credentials are required.

func (*Session) CloudWatch

func (s *Session) CloudWatch() *CloudWatch

CloudWatch returns the CloudWatch metrics client.

func (*Session) Credentials

func (s *Session) Credentials() awssigv4.CredentialsProvider

Credentials is the provider that signs this session's requests.

func (*Session) EKS

func (s *Session) EKS() *EKS

EKS returns the EKS client.

func (*Session) Endpoint

func (s *Session) Endpoint() string

Endpoint is the normalized endpoint override, empty when the AWS endpoints are used.

func (*Session) KMS

func (s *Session) KMS() *KMS

KMS returns the KMS client.

func (*Session) Logs

func (s *Session) Logs() *Logs

Logs returns the CloudWatch Logs client.

func (*Session) Region

func (s *Session) Region() string

Region is the session's signing region.

func (*Session) S3

func (s *Session) S3(options S3Options) *S3

S3 returns the S3 client.

func (*Session) SQS

func (s *Session) SQS() *SQS

SQS returns the SQS client.

func (*Session) STS

func (s *Session) STS() *STS

STS returns the STS client. STS is global in the commons sense: the same region-scoped endpoint serves it.

type SessionOptions

type SessionOptions struct {
	// Region is the signing region and, without an Endpoint, the endpoint region.
	Region string
	// Endpoint overrides the S3, SQS, CloudWatch and CloudWatch Logs endpoints,
	// for emulators and VPC endpoints. It is an http(s) URL with no path. S3
	// addresses buckets as subdomains of it unless S3Options.PathStyle is set.
	Endpoint string
	// ServiceEndpoints overrides individual services by name (the Service*
	// constants), for emulators that also serve STS, KMS or EKS. Entries take
	// precedence over Endpoint.
	ServiceEndpoints map[string]string
	// Credentials signs every request.
	Credentials awssigv4.CredentialsProvider
	// SkipTLSVerify disables certificate verification for HTTPS endpoints.
	SkipTLSVerify bool
	// Customize adjusts each service's HTTP client, e.g. to add request logging.
	Customize func(*commonshttp.Client) *commonshttp.Client
}

SessionOptions configures a Session.

type StartQueryInput

type StartQueryInput struct {
	LogGroupName string `json:"logGroupName"`
	QueryString  string `json:"queryString"`
	StartTime    int64  `json:"startTime"`
	EndTime      int64  `json:"endTime"`
	// Limit caps the returned rows when positive.
	Limit int32 `json:"limit,omitempty"`
}

StartQueryInput starts a Logs Insights query. StartTime and EndTime are epoch seconds, as the API defines them.

Directories

Path Synopsis
Package awstest starts the ministack AWS emulator for integration specs.
Package awstest starts the ministack AWS emulator for integration specs.

Jump to

Keyboard shortcuts

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