Skip to content

Commit

Permalink
Update v2 SDKs example and documentation (#86)
Browse files Browse the repository at this point in the history
Updates the SDK's examples and documentation to use the v2 configuration pattern.

Fix #85
  • Loading branch information
jasdel authored Jan 9, 2018
1 parent 493e3ce commit 14d1593
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 508 deletions.
7 changes: 3 additions & 4 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ type Config struct {
// for empty directory names in s3 requests.
//
// Example:
// sess := session.Must(session.NewSession(&aws.Config{
// DisableRestProtocolURICleaning: aws.Bool(true),
// }))
// cfg, err := external.LoadDefaultAWSConfig()
// cfg.DisableRestProtocolURICleaning = true
//
// svc := s3.New(sess)
// svc := s3.New(cfg)
// out, err := svc.GetObject(&s3.GetObjectInput {
// Bucket: aws.String("bucketname"),
// Key: aws.String("//foo//bar//moo"),
Expand Down
10 changes: 4 additions & 6 deletions aws/defaults/defaults.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Package defaults is a collection of helpers to retrieve the SDK's default
// configuration and handlers.
//
// Generally this package shouldn't be used directly, but session.Session
// Generally this package shouldn't be used directly, but external.Config
// instead. This package is useful when you need to reset the defaults
// of a session or service client to the SDK defaults before setting
// of a service client to the SDK defaults before setting
// additional parameters.
//
// TODO rename to "default"
package defaults

import (
Expand Down Expand Up @@ -43,7 +41,7 @@ func (l defaultLogger) Log(args ...interface{}) {
//
// Generally you shouldn't need to use this method directly, but
// is available if you need to reset the configuration of an
// existing service client or session.
// existing service client.
func Config() aws.Config {
return aws.Config{
EndpointResolver: endpoints.NewDefaultResolver(),
Expand Down Expand Up @@ -74,7 +72,7 @@ func HTTPClient() *http.Client {
//
// Generally you shouldn't need to use this method directly, but
// is available if you need to reset the request handlers of an
// existing service client or session.
// existing service client.
func Handlers() aws.Handlers {
var handlers aws.Handlers

Expand Down
4 changes: 2 additions & 2 deletions aws/ec2metadata/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type EC2Metadata struct {
*aws.Client
}

// New creates a new instance of the EC2Metadata client with a session.
// New creates a new instance of the EC2Metadata client with a Config.
// This client is safe to use across multiple goroutines.
//
// Example:
// // Create a EC2Metadata client from just a session.
// // Create a EC2Metadata client from just a config.
// svc := ec2metadata.New(cfg)
func New(config aws.Config) *EC2Metadata {
svc := &EC2Metadata{
Expand Down
2 changes: 1 addition & 1 deletion aws/endpoints/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// If a type implements the Resolver interface it can be used to resolve
// endpoints. To use this with the SDK's Session and Config set the value
// of the type to the EndpointsResolver field of aws.Config when initializing
// the session, or service client.
// the service client.
//
// In addition the ResolverFunc is a wrapper for a func matching the signature
// of Resolver.ResolveEndpoint, converting it to a type that satisfies the
Expand Down
2 changes: 1 addition & 1 deletion aws/external/env_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type EnvConfig struct {
//
// Setting a custom HTTPClient in the aws.Config options will override this setting.
// To use this option and custom HTTP client, the HTTP client needs to be provided
// when creating the session. Not the service client.
// when creating the config. Not the service client.
//
// AWS_CA_BUNDLE=$HOME/my_custom_ca_bundle
CustomCABundle string
Expand Down
11 changes: 7 additions & 4 deletions aws/stscreds/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ future AWS service API operation calls.
The SDK will ensure that per instance of credentials.Credentials all requests
to refresh the credentials will be synchronized. But, the SDK is unable to
ensure synchronous usage of the AssumeRoleProvider if the value is shared
between multiple Credentials, Sessions or service clients.
between multiple Credentials or service clients.
Assume Role
Expand All @@ -17,15 +17,18 @@ with the SDKs's stscreds package.
// 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())
cfg, err := external.LoadDefaultAWSConfig()
// Create the credentials from AssumeRoleProvider to assume the role
// referenced by the "myRoleARN" ARN.
creds := stscreds.NewCredentials(sess, "myRoleArn")
stsSvc := sts.New(cfg)
stsCredProvider := stscreds.NewAssumeRoleProvider(stsSvc, "myRoleArn")
cfg.Credentials = aws.NewCredentials(stsCredProvider)
// Create service client value configured for credentials
// from assumed role.
svc := s3.New(sess, &aws.Config{Credentials: creds})
svc := s3.New(cfg)
Assume Role with static MFA Token
Expand Down
Loading

0 comments on commit 14d1593

Please sign in to comment.