Back to Blog
    8 min read

    Test Terraform Modules Against AWS Emulator Before You Plan in us-east-1

    Hardik Shah
    Hardik ShahCloud Architect & AWS Expert
    TerraformAWS EmulatorInfrastructure as CodeAWSCI/CDTestingDevOps
    Test Terraform Modules Against AWS Emulator Before You Plan in us-east-1

    Test Terraform modules against AWS Emulator first because a local apply catches typos, wrong attribute names and ordering bugs in about a minute, with no AWS account. I ran a 28-resource module through it. Provider 5.x applied everything. Provider 6.x hung on an S3 bucket for five minutes, and the reason is worth knowing before you wire this into CI.

    The loop a sandbox account forces on you

    Every Terraform change I review goes through the same loop. Write the module, run plan against a sandbox account, wait for credentials, apply, find the typo in a policy, destroy, repeat. The sandbox costs money, needs an SSO session, and is shared with three other people who also forgot to destroy their stacks.

    In November 2026 AWS released AWS Emulator, a free local server for the public APIs of more than 200 services. I pointed a real module at it to see how much of that loop it can take over. Every number below comes from that run: emulator 1.0.610 in Docker on an arm64 Mac, Terraform 1.17.2, AWS provider 5.100.0 and 6.74.0.

    What is AWS Emulator?

    AWS Emulator is an open-source server from AWS that answers AWS API calls on your own machine. It is written in Rust, generated from the Smithy models the SDKs use, and keeps all state in memory. The AWS CLI, any SDK and Terraform talk to it by changing the endpoint, with no AWS account.

    On Linux it installs as an RPM or Debian package. On a Mac there is no prebuilt image, so you build one from the short Dockerfile in the user guide, using the aarch64 RPM on Apple silicon.

    bash
    docker build -t aws-emulator .
    mkdir -p ~/.aws/emulator
    PORT=9297
    docker run --rm --memory=2g --memory-swap=2g -p 127.0.0.1:$PORT:$PORT \
      -e HOME="$HOME" -v "$HOME/.aws/emulator:$HOME/.aws/emulator" \
      aws-emulator -p $PORT --telemetry off

    It serves HTTPS on 127.0.0.1:9297 with a self-signed certificate. On each start it writes a fresh key pair, a CA bundle and a config file to ~/.aws/emulator/9297/, and keys from an earlier run stop working. Telemetry is on by default, which is why the flag is there. With my 28-resource stack loaded, the container used 216 MiB.

    How do you point Terraform at it?

    Export the endpoint, credentials, config and CA bundle the emulator generates, and keep the provider block down to a Region. Provider 5.x reads all of it from the environment. Use 127.0.0.1, never localhost, or some SDKs put the bucket name in the host and miss the emulator entirely.

    bash
    unset AWS_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
    export AWS_ENDPOINT_URL=https://127.0.0.1:9297
    export AWS_SHARED_CREDENTIALS_FILE=~/.aws/emulator/9297/emulator_credentials
    export AWS_CONFIG_FILE=~/.aws/emulator/9297/config
    export AWS_CA_BUNDLE=~/.aws/emulator/9297/ca.pem
    export AWS_EC2_METADATA_DISABLED=true
    export AWS_REGION=us-east-1
    hcl
    terraform {
      required_providers {
        aws = { source = "hashicorp/aws", version = "~> 5.0" }
      }
    }
    
    provider "aws" {
      region = "us-east-1"
    }

    That provider file is the same one the module uses against a real account. Only the shell changes. Check the shell before every apply:

    bash
    aws sts get-caller-identity
    # "Account": "000000000000"
    # "Arn": "arn:aws:iam::000000000000:user/emulator"

    If that prints your real account ID, stop. Something still has your profile or session keys set, and the next apply goes to AWS.

    Which resources applied cleanly?

    All 28 resources in my test module applied on provider 5.100.0, and a second terraform plan showed no changes. The apply took 54 seconds, the replan 4 seconds and the destroy 9 seconds. Most of the apply time was the provider waiting about 25 seconds on each SQS queue, as it does against real AWS.

    The module is the one most of my client stacks start from:

    AreaResources
    NetworkVPC, 3 private subnets in us-east-1a, us-east-1b and us-east-1c, internet gateway, route table and 3 associations, security group, Elastic IP, NAT gateway, S3 gateway endpoint, VPC flow log
    StorageS3 bucket with versioning, AES256 encryption and a public access block, DynamoDB table with point-in-time recovery
    MessagingSQS queue with a dead-letter queue, SNS topic encrypted with a KMS key
    OtherKMS key with rotation, CloudWatch log group, ECR repository with scan on push, 2 IAM roles and an inline policy

    The replan is the step that matters. When plan shows changes straight after an apply, the emulator stored something different from what it accepted. That is a fidelity gap, and it means you cannot trust that resource in a local test. I got zero, which surprised me.

    Why did provider 6.x hang on the S3 bucket?

    Provider 6.74.0 reads S3 bucket tags through the S3 Control ListTagsForResource API. S3 Control puts the account ID in the hostname, which the emulator cannot serve. Without an s3control endpoint, the provider sent those calls to the real AWS host and retried for over five minutes.

    The debug log showed the request going to 000000000000.s3-control.us-east-1.amazonaws.com, signed with the emulator's throwaway key. AWS rejected it and the provider kept retrying. Adding an s3control endpoint made it fail fast instead:

    bash
    Error: listing tags for S3 (Simple Storage) Bucket (hs-emu-test-artifacts):
    operation error S3 Control: ListTagsForResource, ...
    dial tcp: lookup 000000000000.127.0.0.1: no such host

    The user guide lists S3 Control as a gap the emulator cannot fix. Two lessons. Pin provider 5.x for emulator runs until that path works. And an emulator run can still send requests to real AWS hostnames when the provider calls a service you did not route, so set a CI timeout well under five minutes.

    What returns HTTP 501?

    Operations AWS has scaffolded but not built answer with HTTP 501 and the error code NotImplemented. Most read and list calls I tried for EKS, RDS, ECS, Lambda, ELB, CloudFront, Route 53, GuardDuty, CloudTrail, ACM and WAF worked. Cost Explorer and AWS RAM did not.

    bash
    $ aws ram list-resources --resource-owner SELF
    An error occurred (NotImplemented) when calling the ListResources operation:
    operation ListResources is scaffolded but not implemented in this emulator

    aws ce get-cost-and-usage returned the same error. A module that shares subnets through RAM fails on the emulator, so keep that part in its own stack. Anything that reads Cost Explorer has to be tested against a real account.

    What can it not tell you?

    Anything about permissions. The emulator does not evaluate IAM policies, bucket policies or KMS key policies the way AWS does, and the user guide says not to use it to test security. A module that applies locally can still fail with AccessDenied in your own account.

    • One account and one Region per process. A module that deploys to two Regions needs two emulators on two ports.
    • AWS verified it in us-west-2, with global services in us-east-1. A us-east-1 plan runs, but differences in what each Region offers are not modelled.
    • State lives in memory. Stopping the container deletes everything. That suits CI and rules it out for a long-lived dev stack.
    • AWS publishes a fidelity score per service with each release. One developer counted about two in three tests passing for S3, DynamoDB and SQS, and under one in five for CloudFormation. Check the release notes for the version you pin.

    Where does it replace a sandbox account?

    It replaces the sandbox for the early applies of a new module: typos, wrong attribute names, missing dependencies and ordering problems. My 28-resource module went through apply, replan and destroy in about a minute with no account at all. Permissions, quotas and Region limits still need the real account.

    The CI job I am moving to runs in this order. A pull request starts the emulator, applies the module, runs a second plan with -detailed-exitcode, and fails on any NotImplemented, any drift, or any step over three minutes. Only after that passes does it assume a role in the sandbox account for a real plan. The sandbox is still there. It just sees fewer broken modules.

    Hardik Shah

    About Hardik Shah

    Hardik ran every command in this post against AWS Emulator 1.0.610 on his own machine before writing it. He still keeps a sandbox account, he just sends it fewer broken modules.