Skip to content

Commit 14d1593

Browse files
authored
Update v2 SDKs example and documentation (#86)
Updates the SDK's examples and documentation to use the v2 configuration pattern. Fix #85
1 parent 493e3ce commit 14d1593

File tree

20 files changed

+176
-508
lines changed

20 files changed

+176
-508
lines changed

aws/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ type Config struct {
6969
// for empty directory names in s3 requests.
7070
//
7171
// Example:
72-
// sess := session.Must(session.NewSession(&aws.Config{
73-
// DisableRestProtocolURICleaning: aws.Bool(true),
74-
// }))
72+
// cfg, err := external.LoadDefaultAWSConfig()
73+
// cfg.DisableRestProtocolURICleaning = true
7574
//
76-
// svc := s3.New(sess)
75+
// svc := s3.New(cfg)
7776
// out, err := svc.GetObject(&s3.GetObjectInput {
7877
// Bucket: aws.String("bucketname"),
7978
// Key: aws.String("//foo//bar//moo"),

aws/defaults/defaults.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Package defaults is a collection of helpers to retrieve the SDK's default
22
// configuration and handlers.
33
//
4-
// Generally this package shouldn't be used directly, but session.Session
4+
// Generally this package shouldn't be used directly, but external.Config
55
// instead. This package is useful when you need to reset the defaults
6-
// of a session or service client to the SDK defaults before setting
6+
// of a service client to the SDK defaults before setting
77
// additional parameters.
8-
//
9-
// TODO rename to "default"
108
package defaults
119

1210
import (
@@ -43,7 +41,7 @@ func (l defaultLogger) Log(args ...interface{}) {
4341
//
4442
// Generally you shouldn't need to use this method directly, but
4543
// is available if you need to reset the configuration of an
46-
// existing service client or session.
44+
// existing service client.
4745
func Config() aws.Config {
4846
return aws.Config{
4947
EndpointResolver: endpoints.NewDefaultResolver(),
@@ -74,7 +72,7 @@ func HTTPClient() *http.Client {
7472
//
7573
// Generally you shouldn't need to use this method directly, but
7674
// is available if you need to reset the request handlers of an
77-
// existing service client or session.
75+
// existing service client.
7876
func Handlers() aws.Handlers {
7977
var handlers aws.Handlers
8078

aws/ec2metadata/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ type EC2Metadata struct {
2020
*aws.Client
2121
}
2222

23-
// New creates a new instance of the EC2Metadata client with a session.
23+
// New creates a new instance of the EC2Metadata client with a Config.
2424
// This client is safe to use across multiple goroutines.
2525
//
2626
// Example:
27-
// // Create a EC2Metadata client from just a session.
27+
// // Create a EC2Metadata client from just a config.
2828
// svc := ec2metadata.New(cfg)
2929
func New(config aws.Config) *EC2Metadata {
3030
svc := &EC2Metadata{

aws/endpoints/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
// If a type implements the Resolver interface it can be used to resolve
4242
// endpoints. To use this with the SDK's Session and Config set the value
4343
// of the type to the EndpointsResolver field of aws.Config when initializing
44-
// the session, or service client.
44+
// the service client.
4545
//
4646
// In addition the ResolverFunc is a wrapper for a func matching the signature
4747
// of Resolver.ResolveEndpoint, converting it to a type that satisfies the

aws/external/env_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ type EnvConfig struct {
130130
//
131131
// Setting a custom HTTPClient in the aws.Config options will override this setting.
132132
// To use this option and custom HTTP client, the HTTP client needs to be provided
133-
// when creating the session. Not the service client.
133+
// when creating the config. Not the service client.
134134
//
135135
// AWS_CA_BUNDLE=$HOME/my_custom_ca_bundle
136136
CustomCABundle string

aws/stscreds/provider.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ future AWS service API operation calls.
77
The SDK will ensure that per instance of credentials.Credentials all requests
88
to refresh the credentials will be synchronized. But, the SDK is unable to
99
ensure synchronous usage of the AssumeRoleProvider if the value is shared
10-
between multiple Credentials, Sessions or service clients.
10+
between multiple Credentials or service clients.
1111
1212
Assume Role
1313
@@ -17,15 +17,18 @@ with the SDKs's stscreds package.
1717
// Initial credentials loaded from SDK's default credential chain. Such as
1818
// the environment, shared credentials (~/.aws/credentials), or EC2 Instance
1919
// Role. These credentials will be used to to make the STS Assume Role API.
20-
sess := session.Must(session.NewSession())
20+
cfg, err := external.LoadDefaultAWSConfig()
2121
2222
// Create the credentials from AssumeRoleProvider to assume the role
2323
// referenced by the "myRoleARN" ARN.
24-
creds := stscreds.NewCredentials(sess, "myRoleArn")
24+
stsSvc := sts.New(cfg)
25+
stsCredProvider := stscreds.NewAssumeRoleProvider(stsSvc, "myRoleArn")
26+
27+
cfg.Credentials = aws.NewCredentials(stsCredProvider)
2528
2629
// Create service client value configured for credentials
2730
// from assumed role.
28-
svc := s3.New(sess, &aws.Config{Credentials: creds})
31+
svc := s3.New(cfg)
2932
3033
Assume Role with static MFA Token
3134

0 commit comments

Comments
 (0)