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 tructure.
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
69 // AWS 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 request.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.
124 // @see http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html
125 // Amazon S3: Virtual Hosting of Buckets
126 S3ForcePathStyle *bool
128 // Set this to `true` to disable the SDK adding the `Expect: 100-Continue`
129 // header to PUT requests over 2MB of content. 100-Continue instructs the
130 // HTTP client not to send the body until the service responds with a
131 // `continue` status. This is useful to prevent sending the request body
132 // until after the request is authenticated, and validated.
134 // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
136 // 100-Continue is only enabled for Go 1.6 and above. See `http.Transport`'s
137 // `ExpectContinueTimeout` for information on adjusting the continue wait
138 // timeout. https://golang.org/pkg/net/http/#Transport
140 // You should use this flag to disble 100-Continue if you experience issues
141 // with proxies or third party S3 compatible services.
142 S3Disable100Continue *bool
144 // Set this to `true` to enable S3 Accelerate feature. For all operations
145 // compatible with S3 Accelerate will use the accelerate endpoint for
146 // requests. Requests not compatible will fall back to normal S3 requests.
148 // The bucket must be enable for accelerate to be used with S3 client with
149 // accelerate enabled. If the bucket is not enabled for accelerate an error
150 // will be returned. The bucket name must be DNS compatible to also work
152 S3UseAccelerate *bool
154 // Set this to `true` to disable the EC2Metadata client from overriding the
155 // default http.Client's Timeout. This is helpful if you do not want the
156 // EC2Metadata client to create a new http.Client. This options is only
157 // meaningful if you're not already using a custom HTTP client with the
158 // SDK. Enabled by default.
160 // Must be set and provided to the session.NewSession() in order to disable
161 // the EC2Metadata overriding the timeout for default credentials chain.
164 // sess := session.Must(session.NewSession(aws.NewConfig()
165 // .WithEC2MetadataDiableTimeoutOverride(true)))
167 // svc := s3.New(sess)
169 EC2MetadataDisableTimeoutOverride *bool
171 // Instructs the endpiont to be generated for a service client to
172 // be the dual stack endpoint. The dual stack endpoint will support
173 // both IPv4 and IPv6 addressing.
175 // Setting this for a service which does not support dual stack will fail
176 // to make requets. It is not recommended to set this value on the session
177 // as it will apply to all service clients created with the session. Even
178 // services which don't support dual stack endpoints.
180 // If the Endpoint config value is also provided the UseDualStack flag
183 // Only supported with.
185 // sess := session.Must(session.NewSession())
187 // svc := s3.New(sess, &aws.Config{
188 // UseDualStack: aws.Bool(true),
192 // SleepDelay is an override for the func the SDK will call when sleeping
193 // during the lifecycle of a request. Specifically this will be used for
194 // request delays. This value should only be used for testing. To adjust
195 // the delay of a request see the aws/client.DefaultRetryer and
196 // aws/request.Retryer.
198 // SleepDelay will prevent any Context from being used for canceling retry
199 // delay of an API operation. It is recommended to not use SleepDelay at all
200 // and specify a Retryer instead.
201 SleepDelay func(time.Duration)
203 // DisableRestProtocolURICleaning will not clean the URL path when making rest protocol requests.
204 // Will default to false. This would only be used for empty directory names in s3 requests.
207 // sess := session.Must(session.NewSession(&aws.Config{
208 // DisableRestProtocolURICleaning: aws.Bool(true),
211 // svc := s3.New(sess)
212 // out, err := svc.GetObject(&s3.GetObjectInput {
213 // Bucket: aws.String("bucketname"),
214 // Key: aws.String("//foo//bar//moo"),
216 DisableRestProtocolURICleaning *bool
219 // NewConfig returns a new Config pointer that can be chained with builder
220 // methods to set multiple configuration values inline without using pointers.
222 // // Create Session with MaxRetry configuration to be shared by multiple
223 // // service clients.
224 // sess := session.Must(session.NewSession(aws.NewConfig().
225 // WithMaxRetries(3),
228 // // Create S3 service client with a specific Region.
229 // svc := s3.New(sess, aws.NewConfig().
230 // WithRegion("us-west-2"),
232 func NewConfig() *Config {
236 // WithCredentialsChainVerboseErrors sets a config verbose errors boolean and returning
238 func (c *Config) WithCredentialsChainVerboseErrors(verboseErrs bool) *Config {
239 c.CredentialsChainVerboseErrors = &verboseErrs
243 // WithCredentials sets a config Credentials value returning a Config pointer
245 func (c *Config) WithCredentials(creds *credentials.Credentials) *Config {
246 c.Credentials = creds
250 // WithEndpoint sets a config Endpoint value returning a Config pointer for
252 func (c *Config) WithEndpoint(endpoint string) *Config {
253 c.Endpoint = &endpoint
257 // WithEndpointResolver sets a config EndpointResolver value returning a
258 // Config pointer for chaining.
259 func (c *Config) WithEndpointResolver(resolver endpoints.Resolver) *Config {
260 c.EndpointResolver = resolver
264 // WithRegion sets a config Region value returning a Config pointer for
266 func (c *Config) WithRegion(region string) *Config {
271 // WithDisableSSL sets a config DisableSSL value returning a Config pointer
273 func (c *Config) WithDisableSSL(disable bool) *Config {
274 c.DisableSSL = &disable
278 // WithHTTPClient sets a config HTTPClient value returning a Config pointer
280 func (c *Config) WithHTTPClient(client *http.Client) *Config {
281 c.HTTPClient = client
285 // WithMaxRetries sets a config MaxRetries value returning a Config pointer
287 func (c *Config) WithMaxRetries(max int) *Config {
292 // WithDisableParamValidation sets a config DisableParamValidation value
293 // returning a Config pointer for chaining.
294 func (c *Config) WithDisableParamValidation(disable bool) *Config {
295 c.DisableParamValidation = &disable
299 // WithDisableComputeChecksums sets a config DisableComputeChecksums value
300 // returning a Config pointer for chaining.
301 func (c *Config) WithDisableComputeChecksums(disable bool) *Config {
302 c.DisableComputeChecksums = &disable
306 // WithLogLevel sets a config LogLevel value returning a Config pointer for
308 func (c *Config) WithLogLevel(level LogLevelType) *Config {
313 // WithLogger sets a config Logger value returning a Config pointer for
315 func (c *Config) WithLogger(logger Logger) *Config {
320 // WithS3ForcePathStyle sets a config S3ForcePathStyle value returning a Config
321 // pointer for chaining.
322 func (c *Config) WithS3ForcePathStyle(force bool) *Config {
323 c.S3ForcePathStyle = &force
327 // WithS3Disable100Continue sets a config S3Disable100Continue value returning
328 // a Config pointer for chaining.
329 func (c *Config) WithS3Disable100Continue(disable bool) *Config {
330 c.S3Disable100Continue = &disable
334 // WithS3UseAccelerate sets a config S3UseAccelerate value returning a Config
335 // pointer for chaining.
336 func (c *Config) WithS3UseAccelerate(enable bool) *Config {
337 c.S3UseAccelerate = &enable
341 // WithUseDualStack sets a config UseDualStack value returning a Config
342 // pointer for chaining.
343 func (c *Config) WithUseDualStack(enable bool) *Config {
344 c.UseDualStack = &enable
348 // WithEC2MetadataDisableTimeoutOverride sets a config EC2MetadataDisableTimeoutOverride value
349 // returning a Config pointer for chaining.
350 func (c *Config) WithEC2MetadataDisableTimeoutOverride(enable bool) *Config {
351 c.EC2MetadataDisableTimeoutOverride = &enable
355 // WithSleepDelay overrides the function used to sleep while waiting for the
356 // next retry. Defaults to time.Sleep.
357 func (c *Config) WithSleepDelay(fn func(time.Duration)) *Config {
362 // MergeIn merges the passed in configs into the existing config object.
363 func (c *Config) MergeIn(cfgs ...*Config) {
364 for _, other := range cfgs {
365 mergeInConfig(c, other)
369 func mergeInConfig(dst *Config, other *Config) {
374 if other.CredentialsChainVerboseErrors != nil {
375 dst.CredentialsChainVerboseErrors = other.CredentialsChainVerboseErrors
378 if other.Credentials != nil {
379 dst.Credentials = other.Credentials
382 if other.Endpoint != nil {
383 dst.Endpoint = other.Endpoint
386 if other.EndpointResolver != nil {
387 dst.EndpointResolver = other.EndpointResolver
390 if other.Region != nil {
391 dst.Region = other.Region
394 if other.DisableSSL != nil {
395 dst.DisableSSL = other.DisableSSL
398 if other.HTTPClient != nil {
399 dst.HTTPClient = other.HTTPClient
402 if other.LogLevel != nil {
403 dst.LogLevel = other.LogLevel
406 if other.Logger != nil {
407 dst.Logger = other.Logger
410 if other.MaxRetries != nil {
411 dst.MaxRetries = other.MaxRetries
414 if other.Retryer != nil {
415 dst.Retryer = other.Retryer
418 if other.DisableParamValidation != nil {
419 dst.DisableParamValidation = other.DisableParamValidation
422 if other.DisableComputeChecksums != nil {
423 dst.DisableComputeChecksums = other.DisableComputeChecksums
426 if other.S3ForcePathStyle != nil {
427 dst.S3ForcePathStyle = other.S3ForcePathStyle
430 if other.S3Disable100Continue != nil {
431 dst.S3Disable100Continue = other.S3Disable100Continue
434 if other.S3UseAccelerate != nil {
435 dst.S3UseAccelerate = other.S3UseAccelerate
438 if other.UseDualStack != nil {
439 dst.UseDualStack = other.UseDualStack
442 if other.EC2MetadataDisableTimeoutOverride != nil {
443 dst.EC2MetadataDisableTimeoutOverride = other.EC2MetadataDisableTimeoutOverride
446 if other.SleepDelay != nil {
447 dst.SleepDelay = other.SleepDelay
450 if other.DisableRestProtocolURICleaning != nil {
451 dst.DisableRestProtocolURICleaning = other.DisableRestProtocolURICleaning
454 if other.EnforceShouldRetryCheck != nil {
455 dst.EnforceShouldRetryCheck = other.EnforceShouldRetryCheck
459 // Copy will return a shallow copy of the Config object. If any additional
460 // configurations are provided they will be merged into the new config returned.
461 func (c *Config) Copy(cfgs ...*Config) *Config {
465 for _, cfg := range cfgs {