-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update SDK to use Session when initializing service clients #410
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jasdel
force-pushed
the
sessionRefactor
branch
4 times, most recently
from
October 29, 2015 00:02
cc2f2dc
to
aaa546b
Compare
Updates SDK to use `session.Session` when initializing service clients. Service clients now require a session, which contains the SDK defaults and any additional configurations you've provided. This also allows you to create a default set of request handlers for all service clients created with a session. Enabling you to share configurations explicitly. Migrating to this change you'll need to add a `session.Session` to your application. The session will be used in each place a service client is created. Naively this can be `s3.New(session.New())` instead of the previous `s3.New(nil)`. If the `aws.Config` value was being passed in to the service client the code would become, `s3.New(session.New(), cfg)`. If you used `default.DefaultConfig` you can replace this logic with a new session and set merge in the config which was beign set to the global default value. Like `session.New(myCfg)` or: ```go sess := session.New() sess.Config.LogLevel = aws.LogLevel(aws.Debug) ``` Examples: ```go // Create a session with the default config and request handlers. sess := session.New() // Create a session with a custom region sess := session.New(&aws.Config{Region: aws.String("us-east-1")}) // Create a session, and add additional handlers for all service // clients created with the session to inherit. sess := session.New() sess.Handlers.Build.pushBack(func(r *request.Handlers) { // Log every request made and its payload logger.Println("Request: %s/%s, Payload: %s", r.ClientInfo.ServiceName, r.Operation, r.Params) }) // Create a S3 client instance from a session sess := session.New() svc := s3.New(sess) // Create a S3 client with additional configuration svc := s3.New(sess, aws.NewConfig().WithRegion("us-west-2")) ``` In addition to this change there were a few other changes in this update. * aws/service:Service was renamed to aws/client:Client. * aws/service/serviceinfo:ServiceInfo was renamed to aws/client/metadata:ClientInfo * aws:DefaultRetries was renamed to aws:UseServiceDefaultRetries * aws/ec2metadata now takes a session and aws.Config like all other service clients * aws/credentails/ec2rolecreds:EC2RoleProvider now requires an ec2metadata.EC2Metadata and will not default to creating one. * service/s3/s3manager:Downloader now requires a S3 service client instance, and also takes functional options for setting the Downloader's options. * service/s3/s3manager:Uploader now requires a S3 service client instance, and also takes functional options for setting the Uploader's options.
jasdel
force-pushed
the
sessionRefactor
branch
from
October 29, 2015 22:36
aaa546b
to
206e65e
Compare
Released this change in tag v0.10.0 |
skotambkar
pushed a commit
to skotambkar/aws-sdk-go
that referenced
this pull request
May 20, 2021
Breaking Change --- * `service`: Add generated service for wafregional and dynamodbstreams aws#463 * Updates the wafregional and dynamodbstreams API clients to include all API operations, and types that were previously shared between waf and dynamodb API clients respectively. This update ensures that all API clients include all operations and types needed for that client, and shares no types with another client package. * To migrate your applications to use the updated wafregional and dynamodbstreams you'll need to update the package the impacted type is imported from to match the client the type is being used with. * `aws`: Context has been added to EC2Metadata operations.([aws#461](aws/aws-sdk-go-v2#461)) * Also updates utilities that directly or indirectly depend on EC2Metadata client. Signer utilities, credential providers now take in context. * `private/model`: Add utility for validating shape names for structs and enums for the service packages ([aws#471](aws/aws-sdk-go-v2#471)) * Fixes bug which allowed service package structs, enums to start with non alphabetic character * Fixes the incorrect enum types in mediapackage service package, changing enum types __AdTriggersElement, __PeriodTriggersElement to AdTriggersElement, PeriodTriggersElement respectively. * `aws`: Client, Metadata, and Request structures have been refactored to simplify the usage of resolved endpoints ([aws#473](aws/aws-sdk-go-v2#473)) * `aws.Client.Endpoint` struct member has been removed, and `aws.Request.Endpoint` struct member has been added of type `aws.Endpoint` * `aws.Client.Region` structure member has been removed Services --- * Synced the V2 SDK with latest AWS service API definitions. SDK Features --- * `aws`: `PartitionID` has been added to `aws.Endpoint` structure, and is used by the endpoint resolver to indicate which AWS partition an endpoint was resolved for ([aws#473](aws/aws-sdk-go-v2#473)) * `aws/endpoints`: Updated resolvers to populate `PartitionID` for a resolved `aws.Endpoint` ([aws#473](aws/aws-sdk-go-v2#473)) * `service/s3`: Add support for Access Point resources * Adds support for using Access Point resource with Amazon S3 API operation calls. The Access Point resource are identified by an Amazon Resource Name (ARN). * To make operation calls to an S3 Access Point instead of a S3 Bucket, provide the Access Point ARN string as the value of the Bucket parameter. You can create an Access Point for your bucket with the Amazon S3 Control API. The Access Point ARN can be obtained from the S3 Control API. You should avoid building the ARN directly. SDK Enhancements --- * `internal/sdkio`: Adds RingBuffer data structure to the sdk [aws#417](aws/aws-sdk-go-v2#417) * Adds an implementation of RingBuffer data structure which acts as a revolving buffer of a predefined length. The RingBuffer implements io.ReadWriter interface. * Adds unit tests to test the behavior of the ring buffer. * `aws/ec2metadata`: Adds support for EC2Metadata client to use secure tokens provided by the IMDS ([aws#453](aws/aws-sdk-go-v2#453)) * Modifies EC2Metadata client to use request context within its operations ([aws#462](aws/aws-sdk-go-v2#462)) * Reduces the default dialer timeout and response header timeout to help reduce latency for known issues with EC2Metadata client running inside a container * Modifies and adds tests to verify the behavior of the EC2Metadata client. * `service/dynamodb/dynamodbattribute`: Adds clarifying docs on dynamodbattribute.UnixTime ([aws#464](aws/aws-sdk-go-v2#464)) * `example/service/sts/assumeRole`: added sts assume role example ([aws#224](aws/aws-sdk-go-v2#224)) * Fixes [aws#157](aws/aws-sdk-go-v2#157) by adding an example for Amazon STS assume role to retrieve credentials. SDK Bugs --- * `service/dynamodb/dynamodbattribute`: Fixes a panic when decoding into a map with a key string type alias. ([aws#465](aws/aws-sdk-go-v2#465)) * Fixes [aws#410](aws/aws-sdk-go-v2#410), by adding support for keys that are string aliases.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change updates the way the SDK service clients are created.
Instead of taking an optional aws.Config pointer value the SDK now
requires a Session to be provided to the service clients when creating
instances. This session takes over for the global
defaults.DefaultConfig
. Instead of being a global value the defaultsvalues are collected and set to a Session when
session.New()
is called.To migrate to this change you'll need to add a session value to each
place a service client is created. Naively this can be just
s3.New(session.New())
in place ofs3.New(nil)
. If aws.Config valuewas passed in your code would become,
s3.New(session.New(), cfg)
. Ifyou used
default.DefaultConfig
you can create a new session, set theconfig you used on the default config like
session.New(myCfg)
orsess.New(); sess.Config.LogLevel = aws.LogLevel(aws.Debug)
.Examples:
In addition to this change there were a few other changes in this update.