Skip to content

Commit

Permalink
Add Full Example to Getting Started (aws#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail authored Dec 16, 2020
1 parent 2516d8a commit b1bf7d1
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions content/en/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,44 @@ represents Amazon will ever ask you for your secret key. {{% /pageinfo %}}
* [AWS Security Credentials](https://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html)
in Amazon Web Services General Reference.

## Import Packages
## Invoke an Operation

After you have installed the SDK, you import AWS packages into your Go applications to use the SDK, as shown in the
following example, which imports the AWS, Config, and Amazon S3 libraries:
following example, which imports the AWS, Config, and Amazon S3 libraries. After importing the SDK packages, the
AWS SDK Shared Configuration is loaded, a client is constructed, and an API operation is invoked.

```go
package main

import (
"context"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
```

func main() {
// Load the Shared AWS Configuration (~/.aws/config)
config, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatal(err)
}

// Create an Amazon S3 service client
client := s3.NewFromConfig(config)

// Get the first page of results for ListObjectsV2 for a bucket
output, err := client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{
Bucket: aws.String("my-bucket"),
})
if err != nil {
log.Fatal(err)
}

log.Println("first page results:")
for _, object := range output.Contents {
log.Printf("key=%s size=%d", aws.ToString(object.Key), object.Size)
}
}
```

0 comments on commit b1bf7d1

Please sign in to comment.