Coder Social home page Coder Social logo

aws-sdk-go's Introduction

AWS SDK for Go

API Reference Join the chat at https://gitter.im/aws/aws-sdk-go Build status Apache V2 License

aws-sdk-go is the v1 AWS SDK for the Go programming language.

We announced the upcoming end-of-support for AWS SDK for Go (v1). We recommend that you migrate to AWS SDK for Go v2. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

Jump To:

Getting Started

Installing

Use go get to retrieve the SDK to add it to your project's Go module dependencies.

go get github.com/aws/aws-sdk-go

To update the SDK use go get -u to retrieve the latest version of the SDK.

go get -u github.com/aws/aws-sdk-go

Quick Examples

Complete SDK Example

This example shows a complete working Go file which will upload a file to S3 and use the Context pattern to implement timeout logic that will cancel the request if it takes too long. This example highlights how to use sessions, create a service client, make a request, handle the error, and process the response.

  package main

  import (
  	"context"
  	"flag"
  	"fmt"
  	"os"
  	"time"

  	"github.com/aws/aws-sdk-go/aws"
  	"github.com/aws/aws-sdk-go/aws/awserr"
  	"github.com/aws/aws-sdk-go/aws/request"
  	"github.com/aws/aws-sdk-go/aws/session"
  	"github.com/aws/aws-sdk-go/service/s3"
  )

  // Uploads a file to S3 given a bucket and object key. Also takes a duration
  // value to terminate the update if it doesn't complete within that time.
  //
  // The AWS Region needs to be provided in the AWS shared config or on the
  // environment variable as `AWS_REGION`. Credentials also must be provided
  // Will default to shared config file, but can load from environment if provided.
  //
  // Usage:
  //   # Upload myfile.txt to myBucket/myKey. Must complete within 10 minutes or will fail
  //   go run withContext.go -b mybucket -k myKey -d 10m < myfile.txt
  func main() {
  	var bucket, key string
  	var timeout time.Duration

  	flag.StringVar(&bucket, "b", "", "Bucket name.")
  	flag.StringVar(&key, "k", "", "Object key name.")
  	flag.DurationVar(&timeout, "d", 0, "Upload timeout.")
  	flag.Parse()

  	// All clients require a Session. The Session provides the client with
 	// shared configuration such as region, endpoint, and credentials. A
 	// Session should be shared where possible to take advantage of
 	// configuration and credential caching. See the session package for
 	// more information.
  	sess := session.Must(session.NewSession())

 	// Create a new instance of the service's client with a Session.
 	// Optional aws.Config values can also be provided as variadic arguments
 	// to the New function. This option allows you to provide service
 	// specific configuration.
  	svc := s3.New(sess)

  	// Create a context with a timeout that will abort the upload if it takes
  	// more than the passed in timeout.
  	ctx := context.Background()
  	var cancelFn func()
  	if timeout > 0 {
  		ctx, cancelFn = context.WithTimeout(ctx, timeout)
  	}
  	// Ensure the context is canceled to prevent leaking.
  	// See context package for more information, https://golang.org/pkg/context/
	if cancelFn != nil {
  		defer cancelFn()
	}

  	// Uploads the object to S3. The Context will interrupt the request if the
  	// timeout expires.
  	_, err := svc.PutObjectWithContext(ctx, &s3.PutObjectInput{
  		Bucket: aws.String(bucket),
  		Key:    aws.String(key),
  		Body:   os.Stdin,
  	})
  	if err != nil {
  		if aerr, ok := err.(awserr.Error); ok && aerr.Code() == request.CanceledErrorCode {
  			// If the SDK can determine the request or retry delay was canceled
  			// by a context the CanceledErrorCode error code will be returned.
  			fmt.Fprintf(os.Stderr, "upload canceled due to timeout, %v\n", err)
  		} else {
  			fmt.Fprintf(os.Stderr, "failed to upload object, %v\n", err)
  		}
  		os.Exit(1)
  	}

  	fmt.Printf("successfully uploaded file to %s/%s\n", bucket, key)
  }

Overview of SDK's Packages

The SDK is composed of two main components, SDK core, and service clients. The SDK core packages are all available under the aws package at the root of the SDK. Each client for a supported AWS service is available within its own package under the service folder at the root of the SDK.

  • aws - SDK core, provides common shared types such as Config, Logger, and utilities to make working with API parameters easier.

    • awserr - Provides the error interface that the SDK will use for all errors that occur in the SDK's processing. This includes service API response errors as well. The Error type is made up of a code and message. Cast the SDK's returned error type to awserr.Error and call the Code method to compare returned error to specific error codes. See the package's documentation for additional values that can be extracted such as RequestID.

    • credentials - Provides the types and built in credentials providers the SDK will use to retrieve AWS credentials to make API requests with. Nested under this folder are also additional credentials providers such as stscreds for assuming IAM roles, and ec2rolecreds for EC2 Instance roles.

    • endpoints - Provides the AWS Regions and Endpoints metadata for the SDK. Use this to lookup AWS service endpoint information such as which services are in a region, and what regions a service is in. Constants are also provided for all region identifiers, e.g UsWest2RegionID for "us-west-2".

    • session - Provides initial default configuration, and load configuration from external sources such as environment and shared credentials file.

    • request - Provides the API request sending, and retry logic for the SDK. This package also includes utilities for defining your own request retryer, and configuring how the SDK processes the request.

  • service - Clients for AWS services. All services supported by the SDK are available under this folder.

How to Use the SDK's AWS Service Clients

The SDK includes the Go types and utilities you can use to make requests to AWS service APIs. Within the service folder at the root of the SDK you'll find a package for each AWS service the SDK supports. All service clients follow common pattern of creation and usage.

When creating a client for an AWS service you'll first need to have a Session value constructed. The Session provides shared configuration that can be shared between your service clients. When service clients are created you can pass in additional configuration via the aws.Config type to override configuration provided by in the Session to create service client instances with custom configuration.

Once the service's client is created you can use it to make API requests the AWS service. These clients are safe to use concurrently.

Configuring the SDK

In the AWS SDK for Go, you can configure settings for service clients, such as the log level and maximum number of retries. Most settings are optional; however, for each service client, you must specify a region and your credentials. The SDK uses these values to send requests to the correct AWS region and sign requests with the correct credentials. You can specify these values as part of a session or as environment variables.

See the SDK's configuration guide for more information.

See the session package documentation for more information on how to use Session with the SDK.

See the Config type in the aws package for more information on configuration options.

Configuring Credentials

When using the SDK you'll generally need your AWS credentials to authenticate with AWS services. The SDK supports multiple methods of supporting these credentials. By default the SDK will source credentials automatically from its default credential chain. See the session package for more information on this chain, and how to configure it. The common items in the credential chain are the following:

  • Environment Credentials - Set of environment variables that are useful when sub processes are created for specific roles.

  • Shared Credentials file (~/.aws/credentials) - This file stores your credentials based on a profile name and is useful for local development.

  • EC2 Instance Role Credentials - Use EC2 Instance Role to assign credentials to application running on an EC2 instance. This removes the need to manage credential files in production.

Credentials can be configured in code as well by setting the Config's Credentials value to a custom provider or using one of the providers included with the SDK to bypass the default credential chain and use a custom one. This is helpful when you want to instruct the SDK to only use a specific set of credentials or providers.

This example creates a credential provider for assuming an IAM role, "myRoleARN" and configures the S3 service client to use that role for API requests.

  // Initial credentials loaded from SDK's default credential chain. Such as
  // the environment, shared credentials (~/.aws/credentials), or EC2 Instance
  // Role. These credentials will be used to to make the STS Assume Role API.
  sess := session.Must(session.NewSession())

  // Create the credentials from AssumeRoleProvider to assume the role
  // referenced by the "myRoleARN" ARN.
  creds := stscreds.NewCredentials(sess, "myRoleArn")

  // Create service client value configured for credentials
  // from assumed role.
  svc := s3.New(sess, &aws.Config{Credentials: creds})

See the credentials package documentation for more information on credential providers included with the SDK, and how to customize the SDK's usage of credentials.

The SDK has support for the shared configuration file (~/.aws/config). This support can be enabled by setting the environment variable, "AWS_SDK_LOAD_CONFIG=1", or enabling the feature in code when creating a Session via the Option's SharedConfigState parameter.

  sess := session.Must(session.NewSessionWithOptions(session.Options{
      SharedConfigState: session.SharedConfigEnable,
  }))

Configuring AWS Region

In addition to the credentials you'll need to specify the region the SDK will use to make AWS API requests to. In the SDK you can specify the region either with an environment variable, or directly in code when a Session or service client is created. The last value specified in code wins if the region is specified multiple ways.

To set the region via the environment variable set the "AWS_REGION" to the region you want to the SDK to use. Using this method to set the region will allow you to run your application in multiple regions without needing additional code in the application to select the region.

AWS_REGION=us-west-2

The endpoints package includes constants for all regions the SDK knows. The values are all suffixed with RegionID. These values are helpful, because they reduce the need to type the region string manually.

To set the region on a Session use the aws package's Config struct parameter Region to the AWS region you want the service clients created from the session to use. This is helpful when you want to create multiple service clients, and all of the clients make API requests to the same region.

  sess := session.Must(session.NewSession(&aws.Config{
      Region: aws.String(endpoints.UsWest2RegionID),
  }))

See the endpoints package for the AWS Regions and Endpoints metadata.

In addition to setting the region when creating a Session you can also set the region on a per service client bases. This overrides the region of a Session. This is helpful when you want to create service clients in specific regions different from the Session's region.

  svc := s3.New(sess, &aws.Config{
      Region: aws.String(endpoints.UsWest2RegionID),
  })

See the Config type in the aws package for more information and additional options such as setting the Endpoint, and other service client configuration options.

Making API Requests

Once the client is created you can make an API request to the service. Each API method takes a input parameter, and returns the service response and an error. The SDK provides methods for making the API call in multiple ways.

In this list we'll use the S3 ListObjects API as an example for the different ways of making API requests.

  • ListObjects - Base API operation that will make the API request to the service.

  • ListObjectsRequest - API methods suffixed with Request will construct the API request, but not send it. This is also helpful when you want to get a presigned URL for a request, and share the presigned URL instead of your application making the request directly.

  • ListObjectsPages - Same as the base API operation, but uses a callback to automatically handle pagination of the API's response.

  • ListObjectsWithContext - Same as base API operation, but adds support for the Context pattern. This is helpful for controlling the canceling of in flight requests. See the Go standard library context package for more information. This method also takes request package's Option functional options as the variadic argument for modifying how the request will be made, or extracting information from the raw HTTP response.

  • ListObjectsPagesWithContext - same as ListObjectsPages, but adds support for the Context pattern. Similar to ListObjectsWithContext this method also takes the request package's Option function option types as the variadic argument.

In addition to the API operations the SDK also includes several higher level methods that abstract checking for and waiting for an AWS resource to be in a desired state. In this list we'll use WaitUntilBucketExists to demonstrate the different forms of waiters.

  • WaitUntilBucketExists. - Method to make API request to query an AWS service for a resource's state. Will return successfully when that state is accomplished.

  • WaitUntilBucketExistsWithContext - Same as WaitUntilBucketExists, but adds support for the Context pattern. In addition these methods take request package's WaiterOptions to configure the waiter, and how underlying request will be made by the SDK.

The API method will document which error codes the service might return for the operation. These errors will also be available as const strings prefixed with "ErrCode" in the service client's package. If there are no errors listed in the API's SDK documentation you'll need to consult the AWS service's API documentation for the errors that could be returned.

  ctx := context.Background()

  result, err := svc.GetObjectWithContext(ctx, &s3.GetObjectInput{
      Bucket: aws.String("my-bucket"),
      Key: aws.String("my-key"),
  })
  if err != nil {
      // Cast err to awserr.Error to handle specific error codes.
      aerr, ok := err.(awserr.Error)
      if ok && aerr.Code() == s3.ErrCodeNoSuchKey {
          // Specific error code handling
      }
      return err
  }

  // Make sure to close the body when done with it for S3 GetObject APIs or
  // will leak connections.
  defer result.Body.Close()

  fmt.Println("Object Size:", aws.Int64Value(result.ContentLength))

API Request Pagination and Resource Waiters

Pagination helper methods are suffixed with "Pages", and provide the functionality needed to round trip API page requests. Pagination methods take a callback function that will be called for each page of the API's response.

   objects := []string{}
   err := svc.ListObjectsPagesWithContext(ctx, &s3.ListObjectsInput{
       Bucket: aws.String(myBucket),
   }, func(p *s3.ListObjectsOutput, lastPage bool) bool {
       for _, o := range p.Contents {
           objects = append(objects, aws.StringValue(o.Key))
       }
       return true // continue paging
   })
   if err != nil {
       panic(fmt.Sprintf("failed to list objects for bucket, %s, %v", myBucket, err))
   }

   fmt.Println("Objects in bucket:", objects)

Waiter helper methods provide the functionality to wait for an AWS resource state. These methods abstract the logic needed to check the state of an AWS resource, and wait until that resource is in a desired state. The waiter will block until the resource is in the state that is desired, an error occurs, or the waiter times out. If a resource times out the error code returned will be request.WaiterResourceNotReadyErrorCode.

  err := svc.WaitUntilBucketExistsWithContext(ctx, &s3.HeadBucketInput{
      Bucket: aws.String(myBucket),
  })
  if err != nil {
      aerr, ok := err.(awserr.Error)
      if ok && aerr.Code() == request.WaiterResourceNotReadyErrorCode {
          fmt.Fprintf(os.Stderr, "timed out while waiting for bucket to exist")
      }
      panic(fmt.Errorf("failed to wait for bucket to exist, %v", err))
  }
  fmt.Println("Bucket", myBucket, "exists")

Getting Help

Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests.

  • Ask a question on StackOverflow and tag it with the aws-sdk-go tag.
  • Come join the AWS SDK for Go community chat on gitter.
  • Open a support ticket with AWS Support.
  • If you think you may have found a bug, please open an issue.

This SDK implements AWS service APIs. For general issues regarding the AWS services and their limitations, you may also take a look at the Amazon Web Services Discussion Forums.

Opening Issues

If you encounter a bug with the AWS SDK for Go we would like to hear about it. Search the existing issues and see if others are also experiencing the issue before opening a new issue. Please include the version of AWS SDK for Go, Go language, and OS you’re using. Please also include reproduction case when appropriate.

The GitHub issues are intended for bug reports and feature requests. For help and questions with using AWS SDK for Go please make use of the resources listed in the Getting Help section. Keeping the list of open issues lean will help us respond in a timely manner.

Contributing

We work hard to provide a high-quality and useful SDK for our AWS services, and we greatly value feedback and contributions from our community. Please review our contributing guidelines before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your bug report or contribution.

Maintenance and support for SDK major versions

For information about maintenance and support for SDK major versions and our underlying dependencies, see the following in the AWS SDKs and Tools Shared Configuration and Credentials Reference Guide:

Go version support policy

The v2 SDK follows the upstream release policy with an additional six months of support for the most recently deprecated language version.

AWS reserves the right to drop support for unsupported Go versions earlier to address critical security issues.

Resources

Developer guide - This document is a general introduction on how to configure and make requests with the SDK. If this is your first time using the SDK, this documentation and the API documentation will help you get started. This document focuses on the syntax and behavior of the SDK. The Service Developer Guide will help you get started using specific AWS services.

SDK API Reference Documentation - Use this document to look up all API operation input and output parameters for AWS services supported by the SDK. The API reference also includes documentation of the SDK, and examples how to using the SDK, service client API operations, and API operation require parameters.

Service Documentation - Use this documentation to learn how to interface with AWS services. These guides are great for getting started with a service, or when looking for more information about a service. While this document is not required for coding, services may supply helpful samples to look out for.

SDK Examples - Included in the SDK's repo are several hand crafted examples using the SDK features and AWS services.

Forum - Ask questions, get help, and give feedback

Issues - Report issues, submit pull requests, and get involved (see Apache 2.0 License)

aws-sdk-go's People

Contributors

aajtodd avatar aws-sdk-go-automation avatar awstools avatar bflad avatar bpot avatar diehlaws avatar doug-aws avatar eddy-aws avatar euank avatar isaiahvita avatar jasdel avatar jjeffery avatar jordonphillips avatar jsgv avatar kaibalopez avatar lsegal avatar lucix-aws avatar muesli avatar nabeken avatar ncw avatar ranvaknin avatar rosenhouse avatar sbiscigl avatar skmcgrail avatar skotambkar avatar stefansundin avatar stripecodahale avatar titanous avatar wty-bryant avatar xibz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-sdk-go's Issues

Generated EC2 API doesn't set proper `ec2` tag values

Ran into this one. I'm sure this is other places but the exact place we ran into it was ec2.RunInstances. The RunInstancesReq struct doesn't set the ec2 tag on some fields properly so we get errors like:

Parameter ImageID is not recognized

We changed the ec2 tag to ec2:"ImageId" and that moved on, but to another error just like it. We then saw that a lot of the fields don't have the proper tag here.

Looks like the code gen just has to be updated...

Avoid hardcoded use of the logging package

Avoid using global calls to the logging package so that users of the library are free to provide their own implementation. Even more ideal would be using a logging interface that supports the context pattern as described in: #75

Correctly support flattened lists

A bug described in #23:

The current XML struct tag of sqs.ReceiveMessageResult.Messages is wrong
xml:"ReceiveMessageResult>Messages>Message" when it should be
xml:"ReceiveMessageResult>Message"

This is a result of aws-go not correctly supporting list shapes with a flattened attribute:

{
    "MessageList":{
      "type":"list",
      "member":{
        "shape":"Message",
        "locationName":"Message"
      },
      "flattened":true
    },
}

InternetGateway with igw-id fails

Greetings,

I found that if we add a gw-id to the DescribeInternetGateway method you get an error from AWS.

Below is a sample code

    id := "igw-XXXXX"
    DescribeIGWOpts := &ec2.DescribeInternetGatewaysRequest{
        InternetGatewayIDs: []string{id},
    }
    resp, err := cli.DescribeInternetGateways(DescribeIGWOpts)
    if err != nil {
        panic(err)
    }
    res := resp.InternetGateways[0]
    ID := res.InternetGatewayID
    fmt.Println(*ID)

Error:
panic: The parameter InternetGatewayIds is not recognised

use new import paths for go project

Replace all occourances of code.google.com/p/go.XXX with golang.org/x/XXX since this will break the compile starting with Go 1.5 and works already now. The Go team moved the official location of those repositories.

Support context pattern

See this blog article:

https://blog.golang.org/context

We use this heavily in all aspects of our SOA, and it allows us to inject request scoped parameters to systems that need them to provide useful information -- such as logging or in-memory caches. Here is a drastically simplified example:

type key int
const LoggerKey key = 0
const RequestIdKey key = 1
const MethodNameKey key = 2

type Logger interface {
    Debug(ctx context.Context, message, args ...interface{})
}    

// alternatively the context interface could have the log methods on them to avoid this step
func LoggerFrom(ctx context.Context) Logger {
    if logger, ok := ctx.Value(LoggerKey).(Logger); ok {
        return logger
    } else {
        return nullLogger
    }
}

ctx := context.WithCancel(context.Background())
ctx = context.WithValue(ctx, RequestIdKey, uuid.NewV4())
ctx = context.WithValue(ctx, LoggerKey, myLogger)

someFrontendMethod(ctx, other, arguments)

...

func someFrontendMethod(ctx context.Context, other int, arguments string) {
    ctx = context.WithValue(ctx, MethodNameKey, "someFrontendMethod")
    result, err := aws.DynamoDb().Get(ctx, ...) 
    ...
}

// totally made up interface, not implying this should be the real AWS one
func (d *DynamoDb) Get(ctx context.Context, some int, args string) (*Result, error) {
    LoggerFrom(ctx).Debug(ctx, "dynamodb.get - starting request")
    ...
}

This would then output something like:

[DEBUG] [requestId=5f0712749191adda1079e71c2403ec24d65ebf32] someFrontendMethod: dynamodb.get - starting request

Additionally, in the first method, you would be able to timeout the call to someFrontendMethod by closing the Done channel on the context. Depending upon how much of the callstack is using the context, every goroutine underneath it would be notified of the cancelled context and abort as soon as possible. In the case of the AWS lib, this could be used to abort an exponential backoff algorithm that is currently sleeping without the caller of the lib having to cancel manually somehow.

Do not hardcode HttpClient

Allow the user to specify which HTTP client they wish to use instead of using the global one. This is a common issue in many go libraries and it makes unit testing harder while also preventing usage on AppEngine or other environments requiring a custom client.

Generating a pre-signed URL to an S3 object

I would like to use my instance role credentials to generate a URL to an S3 object so that the instance can delegate access.

My use case is to enable a private docker registry to redirect clients to the S3 URL to an image directly, so that the registry itself doesn't have to bit-bash the whole thing from S3 and out to the client, but can instead just do a 302 redirect to an S3 URL which has temporary authorization signature embedded in the query parameters.

I don't need the API itself to produce the whole URLs (which would be nice), but I would like to be able to reuse the signing machinery at least.

Sound like a reasonable addition? I think it's not currently easy to implement because all of the signing machinery currently lives in private interfaces.

Timeout on fetching IAM credentials is too short

We just tried to use the IAM credentials, and it failed with:

listing IAM credentials: Get http://169.254.169.254/latest/meta-data/iam/security-credentials/: net/http: request canceled while waiting for connection

It looks like the root cause is that the Timeout is set too short. Can we increase the length significantly, please?

develop branch: panic when uploading files to s3

Comments apply to develop branch only!

In the s3 api.go code we have this

type PutObjectInput struct {
    XMLName xml.Name

    ACL                     *string           `xml:"-" name:"x-amz-acl"`
    Body                    io.Reader         `xml:"-"`

However Body is typecast into an io.ReadSeeker in aws/protocol/rest/build.go buildBody

This causes a backtrace like this

panic: interface conversion: ioutil.nopCloser is not io.ReadSeeker: missing method Seek [recovered]
    panic: interface conversion: ioutil.nopCloser is not io.ReadSeeker: missing method Seek

goroutine 31 [running]:
testing.func·006()
    /usr/local/go/src/testing/testing.go:441 +0x181
github.com/awslabs/aws-sdk-go/aws/protocol/rest.buildBody(0xc208034340, 0x7cff20, 0xc20806c200, 0xd9)
    /home/ncw/Code/Go/src/github.com/awslabs/aws-sdk-go/aws/protocol/rest/build.go:41 +0x15e
github.com/awslabs/aws-sdk-go/aws/protocol/rest.Build(0xc208034340)
    /home/ncw/Code/Go/src/github.com/awslabs/aws-sdk-go/aws/protocol/rest/build.go:17 +0x173
github.com/awslabs/aws-sdk-go/aws/protocol/restxml.Build(0xc208034340)
    /home/ncw/Code/Go/src/github.com/awslabs/aws-sdk-go/aws/protocol/restxml/restxml.go:12 +0x28
github.com/awslabs/aws-sdk-go/aws.(*HandlerList).Run(0xc208034348, 0xc208034340)
    /home/ncw/Code/Go/src/github.com/awslabs/aws-sdk-go/aws/core.go:248 +0x7e
github.com/awslabs/aws-sdk-go/aws.(*Request).Build(0xc208034340, 0x0, 0x0)
    /home/ncw/Code/Go/src/github.com/awslabs/aws-sdk-go/aws/core.go:173 +0x6e
github.com/awslabs/aws-sdk-go/aws.(*Request).Sign(0xc208034340, 0x0, 0x0)
    /home/ncw/Code/Go/src/github.com/awslabs/aws-sdk-go/aws/core.go:181 +0x3a
github.com/awslabs/aws-sdk-go/aws.(*Request).Send(0xc208034340, 0x0, 0x0)
    /home/ncw/Code/Go/src/github.com/awslabs/aws-sdk-go/aws/core.go:191 +0x3a
github.com/awslabs/aws-sdk-go/service/s3.(*S3).PutObject(0xc20802c050, 0xc20806c200, 0xc2080c6000, 0x0, 0x0)
    /home/ncw/Code/Go/src/github.com/awslabs/aws-sdk-go/service/s3/api.go:1549 +0x5c
github.com/ncw/rclone/s3.(*FsObjectS3).Update(0xc20802e7d0, 0x7f2e04c2e8b8, 0xc2080c2960, 0xeb20d7a72, 0x7f2e1dcd64ff, 0x9d9f80, 0x64, 0x0, 0x0)
    /home/ncw/Code/Go/src/github.com/ncw/rclone/s3/s3.go:625 +0x421
github.com/ncw/rclone/s3.(*FsS3).Put(0xc20803b1c0, 0x7f2e04c2e8b8, 0xc2080c2960, 0x80b7b0, 0xd, 0xeb20d7a72, 0x1dcd64ff, 0x9d9f80, 0x64, 0x0, ...)
    /home/ncw/Code/Go/src/github.com/ncw/rclone/s3/s3.go:408 +0x127
github.com/ncw/rclone/fstest/fstests.testPut(0xc2080522d0, 0x9d9920)
    /home/ncw/Code/Go/src/github.com/ncw/rclone/fstest/fstests/fstests.go:137 +0x2eb
github.com/ncw/rclone/fstest/fstests.TestFsPutFile1(0xc2080522d0)
    /home/ncw/Code/Go/src/github.com/ncw/rclone/fstest/fstests/fstests.go:150 +0x42
github.com/ncw/rclone/s3_test.TestFsPutFile1(0xc2080522d0)
    /home/ncw/Code/Go/src/github.com/ncw/rclone/s3/s3_test.go:29 +0x28
testing.tRunner(0xc2080522d0, 0x9db220)
    /usr/local/go/src/testing/testing.go:447 +0xbf
created by testing.RunTests
    /usr/local/go/src/testing/testing.go:555 +0xa8b

The input can't be a ReadCloser without making the package a lot less useful, so you will have to rethink your hashing in aws/signer/v4/v4.go makeSha256Reader I think!

Also an unchecked type assertion is really ugly...

s3: Metadata support isn't working

In s3.HeadObject and s3.GetObject we need to read the meta headers.

And in s3.PutObject (and s3.CopyObject and possibly others) it doesn't do anything at all with PutObjectRequest.Metadata so the metadata isn't being set.

Here is a patch which fixes the problem by monkey patching the generated s3 file. This needs a proper fix to the generator of course, but should illustrate the problem.

--- a/gen/s3/s3.go
+++ b/gen/s3/s3.go
@@ -327,6 +327,10 @@ func (c *S3) CopyObject(req *CopyObjectRequest) (resp *CopyObjectOutput, err err
        httpReq.Header.Set("x-amz-website-redirect-location", *req.WebsiteRedirectLocation)
    }

+   for name, value := range req.Metadata {
+       httpReq.Header.Set(name, value)
+   }
+
    httpResp, err := c.client.Do(httpReq)
    if err != nil {
        return
@@ -1647,7 +1651,7 @@ func (c *S3) GetObject(req *GetObjectRequest) (resp *GetObjectOutput, err error)

    resp.Metadata = map[string]string{}
    for name := range httpResp.Header {
-       if strings.HasPrefix(name, "headers") {
+       if strings.HasPrefix(name, "X-Amz-Meta-") {
            resp.Metadata[name] = httpResp.Header.Get(name)
        }
    }
@@ -2022,7 +2026,7 @@ func (c *S3) HeadObject(req *HeadObjectRequest) (resp *HeadObjectOutput, err err

    resp.Metadata = map[string]string{}
    for name := range httpResp.Header {
-       if strings.HasPrefix(name, "headers") {
+       if strings.HasPrefix(name, "X-Amz-Meta-") {
            resp.Metadata[name] = httpResp.Header.Get(name)
        }
    }
@@ -3037,6 +3041,10 @@ func (c *S3) PutObject(req *PutObjectRequest) (resp *PutObjectOutput, err error)
        httpReq.Header.Set("x-amz-website-redirect-location", *req.WebsiteRedirectLocation)
    }

+   for name, value := range req.Metadata {
+       httpReq.Header.Set(name, value)
+   }
+
    httpResp, err := c.client.Do(httpReq)
    if err != nil {
        return

Mapping "timestamp" to time.Time causes error in some APIs

Hi, thank you for your work, your aws-go is super! The world was waiting for this!

DynamoDB.CreateTable() fails with an error like:
parsing time "1418743220.164" as ""2006-01-02T15:04:05Z07:00"": cannot parse "1418743220.164" as """.

I found that this is because "type":"timestamp" is mapped to time.Time, but this API actually returns a UNIX epoch time like "1418743220.164" for CreationDateTime so it can't be unmarshalled to time.Time (its UnmarshalJSON supports RFC3339 timestamps only).

The problem is that most of other AWS APIs returns RFC3339/ISO8601 for "timestamp" type and it works fine.

botocore seems to have it's own parsing logic to handle this problem.
https://github.com/boto/botocore/blob/develop/botocore/utils.py#L277

May be adding aws.TimeStampValue with an UnmarshalJSON like botocore.utils.parse_timestamp is a possible solution.

Sending requests with []ec2.Filter appears to be broken

sending API requests with the Filters element set appears to be broken currently. The reflection code in aws/ec2.go doesn't have a case for the []ec2.Filter type and subsequently tries to treat it like a struct, with fails with a panic.

Test code:

creds := aws.Creds("", "", "")
client := ec2.New(creds, "us-east-1", nil)
client.DescribeInstances(&ec2.DescribeInstancesRequest{
    Filters : []ec2.Filter{ec2.Filter{aws.String("SecurityGroups"), []string{""}}}})
panic: reflect: call of reflect.Value.NumField on slice Value

goroutine 22 [running]:
runtime.panic(0x335de0, 0xc2081f4c80)
    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/runtime/panic.c:279 +0xf5
reflect.flag.mustBe(0x172, 0x19)
    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/reflect/value.go:307 +0x8c
reflect.Value.NumField(0x2a65a0, 0xc2081f4c40, 0x0, 0x172, 0x68d1d8)
    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/reflect/value.go:1321 +0x30
github.com/stripe/aws-go/aws.(*EC2Client).loadStruct(0xc2082fc240, 0xc2082a5500, 0x2a65a0, 0xc2081f4c40, 0x0, 0x172, 0x440755, 0x6, 0x0, 0x0)
    /Users/cliff/new_project/src/github.com/stripe/aws-go/aws/ec2.go:93 +0x128
github.com/stripe/aws-go/aws.(*EC2Client).loadValues(0xc2082fc240, 0xc2082a5500, 0x2a65a0, 0xc2081f4c40, 0x440755, 0x6, 0x0, 0x0)
    /Users/cliff/new_project/src/github.com/stripe/aws-go/aws/ec2.go:84 +0x12a
github.com/stripe/aws-go/aws.(*EC2Client).loadStruct(0xc2082fc240, 0xc2082a5500, 0x389020, 0xc2082bb1d0, 0x0, 0x196, 0x3c7940, 0x0, 0x0, 0x0)
    /Users/cliff/new_project/src/github.com/stripe/aws-go/aws/ec2.go:135 +0xa3c
github.com/stripe/aws-go/aws.(*EC2Client).loadValues(0xc2082fc240, 0xc2082a5500, 0x2952c0, 0xc2082bb1d0, 0x3c7940, 0x0, 0x0, 0x0)
    /Users/cliff/new_project/src/github.com/stripe/aws-go/aws/ec2.go:84 +0x12a
github.com/stripe/aws-go/aws.(*EC2Client).Do(0xc2082fc240, 0x3fee50, 0x11, 0x3cd120, 0x4, 0x3c85e0, 0x1, 0x2952c0, 0xc2082bb1d0, 0x295320, ...)
    /Users/cliff/new_project/src/github.com/stripe/aws-go/aws/ec2.go:25 +0x206
github.com/stripe/aws-go/gen/ec2.(*EC2).DescribeInstances(0xc20803c078, 0xc2082bb1d0, 0xc2081f4be0, 0x0, 0x0)
    /Users/cliff/new_project/src/github.com/stripe/aws-go/gen/ec2/ec2.go:1107 +0xeb

SimpleDB not working

Hi,
I wanted to use this library for a project of mine which needs simpledb. Sadly, every api call to simpledb results in the following error:

roberto@voidray ~/projects/test $ go run main.go
2015/01/27 10:43:55 expected element type <ErrorResponse> but have <Response>
exit status 1

The script I used is the following:

package main

import (
    "fmt"
    "log"

    "github.com/stripe/aws-go/aws"
    "github.com/stripe/aws-go/gen/sdb"
)

func main() {
    var (
        creds  = aws.DetectCreds("", "", "")
        client = sdb.New(creds, "eu-west-1", nil)
    )

    attrs, err := client.GetAttributes(nil)

    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("%s \n", attrs)
}

I also tried to pass sensible values to the GetAttributes call with no luck.
p.s.: the credentials work, I tested them with the example in the README and it works fine

Panic when requesting with time.Time fields

Revision: c163213

Reproduction: Make a request containing a time.Time field like:

  client := cloudwatch.New(aws.DetectCreds("", "", ""), "us-east-1", http.DefaultClient)                                                                                                                                                                                                                                                                       
  res, err := client.GetMetricStatistics(&cloudwatch.GetMetricStatisticsInput{                                                                                                                
    StartTime:  time.Now().Add(-20 * time.Hour),                                                                                                                                  
    EndTime:    time.Now(),                                                                                                                                                       
    Namespace:  aws.String("AWS/ELB"),                                                                                                                                            
    MetricName: aws.String("Latency"),                                                                                                                                            
    Period:     aws.Integer(60),                                                                                                                                                  
    Statistics: []string{"Sum", "Maximum", "Minimum", "SampleCount", "Average"},                                                                                                  
  })  

Expected response:

res contains a valid response, err is nil.

Actual response:

panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

goroutine 1 [running]:
reflect.valueInterface(0x26b8e0, 0xc20801e8a0, 0x66, 0x1, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:883 +0xf4
reflect.Value.Interface(0x26b8e0, 0xc20801e8a0, 0x66, 0x0, 0x0)
        /usr/local/go/src/reflect/value.go:872 +0x53
github.com/stripe/aws-go/aws.(*QueryClient).loadValue(0xc20802c060, 0xc20803c5d0, 0x26b8e0, 0xc20801e8a0, 0x66, 0xc20802ae00, 0xb, 0x0, 0x0)
        /gopath/src/github.com/stripe/aws-go/aws/query.go:177 +0x307
github.com/stripe/aws-go/aws.(*QueryClient).loadStruct(0xc20802c060, 0xc20803c5d0, 0x340700, 0xc20801e8a0, 0x59, 0x3704b5, 0x7, 0x0, 0x0)
        /gopath/src/github.com/stripe/aws-go/aws/query.go:168 +0x5ae
github.com/stripe/aws-go/aws.(*QueryClient).loadValues(0xc20802c060, 0xc20803c5d0, 0x340700, 0xc20801e8a0, 0x3704b5, 0x7, 0x0, 0x0)
        /gopath/src/github.com/stripe/aws-go/aws/query.go:92 +0xcd2
github.com/stripe/aws-go/aws.(*QueryClient).loadValue(0xc20802c060, 0xc20803c5d0, 0x340700, 0xc208052018, 0xd9, 0x3704b5, 0x7, 0x0, 0x0)
        /gopath/src/github.com/stripe/aws-go/aws/query.go:214 +0xafd
github.com/stripe/aws-go/aws.(*QueryClient).loadStruct(0xc20802c060, 0xc20803c5d0, 0x31fb20, 0xc208052000, 0xd9, 0x0, 0x0, 0x0, 0x0)
        /gopath/src/github.com/stripe/aws-go/aws/query.go:168 +0x5ae
github.com/stripe/aws-go/aws.(*QueryClient).loadValues(0xc20802c060, 0xc20803c5d0, 0x254b00, 0xc208052000, 0x0, 0x0, 0x0, 0x0)
        /gopath/src/github.com/stripe/aws-go/aws/query.go:92 +0xcd2
github.com/stripe/aws-go/aws.(*QueryClient).Do(0xc20802c060, 0x377eb0, 0x13, 0x34a270, 0x4, 0x345c90, 0x1, 0x254b00, 0xc208052000, 0x254b60, ...)
        /gopath/src/github.com/stripe/aws-go/aws/query.go:26 +0x232
github.com/stripe/aws-go/gen/cloudwatch.(*CloudWatch).GetMetricStatistics(0xc20802e020, 0xc208052000, 0xc20801e020, 0x0, 0x0)
        /gopath/src/github.com/stripe/aws-go/gen/cloudwatch/cloudwatch.go:118 +0xea
main.main()
        /gopath/src/repo/main.go:43 +0x3f8,

sqs: AttributeName and MessageAttributeName

We need to set All to AttributeName and MessageAttributeName in ReceiveMessage to receive messages even if messages have message attributes. (See http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html)

aws-go does not work as I expected even if I set MessageAttributeNames = []string{"All"}.

Expected

aws-go should post to https://ap-northeast-1.queue.amazonaws.com/ Action=ReceiveMessage&AttributeName=All&MaxNumberOfMessages=10&MessageAttributeName=All&QueueUrl=<snip>&Version=2012-11-05

Actual

aws-go posts to https://ap-northeast-1.queue.amazonaws.com/ Action=ReceiveMessage&AttributeName.member.1=All&MaxNumberOfMessages=10&MessageAttributeName.member.1=All&QueueUrl=<snip>&Version=2012-11-05

Any ideas?

APIError should include HTTP StatusCode

Not all APIs return an error response, some just return HTTP status codes.

Eg S3 Head Object - "This implementation of the operation does not return special errors". Which is used in s3.S3.HeadObject

Using s3curl you can verify this quite easily, eg

./s3curl.pl --id aws --head -- -v http://s3.amazonaws.com/mybucket/not-found

Returns just a 404 error and no body.

HTTP/1.1 404 Not Found
x-amz-request-id: 4C6...
x-amz-id-2: 64y6...
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Sun, 28 Dec 2014 09:51:40 GMT
Server: AmazonS3

So I think APIError should have an StatusCode field, and RESTClient.Do should set it if returning an error otherwise it is impossible to tell the errors apart using this API.

PS Happy to make a pull request for this if you agree!

Cognito Identity parser throws errors

I'm not entirely sure if this is an issue with the go code or the amazon api servers:

parsing time "1.421516513393E9" as ""2006-01-02T15:04:05Z07:00"": cannot parse "1.421516513393E9" as """

At issue are the datetimes returned from the call as float's, instead of... datetime, whatever that might look like.

{"CreationDate":1.421516513393E9,"IdentityId":"us-east-1:XX-XX-XX-XX-XX","LastModifiedDate":1.421516513393E9}

s3: Object.Size needs to be 64 bit

s3.Object.Size is defined as

type Object struct {
    XMLName xml.Name `xml:"Object"`

    ETag         aws.StringValue  `xml:"ETag"`
    Key          aws.StringValue  `xml:"Key"`
    LastModified time.Time        `xml:"LastModified"`
    Owner        *Owner           `xml:"Owner,omitempty"`
    Size         aws.IntegerValue `xml:"Size"`
    StorageClass aws.StringValue  `xml:"StorageClass"`
}

And aws.IntegerValue is defined as

// An IntegerValue is an integer which may or may not be present.
type IntegerValue *int

However s3 objects can be bigger than 2GB, meaning that on 32 bit platforms the Size field isn't big enough.

So either IntegerValue needs to be int64 or there needs to be a new type used there.

Support reading/writing typed structs in DynamoDB

Instead of making callers deal with items of the form map[string]dynamodb.AttributeValue, it's convenient to be able to read and write typed structs.

I previously implemented a solution for goamz (AdRoll/goamz#276), and the same approach will work as both projects use similar types (compare https://github.com/awslabs/aws-sdk-go/blob/master/gen/dynamodb/dynamodb.go#L334 to https://github.com/AdRoll/goamz/blob/master/dynamodb/dynamizer/dynamizer.go#L18).

Happy to look into porting over my changes if there is interest in a similar solution.

Unconsidered map structure

I am trying to send a message to SQS using SQS#SendMessage.
So I wrote the code like this:

client := sqs.New(myCred, "ap-northeast-1", nil)
req := &sqs.SendMessageRequest{
    DelaySeconds:      aws.Integer(0),
    MessageAttributes: map[string]sqs.MessageAttributeValue{},
    MessageBody:       aws.String("foo"),
    QueueURL:          aws.String("https://sqs.ap-northeast-1.amazonaws.com/000000000000/bar"),
}
res, err := client.SendMessage(req)

But I encountered a panic during SendMessage:

panic: reflect: call of reflect.Value.NumField on map Value

goroutine 16 [running]:
runtime.panic(0x2ad540, 0xc2080405c0)
    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/runtime/panic.c:279 +0xf5
reflect.flag.mustBe(0x150, 0x19)
    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/reflect/value.go:307 +0x8c
reflect.Value.NumField(0x249d60, 0xc208022c90, 0x0, 0x150, 0x56c230)
    /usr/local/Cellar/go/1.3.3/libexec/src/pkg/reflect/value.go:1321 +0x30
github.com/stripe/aws-go/aws.(*QueryClient).loadStruct(0xc208004300, 0xc208022cc0, 0x249d60, 0xc208022c90, 0x0, 0x150, 0x351ed5, 0x10, 0x0, 0x0)
    /Users/myhome/.go/src/github.com/stripe/aws-go/aws/query.go:93 +0x128

I think this is likely to be caused by the field MessageAttributes in the structure SendMessageRequest.
There is no map structure type in switch clause written in QueryClient#loadStruct called from SendMessage.

s3: can't access objects with non url safe characters in

Can't access objects with non url safe characters in, eg here is the filename I use in my test suite for rclone: hello? sausage/êé/Hello, 世界/ " ' @ < > & ?/z.txt

My attempt to fix it didn't work because it interacted with the signing in some way I don't understand giving this error

Put error The request signature we calculated does not match the signature you provided. Check your key and signing method.
--- a/gen/s3/s3.go
+++ b/gen/s3/s3.go
@@ -2921,6 +2925,12 @@ func (c *S3) PutBucketWebsite(req *PutBucketWebsiteRequest) (err error) {
    return
 }

+// Escape a URL path properly
+func PathEscape(path string) string {
+   // Would like to call url.escape(path, encodePath) here
+   return strings.Replace(url.QueryEscape(path), "+", "%20", -1)
+}
+
 // PutObject is undocumented.
 func (c *S3) PutObject(req *PutObjectRequest) (resp *PutObjectOutput, err error) {
    resp = &PutObjectOutput{}
@@ -2933,13 +2943,15 @@ func (c *S3) PutObject(req *PutObjectRequest) (resp *PutObjectOutput, err error)
    uri := c.client.Endpoint + "/{Bucket}/{Key+}"

    if req.Bucket != nil {
-       uri = strings.Replace(uri, "{"+"Bucket"+"}", *req.Bucket, -1)
-       uri = strings.Replace(uri, "{"+"Bucket+"+"}", *req.Bucket, -1)
+       bucketEscape := PathEscape(*req.Bucket)
+       uri = strings.Replace(uri, "{"+"Bucket"+"}", bucketEscape, -1)
+       uri = strings.Replace(uri, "{"+"Bucket+"+"}", bucketEscape, -1)
    }

    if req.Key != nil {
-       uri = strings.Replace(uri, "{"+"Key"+"}", *req.Key, -1)
-       uri = strings.Replace(uri, "{"+"Key+"+"}", *req.Key, -1)
+       keyEscape := PathEscape(*req.Key)
+       uri = strings.Replace(uri, "{"+"Key"+"}", keyEscape, -1)
+       uri = strings.Replace(uri, "{"+"Key+"+"}", keyEscape, -1)
    }

    q := url.Values{}

Bug when marshaling requests with time.Time

Bug when marshaling requests with time.Time

The time.Time structure only contains hidden fields (http://golang.org/pkg/time/#Time). When the interface is reflected in github.com/stripe/aws-go/aws/ec2.go:132, the panic is raised.

Possible solution: Add a case in func (c *EC2Client) loadStruct(...) to specifically handle time.Time, avoiding reflection within the structure.

Problem Code

func bug(credentials aws.CredentialsProvider) {
    e := ec2.New(credentials, "us-east-1", nil)

    Price := "1.0"
    Count := 1
    ImageID := "ami-12345678"
    InstanceType := "m3.large"

    req := ec2.RequestSpotInstancesRequest{
        SpotPrice:     &Price,
        InstanceCount: &Count,
        LaunchSpecification: &ec2.RequestSpotLaunchSpecification{
            ImageID:      &ImageID,
            InstanceType: &InstanceType,
        },
    }

    resp, err := e.RequestSpotInstances(&req)
    if err != nil {
        panic(err)
    }

    fmt.Println(*resp.SpotInstanceRequests[0].Status.Message)
}

Stack Trace

panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

goroutine 1 [running]:
reflect.valueInterface(0x2737c0, 0xc20801ec60, 0x66, 0xc208083101, 0x0, 0x0)
    /usr/local/go/src/reflect/value.go:883 +0xf4
reflect.Value.Interface(0x2737c0, 0xc20801ec60, 0x66, 0x0, 0x0)
    /usr/local/go/src/reflect/value.go:872 +0x53
github.com/stripe/aws-go/aws.(*EC2Client).loadStruct(0xc20802a2a0, 0xc20803b080, 0x366c00, 0xc20801ec60, 0x59, 0x3cdad5, 0x9, 0x0, 0x0)
    /Users/tyler/go/src/github.com/stripe/aws-go/aws/ec2.go:132 +0x2eb
github.com/stripe/aws-go/aws.(*EC2Client).loadValues(0xc20802a2a0, 0xc20803b080, 0x366c00, 0xc20801ec60, 0x3cdad5, 0x9, 0x0, 0x0)
    /Users/tyler/go/src/github.com/stripe/aws-go/aws/ec2.go:113 +0x382
github.com/stripe/aws-go/aws.(*EC2Client).loadStruct(0xc20802a2a0, 0xc20803b080, 0x344520, 0xc208011030, 0xd9, 0x0, 0x0, 0x0, 0x0)
    /Users/tyler/go/src/github.com/stripe/aws-go/aws/ec2.go:164 +0xa8f
github.com/stripe/aws-go/aws.(*EC2Client).loadValues(0xc20802a2a0, 0xc20803b080, 0x2598e0, 0xc208011030, 0x0, 0x0, 0x0, 0x0)
    /Users/tyler/go/src/github.com/stripe/aws-go/aws/ec2.go:113 +0x382
github.com/stripe/aws-go/aws.(*EC2Client).Do(0xc20802a2a0, 0x3a8210, 0x14, 0x372910, 0x4, 0x36df90, 0x1, 0x2598e0, 0xc208011030, 0x259940, ...)
    /Users/tyler/go/src/github.com/stripe/aws-go/aws/ec2.go:26 +0x232
github.com/stripe/aws-go/gen/ec2.(*EC2).RequestSpotInstances(0xc20802c048, 0xc208011030, 0xc20801ea20, 0x0, 0x0)
    /Users/tyler/go/src/github.com/stripe/aws-go/gen/ec2/ec2.go:1956 +0xea
main.bug(0x1111e98, 0xc20803af00)

Bulk Insert on Redshift

SO right now there is no easy way to do bulk inserts on redshift using Go. Only options I found are either writing my own query formatter (this gets messy real fast), or do a transaction (which avoids the use of goroutines).

Just hoping that someone comes up with a bulk insert function for Redshift. That would allow using redshift for real time analytics without having to rely on a middleware buffer.

PollForDecisionTask on SWF client returns error

Only happens when a valid decision task is received, getting this error:
strconv.ParseInt: parsing "1.420630155882E9": invalid syntax

If the decision task is empty, it returns without an error, and TaskToken is nil as expected.

I think this is coming from aws.JSONClient, when it decodes the response data, but can't why that's happening - perhaps in HistoryEvent struct? I'll keep digging around, but not even really sure where to start.

Calling it like this:

input := &swf.PollForDecisionTaskInput{
    Domain: aws.String("domain"),
    TaskList: &swf.TaskList{
        Name: aws.String("tasklist"),
    },
}
d, err := swfCli.PollForDecisionTask(input)

Invalid signature on S3 file upload

I am trying to upload a file using the S3 PutObject method, but the upload fails because of invalid signature.
I know my credentials work because the ListObjects method returns the content of the bucket I am trying to upload to.

Is this the correct way to prepare a object upload request?

 59         // create a bucket upload request and send
 60         objectreq := s3.PutObjectRequest{
 61                 Bucket:      aws.String(bucket),
 62                 Body:        fd,
 63                 ContentType: aws.String(contenttype),
 64                 Key:         aws.String(fd.Name()),
 65         }

Full program at https://gist.github.com/jvehent/94cd0720985b04e5fd0f

XML conflict using route53 ListHostedZones

Trying to call with no options in the request (defaults) and can't seem to get it to work. Looks like XML Path conflicts.

package main

import(
  "fmt"
  "github.com/stripe/aws-go/aws"
  "github.com/stripe/aws-go/gen/route53"
)

var aws_access_key_id string = "key"
var aws_secret_access_key string = "secret"

func main() {
  creds := aws.Creds(aws_access_key_id, aws_secret_access_key, "")
  r53cl := route53.New(creds, "us-east-1", nil)
  resp, err := r53cl.ListHostedZones(&route53.ListHostedZonesRequest{})
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(resp)
}

The response error is:

xml: name "Config" in tag of route53.HostedZone.Config conflicts with name "HostedZoneConfig" in *route53.HostedZoneConfig.XMLName

Support exceptions

As-is, the clients return a generic APIError.

This is… not as helpful as it could be.

s3.PutObject and s3.CopyObject calls do not work on keys that contain equal signs

Here's a small program that demonstrates the bug in the library. The issue in short is that s3.* operations don't work on keys that contain = signs. That character, however, is a valid character in s3 object keys.

package main

import (
    "bytes"
    "flag"
    "github.com/awslabs/aws-sdk-go/aws"
    "github.com/awslabs/aws-sdk-go/gen/s3"
    "io"
    "log"
    "os"
)

type bodyContent struct {
    io.Reader
}

func (b *bodyContent) Close() error { return nil }

func main() {
    bucket := flag.String("b", "", "bucket to use")
    key := flag.String("k", "", "key name to use")
    flag.Parse()

    if *bucket == "" || *key == "" {
        flag.Usage()
        os.Exit(1)
    }

    creds := aws.DetectCreds("", "", "")
    client := s3.New(creds, "us-east-1", nil)

    buf := bytes.NewBufferString("content")
    _, err := client.PutObject(
        &s3.PutObjectRequest{
            Bucket:        aws.String(*bucket),
            Body:          &bodyContent{buf},
            Key:           aws.String(*key),
            ContentLength: aws.Long(int64(buf.Len())),
        })
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("successfully uploaded")
}

The bug can be demonstrated like so:

$ go run main.go -b cond-test -k 'my=object'
2015/02/02 15:25:25 The request signature we calculated does not match the signature you provided. Check your key and signing method.
exit status 1
$ go run main.go -b cond-test -k 'myobject'
2015/02/02 15:26:29 successfully uploaded

The expected behavior is that the library supports = characters in object keys.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.