AWS SDK for Go v2

repository·main·Indexed 25 days ago

https://github.com/aws/aws-sdk-go-v2

The official software development kit for interacting with Amazon Web Services from the Go programming language. Requires Go 1.24 or later. The SDK provides clients for AWS services, such as Amazon DynamoDB, and includes utilities for EventStream encoding/decoding and S3 downloader/uploader performance benchmarking.

Tokens
27.7K
Snippets
37
Records
233
Agent score
87%

What's inside aws-sdk-go-v2

  1. Install the AWS SDK for Go v2

    main

    To use the AWS SDK for Go v2, initialize your project with Go modules and retrieve the necessary dependencies using go get.

    Note: The v2 SDK requires a minimum version of Go 1.24.

    $ mkdir ~/helloaws
    $ cd ~/helloaws
    $ go mod init helloaws
    $ go get github.com/aws/aws-sdk-go-v2/aws
    $ go get github.com/aws/aws-sdk-go-v2/config
    $ go get github.com/aws/aws-sdk-go-v2/service/dynamodb
  2. Add a manual protocol test file

    main

    To supplement auto-generated protocol tests with hand-written Go source files, place your files in the manual/ directory. You must mirror the target path relative to internal/protocoltest/.

    For example, if you want a test file to be located at internal/protocoltest/jsonrpc10/my_test.go, you should place your file at:

    manual/jsonrpc10/my_test.go

    No changes to the build scripts are required, as the copyManualFiles task automatically copies the entire manual/ directory tree into the target destination, overlaying the generated output.

    manual/jsonrpc10/my_test.go
  3. Add manual files to Protocol Test Codegen

    main

    The protocol test generation process uses hand-written Go source files to supplement auto-generated tests with cases that cannot be expressed via Smithy protocol test traits. To add a manual file, you must mirror the target path relative to internal/protocoltest/ within the manual/ directory.

    For example, if you want a file to be located at internal/protocoltest/jsonrpc10/my_test.go, you must place it at: manual/jsonrpc10/my_test.go.

    No changes to the build scripts are required as the copyManualFiles task automatically copies the entire manual/ directory tree and overlays it onto the generated output.

    manual/jsonrpc10/my_test.go
  4. Run Protocol Test Codegen build

    main

    The protocol test generation build is driven by Gradle. To execute the full task chain—including Smithy build generation, SDK building, cleaning old tests, and copying both generated and manual files—run the following command from the parent directory:

    ./gradlew :protocol-test-codegen:build

    ./gradlew :protocol-test-codegen:build
  5. Run the S3 Downloader performance utility

    main

    The S3 downloader utility allows you to benchmark downloading a test file from an S3 bucket. It supports custom configurations for the HTTP client and the SDK's Download Manager behavior via command-line flags.

    Required environment variables:

    • AWS_REGION: The AWS region to use.
    • AWS_PROFILE: The AWS profile to use for credentials.

    Available flags:

    • -bucket: The S3 bucket name to download from.
    • -client.idle-conns: Sets the number of idle connections.
    • -client.idle-conns-host: Sets the number of idle connections per host.
    • -client.timeout.connect: Sets the connection timeout (e.g., 1s).
    • -client.timeout.response-header: Sets the response header timeout (e.g., 1s).
    • -test.bench: Filter for benchmarks.
    • -test.benchmem: Enable memory allocation statistics.
    • -test.benchtime: Set the benchmark duration (e.g., 1x).
    AWS_REGION=us-west-2 AWS_PROFILE=aws-go-sdk-team-test ./download.test \
    -test.bench=. \
    -test.benchmem \
    -test.benchtime 1x \
    -bucket aws-sdk-go-data \
    -client.idle-conns 1000 \
    -client.idle-conns-host 300 \
    -client.timeout.connect=1s \
    -client.timeout.response-header=1s
  6. Run the protocol test code generation build

    main

    The protocol test generation process is managed via Gradle. To execute the full build chain—which includes generating Smithy builds, producing Go client code, cleaning the target directory, and overlaying manual files—run the following command from the parent directory:

    ./gradlew :protocol-test-codegen:build

    This process ensures that internal/protocoltest/ is populated with both auto-generated protocol tests and any hand-written manual files provided in the manual/ directory.

  7. Paginate GetUsagePlanKeys results

    main

    Use NewGetUsagePlanKeysPaginator to iterate through all pages of usage plan keys. The paginator handles the Position token management automatically.

    Paginator Options

    • Limit: The maximum number of results per page (Default: 25, Max: 500).
    • StopOnDuplicateToken: If set to true, pagination stops if the service returns a token identical to the previous one.
  8. Paginate ListCodeSigningConfigs

    main

    Use the ListCodeSigningConfigsPaginator to automatically iterate through all pages of code signing configurations.

    To use the paginator:

    1. Call NewListCodeSigningConfigsPaginator with your client and input parameters.
    2. Use HasMorePages() to check if more results are available.
    3. Use NextPage(ctx) to retrieve the next batch of results.

    You can configure the paginator using ListCodeSigningConfigsPaginatorOptions:

    • Limit (int32): The maximum number of items to return per page.
    • StopOnDuplicateToken (bool): If true, pagination stops if the service returns a token that matches the most recent token provided.
  9. Initialize an AppConfigData Client

    main

    You can initialize an AppConfigData client in two ways:

    1. From an existing AWS Config: Use NewFromConfig to create a client using a pre-configured aws.Config object. This is the recommended approach for most applications.
    2. With custom options: Use New to provide a specific Options struct and additional functional options to configure behavior like custom endpoints, middleware, or retry logic.

    Note that Options() returns a copy of the client configuration to prevent accidental mutations of the client's internal state.