goamz: github.com/crowdmob/goamz/aws Index | Examples | Files

package aws

import "github.com/crowdmob/goamz/aws"

goamz - Go packages to interact with the Amazon Web Services.


Copyright (c) 2011 Canonical Ltd.

Written by Gustavo Niemeyer <gustavo.niemeyer@canonical.com>



Package Files

attempt.go aws.go client.go regions.go retry.go sign.go


const (
    V2Signature      = iota
    V4Signature      = iota
    Route53Signature = iota

Defines the valid signers

const (
    ISO8601BasicFormat      = "20060102T150405Z"
    ISO8601BasicFormatShort = "20060102"

Common date formats for signing requests


var APNortheast = Region{
    ServiceInfo{"https://monitoring.ap-northeast-1.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.ap-northeast-1.amazonaws.com", V2Signature},
var APSoutheast = Region{
    ServiceInfo{"https://monitoring.ap-southeast-1.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.ap-southeast-1.amazonaws.com", V2Signature},
var APSoutheast2 = Region{
    ServiceInfo{"https://monitoring.ap-southeast-2.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.ap-southeast-2.amazonaws.com", V2Signature},
var EUCentral = Region{
    ServiceInfo{"https://monitoring.eu-central-1.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.eu-central-1.amazonaws.com", V2Signature},
var EUWest = Region{
    ServiceInfo{"https://monitoring.eu-west-1.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.eu-west-1.amazonaws.com", V2Signature},
var Regions = map[string]Region{
    APNortheast.Name:  APNortheast,
    APSoutheast.Name:  APSoutheast,
    APSoutheast2.Name: APSoutheast2,
    EUCentral.Name:    EUCentral,
    EUWest.Name:       EUWest,
    USEast.Name:       USEast,
    USWest.Name:       USWest,
    USWest2.Name:      USWest2,
    USGovWest.Name:    USGovWest,
    SAEast.Name:       SAEast,
var RetryingClient = NewClient(retryingTransport)

Exported default client

var SAEast = Region{
    ServiceInfo{"https://monitoring.sa-east-1.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.sa-east-1.amazonaws.com", V2Signature},
var USEast = Region{
    ServiceInfo{"https://monitoring.us-east-1.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.us-east-1.amazonaws.com", V2Signature},
var USGovWest = Region{
    ServiceInfo{"https://monitoring.us-gov-west-1.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.us-gov-west-1.amazonaws.com", V2Signature},
var USWest = Region{
    ServiceInfo{"https://monitoring.us-west-1.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.us-west-1.amazonaws.com", V2Signature},
var USWest2 = Region{
    ServiceInfo{"https://monitoring.us-west-2.amazonaws.com", V2Signature},
    ServiceInfo{"https://rds.us-west-2.amazonaws.com", V2Signature},

func AvailabilityZone Uses

func AvailabilityZone() string

func Encode Uses

func Encode(s string) string

Encode takes a string and URI-encodes it in a way suitable to be used in AWS signatures.

func ExpBackoff Uses

func ExpBackoff(try int)

func GetInstanceCredentials Uses

func GetInstanceCredentials() (cred credentials, err error)

GetInstanceCredentials creates an Auth based on the instance's role credentials. If the running instance is not in EC2 or does not have a valid IAM role, an error will be returned. For more info about setting up IAM roles, see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

func GetMetaData Uses

func GetMetaData(path string) (contents []byte, err error)

GetMetaData retrieves instance metadata about the current machine.

See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html for more details.

func InstanceId Uses

func InstanceId() string

func InstanceRegion Uses

func InstanceRegion() string

func InstanceType Uses

func InstanceType() string

func LinearBackoff Uses

func LinearBackoff(try int)

func MakeParams Uses

func MakeParams(action string) map[string]string

Create a base set of params for an action

func NewClient Uses

func NewClient(rt *ResilientTransport) *http.Client

Convenience method for creating an http client

func ServerLocalIp Uses

func ServerLocalIp() string

func ServerPublicIp Uses

func ServerPublicIp() string

type AWSService Uses

type AWSService interface {
    // Queries the AWS service at a given method/path with the params and
    // returns an http.Response and error
    Query(method, path string, params map[string]string) (*http.Response, error)
    // Builds an error given an XML payload in the http.Response, can be used
    // to process an error if the status code is not 200 for example.
    BuildError(r *http.Response) error

An AWS Service interface with the API to query the AWS service

Supplied as an easy way to mock out service calls during testing.

type Attempt Uses

type Attempt struct {
    // contains filtered or unexported fields

func (*Attempt) HasNext Uses

func (a *Attempt) HasNext() bool

HasNext returns whether another attempt will be made if the current one fails. If it returns true, the following call to Next is guaranteed to return true.

func (*Attempt) Next Uses

func (a *Attempt) Next() bool

Next waits until it is time to perform the next attempt or returns false if it is time to stop trying.

type AttemptStrategy Uses

type AttemptStrategy struct {
    Total time.Duration // total duration of attempt.
    Delay time.Duration // interval between each try in the burst.
    Min   int           // minimum number of retries; overrides Total

AttemptStrategy represents a strategy for waiting for an action to complete successfully. This is an internal type used by the implementation of other goamz packages.

func (AttemptStrategy) Start Uses

func (s AttemptStrategy) Start() *Attempt

Start begins a new sequence of attempts for the given strategy.

type Auth Uses

type Auth struct {
    AccessKey, SecretKey string
    // contains filtered or unexported fields

func CredentialFileAuth Uses

func CredentialFileAuth(filePath string, profile string, expiration time.Duration) (auth Auth, err error)

CredentialFileAuth creates and Auth based on a credentials file. The file contains various authentication profiles for use with AWS.

The credentials file, which is used by other AWS SDKs, is documented at http://blogs.aws.amazon.com/security/post/Tx3D6U6WSFGOK2H/A-New-and-Standardized-Way-to-Manage-Credentials-in-the-AWS-SDKs

func EnvAuth Uses

func EnvAuth() (auth Auth, err error)

EnvAuth creates an Auth based on environment information. The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are used.

func GetAuth Uses

func GetAuth(accessKey string, secretKey, token string, expiration time.Time) (auth Auth, err error)

GetAuth creates an Auth based on either passed in credentials, environment information or instance based role credentials.

func NewAuth Uses

func NewAuth(accessKey, secretKey, token string, expiration time.Time) *Auth

To be used with other APIs that return auth credentials such as STS

func (*Auth) Expiration Uses

func (a *Auth) Expiration() time.Time

func (*Auth) Token Uses

func (a *Auth) Token() string

type BaseResponse Uses

type BaseResponse struct {
    ResponseMetadata ResponseMetadata

type DeadlineFunc Uses

type DeadlineFunc func() time.Time

type DefaultRetryPolicy Uses

type DefaultRetryPolicy struct {

DefaultRetryPolicy implements the AWS SDK default retry policy.

It will retry up to 3 times, and uses an exponential backoff with a scale factor of 300ms (300ms, 600ms, 1200ms). If the retry is because of throttling, the delay will also include some randomness.

See https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-core/src/main/java/com/amazonaws/retry/PredefinedRetryPolicies.java#L90.

func (DefaultRetryPolicy) Delay Uses

func (policy DefaultRetryPolicy) Delay(target string, r *http.Response, err error, numRetries int) time.Duration

Delay implements the RetryPolicy Delay method.

func (DefaultRetryPolicy) ShouldRetry Uses

func (policy DefaultRetryPolicy) ShouldRetry(target string, r *http.Response, err error, numRetries int) bool

ShouldRetry implements the RetryPolicy ShouldRetry method.

type DynamoDBRetryPolicy Uses

type DynamoDBRetryPolicy struct {

DynamoDBRetryPolicy implements the AWS SDK DynamoDB retry policy.

It will retry up to 10 times, and uses an exponential backoff with a scale factor of 25ms (25ms, 50ms, 100ms, ...).

See https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-core/src/main/java/com/amazonaws/retry/PredefinedRetryPolicies.java#L103.

func (DynamoDBRetryPolicy) Delay Uses

func (policy DynamoDBRetryPolicy) Delay(target string, r *http.Response, err error, numRetries int) time.Duration

Delay implements the RetryPolicy Delay method.

func (DynamoDBRetryPolicy) ShouldRetry Uses

func (policy DynamoDBRetryPolicy) ShouldRetry(target string, r *http.Response, err error, numRetries int) bool

ShouldRetry implements the RetryPolicy ShouldRetry method.

type Error Uses

type Error struct {
    StatusCode int
    Type       string
    Code       string
    Message    string
    RequestId  string

func (*Error) Error Uses

func (err *Error) Error() string

func (*Error) ErrorCode Uses

func (err *Error) ErrorCode() string

type ErrorResponse Uses

type ErrorResponse struct {
    Errors    Error  `xml:"Error"`
    RequestId string // A unique ID for tracking the request

type NeverRetryPolicy Uses

type NeverRetryPolicy struct {

NeverRetryPolicy never retries requests and returns immediately on failure.

func (NeverRetryPolicy) Delay Uses

func (policy NeverRetryPolicy) Delay(target string, r *http.Response, err error, numRetries int) time.Duration

Delay implements the RetryPolicy Delay method.

func (NeverRetryPolicy) ShouldRetry Uses

func (policy NeverRetryPolicy) ShouldRetry(target string, r *http.Response, err error, numRetries int) bool

ShouldRetry implements the RetryPolicy ShouldRetry method.

type Region Uses

type Region struct {
    Name                   string // the canonical name of this region.
    EC2Endpoint            string
    S3Endpoint             string
    S3BucketEndpoint       string // Not needed by AWS S3. Use ${bucket} for bucket name.
    S3LocationConstraint   bool   // true if this region requires a LocationConstraint declaration.
    S3LowercaseBucket      bool   // true if the region requires bucket names to be lower case.
    SDBEndpoint            string
    SNSEndpoint            string
    SQSEndpoint            string
    SESEndpoint            string
    IAMEndpoint            string
    ELBEndpoint            string
    DynamoDBEndpoint       string
    CloudWatchServicepoint ServiceInfo
    AutoScalingEndpoint    string
    RDSEndpoint            ServiceInfo
    KinesisEndpoint        string
    STSEndpoint            string
    CloudFormationEndpoint string
    ElastiCacheEndpoint    string

Region defines the URLs where AWS services may be accessed.

See http://goo.gl/d8BP1 for more details.

func GetRegion Uses

func GetRegion(regionName string) (region Region)

type ResilientTransport Uses

type ResilientTransport struct {
    // Timeout is the maximum amount of time a dial will wait for
    // a connect to complete.
    // The default is no timeout.
    // With or without a timeout, the operating system may impose
    // its own earlier timeout. For instance, TCP timeouts are
    // often around 3 minutes.
    DialTimeout time.Duration

    // MaxTries, if non-zero, specifies the number of times we will retry on
    // failure. Retries are only attempted for temporary network errors or known
    // safe failures.
    MaxTries    int
    Deadline    DeadlineFunc
    ShouldRetry RetryableFunc
    Wait        WaitFunc
    // contains filtered or unexported fields

func (*ResilientTransport) RoundTrip Uses

func (t *ResilientTransport) RoundTrip(req *http.Request) (*http.Response, error)

type ResponseMetadata Uses

type ResponseMetadata struct {
    RequestId string // A unique ID for tracking the request


type RetryPolicy Uses

type RetryPolicy interface {
    // ShouldRetry returns whether a client should retry a failed request.
    ShouldRetry(target string, r *http.Response, err error, numRetries int) bool

    // Delay returns the time a client should wait before issuing a retry.
    Delay(target string, r *http.Response, err error, numRetries int) time.Duration

A RetryPolicy encapsulates a strategy for implementing client retries.

Default implementations are provided which match the AWS SDKs.

type RetryableFunc Uses

type RetryableFunc func(*http.Request, *http.Response, error) bool

type Route53Signer Uses

type Route53Signer struct {
    // contains filtered or unexported fields

func NewRoute53Signer Uses

func NewRoute53Signer(auth Auth) *Route53Signer

func (*Route53Signer) Sign Uses

func (s *Route53Signer) Sign(req *http.Request)

Adds all the required headers for AWS Route53 API to the request including the authorization

type Service Uses

type Service struct {
    // contains filtered or unexported fields

Implements a Server Query/Post API to easily query AWS services and build errors when desired

func NewService Uses

func NewService(auth Auth, service ServiceInfo) (s *Service, err error)

Create a new AWS server to handle making requests

func (*Service) BuildError Uses

func (s *Service) BuildError(r *http.Response) error

func (*Service) Query Uses

func (s *Service) Query(method, path string, params map[string]string) (resp *http.Response, err error)

type ServiceError Uses

type ServiceError interface {
    ErrorCode() string

type ServiceInfo Uses

type ServiceInfo struct {
    Endpoint string
    Signer   uint

Defines the service endpoint and correct Signer implementation to use to sign requests for this endpoint

type Signer Uses

type Signer interface {
    Sign(method, path string, params map[string]string)

Designates a signer interface suitable for signing AWS requests, params should be appropriately encoded for the request before signing.

A signer should be initialized with Auth and the appropriate endpoint.

type V2Signer Uses

type V2Signer struct {
    // contains filtered or unexported fields

func NewV2Signer Uses

func NewV2Signer(auth Auth, service ServiceInfo) (*V2Signer, error)

func (*V2Signer) Sign Uses

func (s *V2Signer) Sign(method, path string, params map[string]string)

type V4Signer Uses

type V4Signer struct {

    // Add the x-amz-content-sha256 header
    IncludeXAmzContentSha256 bool
    // contains filtered or unexported fields

The V4Signer encapsulates all of the functionality to sign a request with the AWS Signature Version 4 Signing Process. (http://goo.gl/u1OWZz)


// Get auth from env vars
auth, err := aws.EnvAuth()
if err != nil {

// Create a signer with the auth, name of the service, and aws region
signer := aws.NewV4Signer(auth, "dynamodb", aws.USEast)

// Create a request
req, err := http.NewRequest("POST", aws.USEast.DynamoDBEndpoint, strings.NewReader("sample_request"))
if err != nil {

// Date or x-amz-date header is required to sign a request
req.Header.Add("Date", time.Now().UTC().Format(http.TimeFormat))

// Sign the request

// Issue signed request

func NewV4Signer Uses

func NewV4Signer(auth Auth, serviceName string, region Region) *V4Signer

Return a new instance of a V4Signer capable of signing AWS requests.

func (*V4Signer) Sign Uses

func (s *V4Signer) Sign(req *http.Request)

Sign a request according to the AWS Signature Version 4 Signing Process. (http://goo.gl/u1OWZz)

The signed request will include an "x-amz-date" header with a current timestamp if a valid "x-amz-date" or "date" header was not available in the original request. In addition, AWS Signature Version 4 requires the "host" header to be a signed header, therefor the Sign method will manually set a "host" header from the request.Host.

The signed request will include a new "Authorization" header indicating that the request has been signed.

Any changes to the request after signing the request will invalidate the signature.

type WaitFunc Uses

type WaitFunc func(try int)

Package aws imports 21 packages (graph) and is imported by 976 packages. Updated 2016-07-14. Refresh now. Tools for package owners.