Skip to content

AWS Emulator

Not available until the next release main

Introduction

The Testcontainers module for AWS Emulator, a local implementation of AWS APIs for development and integration tests. The module starts the emulator with HTTPS and request authentication enabled.

Adding this module to your project dependencies

Please run the following command to add the AWS Emulator module to your Go dependencies:

go get github.com/testcontainers/testcontainers-go/modules/aws

Usage example

ctx := context.Background()
container, err := aws.Run(ctx, "ghcr.io/xsavikx/aws-emulator:1.0.509.1-20261118.43", aws.WithDisableTelemetry())
defer func() {
    if err := testcontainers.TerminateContainer(container); err != nil {
        log.Printf("terminate AWS Emulator: %s", err)
    }
}()
if err != nil {
    log.Printf("start AWS Emulator: %s", err)
    return
}

Configuring the AWS SDK v2

Configure the SDK with the container's endpoint, generated credentials and TLS configuration. No host AWS credentials or configuration files are needed.

endpoint, err := container.EndpointURL(ctx)
require.NoError(t, err)
keys, err := container.Credentials(ctx)
require.NoError(t, err)
tlsConfig, err := container.TLSConfig(ctx)
require.NoError(t, err)
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.TLSClientConfig = tlsConfig
t.Cleanup(transport.CloseIdleConnections)
cfg := aws.Config{
    Region:       "us-east-1",
    BaseEndpoint: aws.String(endpoint),
    Credentials:  credentials.NewStaticCredentialsProvider(keys.AccessKeyID, keys.SecretAccessKey, ""),
    HTTPClient:   &http.Client{Transport: transport, Timeout: 30 * time.Second},
}

SDK dependencies and executable STS, S3 and SQS tests live in the separate modules/aws/examples Go module. S3 clients must use path-style addressing.

Module Reference

Run function

  • Not available until the next release main

The AWS Emulator module exposes one entrypoint function to create the AWS Emulator container, and this function receives three parameters:

func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
  • context.Context, the Go context.
  • string, the Docker image to use.
  • testcontainers.ContainerCustomizer, a variadic argument for passing options.

Image

Use the second argument in the Run function to set a valid Docker image. For example: Run(context.Background(), "ghcr.io/xsavikx/aws-emulator:1.0.509.1-20261118.43").

AWS does not currently publish an official AWS Emulator container image. The example uses a pinned build of the unofficial community image, available for Linux amd64 and arm64. You can substitute your own image with an aws-emulator entrypoint that supports the --bind, --port and --auth flags.

The module binds the emulator to 0.0.0.0:9297 inside the container and waits for its HTTPS health endpoint.

Container Options

When starting the AWS Emulator container, you can pass options in a variadic way to configure it.

WithDisableTelemetry

  • Not available until the next release main

aws.WithDisableTelemetry() disables AWS Emulator's usage telemetry by setting EMULATOR_TELEMETRY=off. The usage example includes this option.

The following options are exposed by the testcontainers package.

Basic Options

Lifecycle Options

Files & Mounts Options

Build Options

Logging Options

Image Options

Networking Options

Advanced Options

Experimental Options

Warning

Keep the module's container port (9297), HOME (/tmp/testcontainers-aws), and authentication settings when customizing the request. Its file helpers depend on those settings.

Container Methods

The AWS Emulator container exposes the following methods:

EndpointURL

  • Not available until the next release main

EndpointURL(ctx) returns the HTTPS API endpoint, including the dynamically mapped host port for container port 9297.

Credentials

  • Not available until the next release main

Credentials(ctx) returns a Credentials value containing the AccessKeyID and SecretAccessKey generated for this emulator instance. Use these keys to configure the SDK's credentials provider. They cannot authenticate to AWS.

CACertificate

  • Not available until the next release main

CACertificate(ctx) returns this instance's generated certificate in PEM format. Use it to configure certificate trust for clients outside Go.

TLSConfig

  • Not available until the next release main

TLSConfig(ctx) returns a *tls.Config that trusts this instance's certificate and verifies its localhost identity, including when dialing a remote Docker host. It does not disable certificate verification. The SDK example above uses this configuration with an HTTP client.

Limitations

The module exposes the shared AWS API endpoint. Services that return their own URLs or open extra resource listeners may advertise container-local addresses or unmapped ports. Those resource endpoints are not rewritten or exposed by this prototype. The SQS example uses the returned QueueUrl as an identifier while connecting through the configured SDK endpoint.

AWS API coverage and fidelity vary by service and release. Passing the example tests does not establish compatibility with every AWS service or behavior.