When developing applications that use AWS services, testing them against the actual AWS cloud is not always necessary. Sometimes, you just want to experiment, test your code, or understand how a particular AWS service works without creating real cloud resources.
This is where AWS Emulator comes in.
AWS Emulator allows you to run and test supported AWS APIs locally. You can use familiar tools such as the AWS CLI and AWS SDKs without connecting to an actual AWS account.
In this article, we will set up AWS Emulator using Docker and explore some practical examples using Amazon S3, DynamoDB, and SQS.
By the end of this article, you should have a working local environment where you can create buckets, store data, and send messages between services.
What is AWS Emulator
AWS Emulator is a local implementation of AWS APIs. It allows developers to interact with supported AWS services without sending requests to the actual AWS cloud.
For example, imagine you are developing an application that uses Amazon S3 to store uploaded files. Normally, you would need to create an S3 bucket in your AWS account before testing the integration.
With AWS Emulator, you can create that bucket locally and test the same AWS CLI commands or application code.
A few things worth knowing:
- You don't need an AWS account.
- You don't need real AWS credentials.
- You don't pay an additional AWS Emulator service fee.
- Your resources are created locally and never reach your AWS account.
- It works with the AWS CLI and AWS SDKs.
One important thing to understand is that AWS Emulator is not a graphical interface. You interact with it through the same tools you would normally use when working with AWS.
How does it work?
Before getting started, let's understand what we are going to build.
AWS Emulator runs inside a Docker container and exposes a local HTTPS endpoint. We configure the AWS CLI to communicate with this endpoint instead of the actual AWS cloud.
Here is a simple overview:
The important part is that the AWS CLI does not know whether it is communicating with the actual AWS cloud or a local emulator. It uses the same AWS API commands, but we change the endpoint to point to our local environment.
Let's build it.
Prerequisites
Before starting, make sure you have the following installed:
- Docker: To build and run AWS Emulator.
- AWS CLI: To interact with the emulator.
You don't need an AWS account.
If you haven't installed Docker yet, follow the official Docker installation guide.
You can verify your installations by running:
docker --version
aws --version
Build the AWS Emulator Docker image
AWS doesn't provide a prebuilt Docker image for AWS Emulator. Instead, we need to build one using a Dockerfile.
First, create a directory for the project:
mkdir aws-emulator
cd aws-emulator
Inside this directory, create a file named Dockerfile and add the following content:
FROM public.ecr.aws/amazonlinux/amazonlinux:2023-minimal
ADD https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/latest/aws-emulator-x86_64.rpm /tmp/aws-emulator.rpm
RUN rpm -i /tmp/aws-emulator.rpm && rm /tmp/aws-emulator.rpm \
&& mkdir -p /home/emulator && chown 1000 /home/emulator
USER 1000
ENV HOME=/home/emulator EMULATOR_BIND_ADDRESS=0.0.0.0
ENTRYPOINT ["aws-emulator"]
A few things are happening here:
-
FROM: Uses Amazon Linux 2023 as the base image. -
ADD: Downloads the AWS Emulator Linux package. -
RUN: Installs the package and creates the emulator's home directory. -
USER: Runs the emulator as a non-root user. -
ENV: Configures the home directory and allows the emulator to listen on all interfaces inside the container. -
ENTRYPOINT: Defines the command that starts AWS Emulator.
Note: If you are using a Mac with Apple Silicon (M1, M2, M3, M4, etc.) or another ARM-based processor, replace aws-emulator-x86_64.rpm with aws-emulator-aarch64.rpm in the Dockerfile.
Now let's build the image:
docker build -t aws-emulator .
This command builds the Docker image and names it aws-emulator.
To verify that the image was created successfully:
docker images
You should see aws-emulator in the list.
Start AWS Emulator using Docker
Now that we have our Docker image, let's start the emulator.
First, create a directory on your machine where AWS Emulator will store its configuration files and certificates.
On macOS and Linux:
mkdir -p ~/.aws/emulator
On Windows PowerShell:
New-Item -ItemType Directory -Force "$env:USERPROFILE\.aws\emulator"
Next, start the container.
For macOS and Linux:
docker run --rm --memory=2g --memory-swap=2g \
-p 127.0.0.1:9297:9297 \
-e HOME="$HOME" \
-v "$HOME/.aws/emulator:$HOME/.aws/emulator" \
aws-emulator -p 9297
For Windows PowerShell:
docker run --rm --memory=2g --memory-swap=2g `
-p "127.0.0.1:9297:9297" `
-v "$env:USERPROFILE\.aws\emulator:/home/emulator/.aws/emulator" `
aws-emulator -p 9297
Let's understand some of the important options:
-
--rm: Removes the container when it stops. -
--memory=2g: Limits the container to 2 GB of memory. -
--memory-swap=2g: Prevents the container from using additional swap memory. -
-p: Maps the emulator's port to your local machine. -
-v: Mounts a directory from your machine into the container. -
-e HOME: Sets the home directory used by the emulator.
We are using port 9297 to communicate with AWS Emulator.
Notice that we bind the port to 127.0.0.1. This ensures that the emulator is accessible only from your local machine.
Important: Keep this terminal running. The emulator needs to remain active while we execute the examples.
On Linux, also add --user "$(id -u):$(id -g)" immediately after docker run to ensure that files created by the container belong to your current user.
Configure AWS CLI to communicate with AWS Emulator
At this point, AWS Emulator is running, but our AWS CLI still needs to know where to send its requests.
By default, AWS CLI communicates with actual AWS endpoints. We need to change this behavior by setting a few environment variables.
Open another terminal window.
For macOS and Linux:
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_DISABLE_HOST_PREFIX_INJECTION=true
export AWS_REGION=us-east-1
export AWS_DEFAULT_REGION=us-east-1
For Windows PowerShell:
$env:AWS_ENDPOINT_URL = "https://127.0.0.1:9297"
$env:AWS_SHARED_CREDENTIALS_FILE = "$env:USERPROFILE\.aws\emulator\9297\emulator_credentials"
$env:AWS_CONFIG_FILE = "$env:USERPROFILE\.aws\emulator\9297\config"
$env:AWS_CA_BUNDLE = "$env:USERPROFILE\.aws\emulator\9297\ca.pem"
$env:AWS_EC2_METADATA_DISABLED = "true"
$env:AWS_DISABLE_HOST_PREFIX_INJECTION = "true"
$env:AWS_REGION = "us-east-1"
$env:AWS_DEFAULT_REGION = "us-east-1"
Let's briefly understand what these variables do:
-
AWS_ENDPOINT_URL: Tells AWS CLI to send requests to our local emulator. -
AWS_SHARED_CREDENTIALS_FILE: Points to the credentials generated by the emulator. -
AWS_CONFIG_FILE: Points to the emulator configuration. -
AWS_CA_BUNDLE: Tells AWS CLI to trust the emulator's HTTPS certificate. -
AWS_EC2_METADATA_DISABLED: Prevents the SDK from looking for credentials through EC2 instance metadata. -
AWS_DISABLE_HOST_PREFIX_INJECTION: Prevents AWS CLI from adding prefixes to certain endpoint hostnames. -
AWS_REGION and AWS_DEFAULT_REGION: Define the AWS Region used for requests.
One interesting detail is that AWS Emulator automatically generates its own credentials and certificates when it starts. We don't need to create access keys manually.
Important: If you already have AWS credentials configured through environment variables, unset them before testing.
On macOS and Linux:
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_PROFILE
On Windows PowerShell:
Remove-Item Env:AWS_ACCESS_KEY_ID, Env:AWS_SECRET_ACCESS_KEY, Env:AWS_SESSION_TOKEN, Env:AWS_PROFILE -ErrorAction SilentlyContinue
This helps prevent your requests from being signed with real AWS credentials.
Verify that AWS Emulator is running
Before creating any resources, let's make sure our setup is working correctly.
First, check the emulator's health:
curl --cacert ~/.aws/emulator/9297/ca.pem \
https://127.0.0.1:9297/__admin/health
If everything is working correctly, you should receive:
ok
Next, let's verify that AWS CLI is communicating with the emulator:
aws sts get-caller-identity
You should receive a response similar to:
{
"UserId": "emulator",
"Account": "000000000000",
"Arn": "arn:aws:iam::000000000000:user/emulator"
}
Notice the account ID: 000000000000.
This is the local account ID used by AWS Emulator.
If you see your actual AWS account ID, your requests are going to AWS instead of the emulator. Check your environment variables before continuing.
Great! We now have a working local AWS environment.
But what can we actually do with it?
Let's explore some examples.
Working with Amazon S3
Amazon S3 is an object storage service that allows you to store and retrieve files.
Let's create an S3 bucket locally and upload a file to it.
First, create a bucket:
aws s3api create-bucket \
--bucket my-local-bucket
You should receive a response similar to:
{
"Location": "/my-local-bucket"
}
Now let's list our buckets:
aws s3api list-buckets \
--query 'Buckets[].Name'
Expected output:
[
"my-local-bucket"
]
Our bucket has been created successfully.
Upload a file to S3
Let's create a simple text file:
echo "Hello from AWS Emulator!" > hello.txt
Upload it to our bucket:
aws s3 cp hello.txt s3://my-local-bucket/
To verify that the file was uploaded, list the objects inside the bucket:
aws s3 ls s3://my-local-bucket/
You should see hello.txt in the output.
We can also download the file:
aws s3 cp s3://my-local-bucket/hello.txt downloaded.txt
Finally, read its content:
cat downloaded.txt
Output:
Hello from AWS Emulator!
That's it! We have created an S3 bucket, uploaded a file, and downloaded it again without using an actual AWS account.
Working with Amazon DynamoDB
Let's move to another AWS service: DynamoDB.
DynamoDB is a fully managed NoSQL database service. It allows applications to store and retrieve data using tables, items, and attributes.
Imagine we are building a simple application that manages users. We can use DynamoDB to store information about them.
First, let's create a table named Users:
aws dynamodb create-table \
--table-name Users \
--attribute-definitions \
AttributeName=userId,AttributeType=S \
--key-schema \
AttributeName=userId,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
Here is what we are defining:
-
--table-name: The name of our table. -
--attribute-definitions: Defines the attributes used by the table's key. -
--key-schema: Defines the partition key. -
--billing-mode: Uses on-demand capacity mode.
Our table uses userId as its partition key.
To verify that the table was created:
aws dynamodb list-tables
Now let's insert a user:
aws dynamodb put-item \
--table-name Users \
--item '{
"userId": {"S": "user-001"},
"name": {"S": "Ibrahim"},
"email": {"S": "ibrahim@example.com"}
}'
The command inserts a new item into the Users table.
To retrieve the user, run:
aws dynamodb get-item \
--table-name Users \
--key '{"userId": {"S": "user-001"}}'
You should receive the user information:
{
"Item": {
"userId": {
"S": "user-001"
},
"name": {
"S": "Ibrahim"
},
"email": {
"S": "ibrahim@example.com"
}
}
}
We have successfully created a DynamoDB table and stored a user inside it.
You can also retrieve all the records using:
aws dynamodb scan --table-name Users
Working with Amazon SQS
So far, we have explored object storage and databases.
Let's look at messaging.
Amazon Simple Queue Service (SQS) is a message queuing service that allows different components of an application to communicate asynchronously.
For example, imagine an application where users submit orders. Instead of processing every order immediately, the application can put each order into a queue. Another service can retrieve and process those orders later.
Let's simulate this locally.
First, create a queue:
aws sqs create-queue \
--queue-name orders-queue
The command returns a queue URL.
We can also retrieve it using:
QUEUE_URL=$(aws sqs get-queue-url \
--queue-name orders-queue \
--query 'QueueUrl' \
--output text)
Now let's send a message to the queue:
aws sqs send-message \
--queue-url "$QUEUE_URL" \
--message-body "Order #1001 has been created"
You should receive a response containing a MessageId.
Let's retrieve the message:
aws sqs receive-message \
--queue-url "$QUEUE_URL" \
--wait-time-seconds 2
You should see the message we sent earlier.
We have now created a queue, sent a message, and retrieved it using AWS CLI.
This is a simple example of how different application components can communicate without needing to process requests immediately.
What happens when you stop AWS Emulator?
There is something important to understand about AWS Emulator.
Unlike actual AWS services, the emulator keeps its resources in memory.
This means that when you stop the emulator, the resources you created disappear.
For example, if you stop the Docker container and start it again, your S3 buckets, DynamoDB tables, and SQS queues will no longer be available.
To stop the emulator, go to the terminal where Docker is running and press:
ctrl + c
To remove the Docker image:
docker image rm aws-emulator
You can also remove the local configuration directory if you no longer need it:
rm -rf ~/.aws/emulator
Be careful with this last command because it permanently deletes the emulator's local files.
When should you use AWS Emulator?
AWS Emulator is particularly useful when:
- Developing applications that depend on AWS services.
- Testing AWS integrations without deploying resources.
- Learning how AWS APIs work without an AWS account.
- Running integration tests in CI/CD pipelines.
- Experimenting with different AWS services locally.
However, it is important to understand its limitations.
AWS Emulator is designed for development and testing, not production workloads. Its behavior does not perfectly match every AWS service and API operation. It also does not fully evaluate IAM policies like the real AWS environment.
You should still test your application against actual AWS services before deploying it to production.
Conclusion
AWS Emulator provides a convenient way to experiment with AWS services locally.
In this article, we built a Docker image, started AWS Emulator, configured AWS CLI, and explored three practical examples using S3, DynamoDB, and SQS.
The interesting part is that we used the same AWS CLI commands we would normally use with AWS, but all our operations were handled locally.
If you are learning AWS or developing applications that depend on AWS services, this is definitely a tool worth exploring.
For more information, check out the official AWS Emulator documentation.

Top comments (0)