7 "github.com/aws/aws-sdk-go/aws/credentials"
8 "github.com/aws/aws-sdk-go/aws/endpoints"
11 // UseServiceDefaultRetries instructs the config to use the service's own
12 // default number of retries. This will be the default action if
13 // Config.MaxRetries is nil also.
14 const UseServiceDefaultRetries = -1
16 // RequestRetryer is an alias for a type that implements the request.Retryer
18 type RequestRetryer interface{}
20 // A Config provides service configuration for service clients. By default,
21 // all clients will use the defaults.DefaultConfig structure.
23 // // Create Session with MaxRetry configuration to be shared by multiple
24 // // service clients.
25 // sess := session.Must(session.NewSession(&aws.Config{
26 // MaxRetries: aws.Int(3),
29 // // Create S3 service client with a specific Region.
30 // svc := s3.New(sess, &aws.Config{
31 // Region: aws.String("us-west-2"),
34 // Enables verbose error printing of all credential chain errors.
35 // Should be used when wanting to see all errors while attempting to
36 // retrieve credentials.
37 CredentialsChainVerboseErrors *bool
39 // The credentials object to use when signing requests. Defaults to a
40 // chain of credential providers to search for credentials in environment
41 // variables, shared credential file, and EC2 Instance Roles.
42 Credentials *credentials.Credentials
44 // An optional endpoint URL (hostname only or fully qualified URI)
45 // that overrides the default generated endpoint for a client. Set this
46 // to `""` to use the default generated endpoint.
48 // Note: You must still provide a `Region` value when specifying an
49 // endpoint for a client.
52 // The resolver to use for looking up endpoints for AWS service clients
53 // to use based on region.
54 EndpointResolver endpoints.Resolver
56 // EnforceShouldRetryCheck is used in the AfterRetryHandler to always call
57 // ShouldRetry regardless of whether or not if request.Retryable is set.
58 // This will utilize ShouldRetry method of custom retryers. If EnforceShouldRetryCheck
59 // is not set, then ShouldRetry will only be called if request.Retryable is nil.
60 // Proper handling of the request.Retryable field is important when setting this field.
61 EnforceShouldRetryCheck *bool
63 // The region to send requests to. This parameter is required and must
64 // be configured globally or on a per-client basis unless otherwise
65 // noted. A full list of regions is found in the "Regions and Endpoints"
68 // See http://docs.aws.amazon.com/general/latest/gr/rande.html for AWS
69 // Regions and Endpoints.
72 // Set this to `true` to disable SSL when sending requests. Defaults
76 // The HTTP client to use when sending requests. Defaults to
77 // `http.DefaultClient`.
78 HTTPClient *http.Client
80 // An integer value representing the logging level. The default log level
81 // is zero (LogOff), which represents no logging. To enable logging set
82 // to a LogLevel Value.
83 LogLevel *LogLevelType
85 // The logger writer interface to write logging messages to. Defaults to
89 // The maximum number of times that a request will be retried for failures.
90 // Defaults to -1, which defers the max retry setting to the service
91 // specific configuration.
94 // Retryer guides how HTTP requests should be retried in case of
95 // recoverable failures.
97 // When nil or the value does not implement the request.Retryer interface,
98 // the client.DefaultRetryer will be used.
100 // When both Retryer and MaxRetries are non-nil, the former is used and
101 // the latter ignored.
103 // To set the Retryer field in a type-safe manner and with chaining, use
104 // the request.WithRetryer helper function:
106 // cfg := request.WithRetryer(aws.NewConfig(), myRetryer)
108 Retryer RequestRetryer
110 // Disables semantic parameter validation, which validates input for
111 // missing required fields and/or other semantic request input errors.
112 DisableParamValidation *bool
114 // Disables the computation of request and response checksums, e.g.,
115 // CRC32 checksums in Amazon DynamoDB.
116 DisableComputeChecksums *bool
118 // Set this to `true` to force the request to use path-style addressing,
119 // i.e., `http://s3.amazonaws.com/BUCKET/KEY`. By default, the S3 client
120 // will use virtual hosted bucket addressing when possible
121 // (`http://BUCKET.s3.amazonaws.com/KEY`).
123 // Note: This configuration option is specific to the Amazon S3 service.
125 // See http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html
126 // for Amazon S3: Virtual Hosting of Buckets
127 S3ForcePathStyle *bool
129 // Set this to `true` to disable the SDK adding the `Expect: 100-Continue`
130 // header to PUT requests over 2MB of content. 100-Continue instructs the
131 // HTTP client not to send the body until the service responds with a
132 // `continue` status. This is useful to prevent sending the request body
133 // until after the request is authenticated, and validated.
135 // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
137 // 100-Continue is only enabled for Go 1.6 and above. See `http.Transport`'s
138 // `ExpectContinueTimeout` for information on adjusting the continue wait
139 // timeout. https://golang.org/pkg/net/http/#Transport
141 // You should use this flag to disble 100-Continue if you experience issues
142 // with proxies or third party S3 compatible services.
143 S3Disable100Continue *bool
145 // Set this to `true` to enable S3 Accelerate feature. For all operations
146 // compatible with S3 Accelerate will use the accelerate endpoint for
147 // requests. Requests not compatible will fall back to normal S3 requests.
149 // The bucket must be enable for accelerate to be used with S3 client with
150 // accelerate enabled. If the bucket is not enabled for accelerate an error
151 // will be returned. The bucket name must be DNS compatible to also work
153 S3UseAccelerate *bool
155 // S3DisableContentMD5Validation config option is temporarily disabled,
156 // For S3 GetObject API calls, #1837.
158 // Set this to `true` to disable the S3 service client from automatically
159 // adding the ContentMD5 to S3 Object Put and Upload API calls. This option
160 // will also disable the SDK from performing object ContentMD5 validation
161 // on GetObject API calls.
162 S3DisableContentMD5Validation *bool
164 // Set this to `true` to disable the EC2Metadata client from overriding the
165 // default http.Client's Timeout. This is helpful if you do not want the
166 // EC2Metadata client to create a new http.Client. This options is only
167 // meaningful if you're not already using a custom HTTP client with the
168 // SDK. Enabled by default.
170 // Must be set and provided to the session.NewSession() in order to disable
171 // the EC2Metadata overriding the timeout for default credentials chain.
174 // sess := session.Must(session.NewSession(aws.NewConfig()
175 // .WithEC2MetadataDiableTimeoutOverride(true)))
177 // svc := s3.New(sess)
179 EC2MetadataDisableTimeoutOverride *bool
181 // Instructs the endpoint to be generated for a service client to
182 // be the dual stack endpoint. The dual stack endpoint will support
183 // both IPv4 and IPv6 addressing.
185 // Setting this for a service which does not support dual stack will fail
186 // to make requets. It is not recommended to set this value on the session
187 // as it will apply to all service clients created with the session. Even
188 // services which don't support dual stack endpoints.
190 // If the Endpoint config value is also provided the UseDualStack flag
193 // Only supported with.
195 // sess := session.Must(session.NewSession())
197 // svc := s3.New(sess, &aws.Config{
198 // UseDualStack: aws.Bool(true),
202 // SleepDelay is an override for the func the SDK will call when sleeping
203 // during the lifecycle of a request. Specifically this will be used for
204 // request delays. This value should only be used for testing. To adjust
205 // the delay of a request see the aws/client.DefaultRetryer and
206 // aws/request.Retryer.
208 // SleepDelay will prevent any Context from being used for canceling retry
209 // delay of an API operation. It is recommended to not use SleepDelay at all
210 // and specify a Retryer instead.
211 SleepDelay func(time.Duration)
213 // DisableRestProtocolURICleaning will not clean the URL path when making rest protocol requests.
214 // Will default to false. This would only be used for empty directory names in s3 requests.
217 // sess := session.Must(session.NewSession(&aws.Config{
218 // DisableRestProtocolURICleaning: aws.Bool(true),
221 // svc := s3.New(sess)
222 // out, err := svc.GetObject(&s3.GetObjectInput {
223 // Bucket: aws.String("bucketname"),
224 // Key: aws.String("//foo//bar//moo"),
226 DisableRestProtocolURICleaning *bool
228 // EnableEndpointDiscovery will allow for endpoint discovery on operations that
229 // have the definition in its model. By default, endpoint discovery is off.
232 // sess := session.Must(session.NewSession(&aws.Config{
233 // EnableEndpointDiscovery: aws.Bool(true),
236 // svc := s3.New(sess)
237 // out, err := svc.GetObject(&s3.GetObjectInput {
238 // Bucket: aws.String("bucketname"),
239 // Key: aws.String("/foo/bar/moo"),
241 EnableEndpointDiscovery *bool
243 // DisableEndpointHostPrefix will disable the SDK's behavior of prefixing
244 // request endpoint hosts with modeled information.
246 // Disabling this feature is useful when you want to use local endpoints
247 // for testing that do not support the modeled host prefix pattern.
248 DisableEndpointHostPrefix *bool
251 // NewConfig returns a new Config pointer that can be chained with builder
252 // methods to set multiple configuration values inline without using pointers.
254 // // Create Session with MaxRetry configuration to be shared by multiple
255 // // service clients.
256 // sess := session.Must(session.NewSession(aws.NewConfig().
257 // WithMaxRetries(3),
260 // // Create S3 service client with a specific Region.
261 // svc := s3.New(sess, aws.NewConfig().
262 // WithRegion("us-west-2"),
264 func NewConfig() *Config {
268 // WithCredentialsChainVerboseErrors sets a config verbose errors boolean and returning
270 func (c *Config) WithCredentialsChainVerboseErrors(verboseErrs bool) *Config {
271 c.CredentialsChainVerboseErrors = &verboseErrs
275 // WithCredentials sets a config Credentials value returning a Config pointer
277 func (c *Config) WithCredentials(creds *credentials.Credentials) *Config {
278 c.Credentials = creds
282 // WithEndpoint sets a config Endpoint value returning a Config pointer for
284 func (c *Config) WithEndpoint(endpoint string) *Config {
285 c.Endpoint = &endpoint
289 // WithEndpointResolver sets a config EndpointResolver value returning a
290 // Config pointer for chaining.
291 func (c *Config) WithEndpointResolver(resolver endpoints.Resolver) *Config {
292 c.EndpointResolver = resolver
296 // WithRegion sets a config Region value returning a Config pointer for
298 func (c *Config) WithRegion(region string) *Config {
303 // WithDisableSSL sets a config DisableSSL value returning a Config pointer
305 func (c *Config) WithDisableSSL(disable bool) *Config {
306 c.DisableSSL = &disable
310 // WithHTTPClient sets a config HTTPClient value returning a Config pointer
312 func (c *Config) WithHTTPClient(client *http.Client) *Config {
313 c.HTTPClient = client
317 // WithMaxRetries sets a config MaxRetries value returning a Config pointer
319 func (c *Config) WithMaxRetries(max int) *Config {
324 // WithDisableParamValidation sets a config DisableParamValidation value
325 // returning a Config pointer for chaining.
326 func (c *Config) WithDisableParamValidation(disable bool) *Config {
327 c.DisableParamValidation = &disable
331 // WithDisableComputeChecksums sets a config DisableComputeChecksums value
332 // returning a Config pointer for chaining.
333 func (c *Config) WithDisableComputeChecksums(disable bool) *Config {
334 c.DisableComputeChecksums = &disable
338 // WithLogLevel sets a config LogLevel value returning a Config pointer for
340 func (c *Config) WithLogLevel(level LogLevelType) *Config {
345 // WithLogger sets a config Logger value returning a Config pointer for
347 func (c *Config) WithLogger(logger Logger) *Config {
352 // WithS3ForcePathStyle sets a config S3ForcePathStyle value returning a Config
353 // pointer for chaining.
354 func (c *Config) WithS3ForcePathStyle(force bool) *Config {
355 c.S3ForcePathStyle = &force
359 // WithS3Disable100Continue sets a config S3Disable100Continue value returning
360 // a Config pointer for chaining.
361 func (c *Config) WithS3Disable100Continue(disable bool) *Config {
362 c.S3Disable100Continue = &disable
366 // WithS3UseAccelerate sets a config S3UseAccelerate value returning a Config
367 // pointer for chaining.
368 func (c *Config) WithS3UseAccelerate(enable bool) *Config {
369 c.S3UseAccelerate = &enable
374 // WithS3DisableContentMD5Validation sets a config
375 // S3DisableContentMD5Validation value returning a Config pointer for chaining.
376 func (c *Config) WithS3DisableContentMD5Validation(enable bool) *Config {
377 c.S3DisableContentMD5Validation = &enable
382 // WithUseDualStack sets a config UseDualStack value returning a Config
383 // pointer for chaining.
384 func (c *Config) WithUseDualStack(enable bool) *Config {
385 c.UseDualStack = &enable
389 // WithEC2MetadataDisableTimeoutOverride sets a config EC2MetadataDisableTimeoutOverride value
390 // returning a Config pointer for chaining.
391 func (c *Config) WithEC2MetadataDisableTimeoutOverride(enable bool) *Config {
392 c.EC2MetadataDisableTimeoutOverride = &enable
396 // WithSleepDelay overrides the function used to sleep while waiting for the
397 // next retry. Defaults to time.Sleep.
398 func (c *Config) WithSleepDelay(fn func(time.Duration)) *Config {
403 // WithEndpointDiscovery will set whether or not to use endpoint discovery.
404 func (c *Config) WithEndpointDiscovery(t bool) *Config {
405 c.EnableEndpointDiscovery = &t
409 // WithDisableEndpointHostPrefix will set whether or not to use modeled host prefix
410 // when making requests.
411 func (c *Config) WithDisableEndpointHostPrefix(t bool) *Config {
412 c.DisableEndpointHostPrefix = &t
416 // MergeIn merges the passed in configs into the existing config object.
417 func (c *Config) MergeIn(cfgs ...*Config) {
418 for _, other := range cfgs {
419 mergeInConfig(c, other)
423 func mergeInConfig(dst *Config, other *Config) {
428 if other.CredentialsChainVerboseErrors != nil {
429 dst.CredentialsChainVerboseErrors = other.CredentialsChainVerboseErrors
432 if other.Credentials != nil {
433 dst.Credentials = other.Credentials
436 if other.Endpoint != nil {
437 dst.Endpoint = other.Endpoint
440 if other.EndpointResolver != nil {
441 dst.EndpointResolver = other.EndpointResolver
444 if other.Region != nil {
445 dst.Region = other.Region
448 if other.DisableSSL != nil {
449 dst.DisableSSL = other.DisableSSL
452 if other.HTTPClient != nil {
453 dst.HTTPClient = other.HTTPClient
456 if other.LogLevel != nil {
457 dst.LogLevel = other.LogLevel
460 if other.Logger != nil {
461 dst.Logger = other.Logger
464 if other.MaxRetries != nil {
465 dst.MaxRetries = other.MaxRetries
468 if other.Retryer != nil {
469 dst.Retryer = other.Retryer
472 if other.DisableParamValidation != nil {
473 dst.DisableParamValidation = other.DisableParamValidation
476 if other.DisableComputeChecksums != nil {
477 dst.DisableComputeChecksums = other.DisableComputeChecksums
480 if other.S3ForcePathStyle != nil {
481 dst.S3ForcePathStyle = other.S3ForcePathStyle
484 if other.S3Disable100Continue != nil {
485 dst.S3Disable100Continue = other.S3Disable100Continue
488 if other.S3UseAccelerate != nil {
489 dst.S3UseAccelerate = other.S3UseAccelerate
492 if other.S3DisableContentMD5Validation != nil {
493 dst.S3DisableContentMD5Validation = other.S3DisableContentMD5Validation
496 if other.UseDualStack != nil {
497 dst.UseDualStack = other.UseDualStack
500 if other.EC2MetadataDisableTimeoutOverride != nil {
501 dst.EC2MetadataDisableTimeoutOverride = other.EC2MetadataDisableTimeoutOverride
504 if other.SleepDelay != nil {
505 dst.SleepDelay = other.SleepDelay
508 if other.DisableRestProtocolURICleaning != nil {
509 dst.DisableRestProtocolURICleaning = other.DisableRestProtocolURICleaning
512 if other.EnforceShouldRetryCheck != nil {
513 dst.EnforceShouldRetryCheck = other.EnforceShouldRetryCheck
516 if other.EnableEndpointDiscovery != nil {
517 dst.EnableEndpointDiscovery = other.EnableEndpointDiscovery
520 if other.DisableEndpointHostPrefix != nil {
521 dst.DisableEndpointHostPrefix = other.DisableEndpointHostPrefix
525 // Copy will return a shallow copy of the Config object. If any additional
526 // configurations are provided they will be merged into the new config returned.
527 func (c *Config) Copy(cfgs ...*Config) *Config {
531 for _, cfg := range cfgs {