AWS Developer Tools Blog
Using AWS SDK for Go API Setters
In release v1.5.0 of the AWS SDK for Go, we added setters to all API operation parameters. Setters give you the ability to set API parameters without directly taking the value’s address. The setters wrap this functionality internally so you don’t have to. The setters are a convenient way to reduce the need to use aws.String and similar utilities.
The following code shows how you could use the Amazon S3 PutObject with the setters.
resp, err := svc.PutObject((&s3.PutObject{}).
SetBucket("myBucket").
SetKey("myKey").
SetBody(strings.NewReader("abc")).
SetWebsiteRedirectLocation("https://example.com/something"),
)
The following example uses Amazon ECS and nested setters to update a service’s deployment.
resp, err := svc.UpdateService((&ecs.UpdateServiceInput{}).
SetService("myService").
SetDeploymentConfiguration((&ecs.DeploymentConfiguration{}).
SetMinimumHealthyPrecent(80),
),
)
If you have additional suggestions or feedback on how to improve the SDK, send us your comments. We look forward to hearing from you.