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
- Variables
- func EKSToken(credentials awssigv4.Credentials, cluster string, now time.Time) (string, error)
- func IsNotFound(err error) bool
- func PresignGetCallerIdentity(credentials awssigv4.Credentials, cluster string, now time.Time) (string, error)
- type APIError
- type CallerIdentity
- type CloudWatch
- func (c *CloudWatch) GetMetricData(ctx context.Context, in GetMetricDataInput) (*GetMetricDataOutput, error)
- func (c *CloudWatch) ListMetrics(ctx context.Context, in ListMetricsInput) (*ListMetricsOutput, error)
- func (c *CloudWatch) PutMetricData(ctx context.Context, namespace string, data []MetricDatum) error
- type Dimension
- type EKS
- type EKSCluster
- type GetMetricDataInput
- type GetMetricDataOutput
- type KMS
- type KMSDecryptInput
- type KMSEncryptInput
- type ListMetricsInput
- type ListMetricsOutput
- type ListObjectsInput
- type ListObjectsOutput
- type LogEvent
- type Logs
- func (c *Logs) CreateLogGroup(ctx context.Context, group string) error
- func (c *Logs) CreateLogStream(ctx context.Context, group, stream string) error
- func (c *Logs) GetQueryResults(ctx context.Context, queryID string) (*QueryResults, error)
- func (c *Logs) PutLogEvents(ctx context.Context, group, stream string, events []LogEvent) error
- func (c *Logs) StartQuery(ctx context.Context, in StartQueryInput) (string, error)
- type Message
- type MessageAttribute
- type Metric
- type MetricDataQuery
- type MetricDataResult
- type MetricDatum
- type MetricMessage
- type MetricStat
- type QueryResultField
- type QueryResults
- type QueryStatistics
- type QueryStatus
- type ReceiveMessageInput
- type S3
- func (c *S3) CreateBucket(ctx context.Context, bucket string) error
- func (c *S3) DeleteObject(ctx context.Context, ref S3ObjectRef) error
- func (c *S3) GetObject(ctx context.Context, ref S3ObjectRef) (*S3ObjectBody, error)
- func (c *S3) HeadBucket(ctx context.Context, bucket string) error
- func (c *S3) HeadObject(ctx context.Context, ref S3ObjectRef) (*S3ObjectHead, error)
- func (c *S3) ListBuckets(ctx context.Context) ([]S3Bucket, error)
- func (c *S3) ListObjectsV2(ctx context.Context, in ListObjectsInput) (*ListObjectsOutput, error)
- func (c *S3) PutObject(ctx context.Context, ref S3ObjectRef, body io.Reader) error
- type S3Bucket
- type S3Object
- type S3ObjectBody
- type S3ObjectHead
- type S3ObjectRef
- type S3Options
- type SQS
- func (c *SQS) ChangeMessageVisibility(ctx context.Context, queueURL, receiptHandle string, ...) error
- func (c *SQS) CreateQueue(ctx context.Context, name string) (string, error)
- func (c *SQS) DeleteMessage(ctx context.Context, queueURL, receiptHandle string) error
- func (c *SQS) ReceiveMessage(ctx context.Context, in ReceiveMessageInput) ([]Message, error)
- func (c *SQS) SendMessage(ctx context.Context, queueURL, body string) (string, error)
- type STS
- type Session
- func (s *Session) CloudWatch() *CloudWatch
- func (s *Session) Credentials() awssigv4.CredentialsProvider
- func (s *Session) EKS() *EKS
- func (s *Session) Endpoint() string
- func (s *Session) KMS() *KMS
- func (s *Session) Logs() *Logs
- func (s *Session) Region() string
- func (s *Session) S3(options S3Options) *S3
- func (s *Session) SQS() *SQS
- func (s *Session) STS() *STS
- type SessionOptions
- type StartQueryInput
Constants ¶
const ( StatusCodeComplete = "Complete" StatusCodePartialData = "PartialData" )
Metric data status codes.
const ( ServiceS3 = "s3" ServiceSQS = "sqs" ServiceCloudWatch = "monitoring" ServiceLogs = "logs" ServiceSTS = "sts" ServiceKMS = "kms" ServiceEKS = "eks" )
Service names, as used by SessionOptions.ServiceEndpoints.
const (
// EKSClusterIDHeader names the cluster a token is minted for.
EKSClusterIDHeader = "x-k8s-aws-id"
)
const ScanByTimestampAscending = "TimestampAscending"
ScanByTimestampAscending returns the oldest datapoints first.
Variables ¶
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 ¶
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 ¶
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.
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 EKS ¶
type EKS struct {
// contains filtered or unexported fields
}
EKS is the Elastic Kubernetes Service client (REST-JSON).
func (*EKS) DescribeCluster ¶
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).
type KMSDecryptInput ¶
type KMSDecryptInput struct {
CiphertextBlob []byte `json:"CiphertextBlob"`
}
KMSDecryptInput carries ciphertext produced by Encrypt; KMS finds the key from it.
type KMSEncryptInput ¶
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 Logs ¶
type Logs struct {
// contains filtered or unexported fields
}
Logs is the CloudWatch Logs client (JSON 1.1).
func (*Logs) CreateLogGroup ¶
CreateLogGroup creates a log group.
func (*Logs) CreateLogStream ¶
CreateLogStream creates a log stream in a group.
func (*Logs) GetQueryResults ¶
GetQueryResults returns the current status and results of a query.
func (*Logs) PutLogEvents ¶
PutLogEvents appends events to a log stream.
func (*Logs) StartQuery ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
S3ObjectHead is the metadata HeadObject returns.
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 ¶
CreateQueue creates a standard queue (or returns the existing one) and returns its URL.
func (*SQS) DeleteMessage ¶
DeleteMessage acknowledges a message by its receipt handle.
func (*SQS) ReceiveMessage ¶
ReceiveMessage long-polls the queue.
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.
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.