Creating S3 and SQS with Terraform on AWS Emulator
If you run AWS Emulator locally, you can use terraform apply to create an S3 bucket and an SQS queue without an AWS account. This article shows how to run plan and apply locally or in CI before you apply infrastructure code (IaC) to real AWS. However, with AWS provider 6.73.0, which was the latest version when I tested, bucket creation failed with an error. This article explains the cause and how to work around it by pinning the provider version. The explanation is based on the commands and output from my test environment.
The test environment was Ubuntu 24.04 (x86_64), AWS Emulator 1.0.487 (released November 17, 2026), Terraform 1.17.2, AWS provider 6.22.1 and 6.73.0, and AWS CLI 2.40.4. I did not use an AWS account or credentials. I did not test what happens when the same configuration is applied to real AWS, including charges, IAM permission checks, and how long resource creation takes. The test environment could not reach the Terraform Registry, so I downloaded the AWS provider from releases.hashicorp.com, verified its SHA256 checksum, and installed it with Terraform's filesystem mirror setting. Terraform ran without an HTTPS proxy. The emulator's account ID is twelve zeros. In the output it is replaced with the placeholder <12桁のアカウントID> (a placeholder for the 12-digit account ID). The run of twelve zeros at the start of a hostname below is the same value.
- 1. Start the emulator and point Terraform at it
- 2. With newer AWS providers, S3 bucket creation stops
- 3. Pin the provider to a version before 6.23.0 and create the bucket and queue
- 4. Check the results with the AWS CLI
- 5. Check whether plan shows drift and whether configuration changes apply
- 6. Restarting the emulator leaves only the state behind
Start the emulator and point Terraform at it
AWS Emulator is an emulator that accepts AWS API calls on your own machine. According to the official documentation, you do not need an AWS account, and requests are not sent to AWS.
The installation steps are covered in a separate article, "How to Install AWS Emulator on Ubuntu and Get Started." Here I installed the Debian package from the Linux instructions and verified its gpg signature first. I worked as root, so I did not use sudo, but the commands below include it for a regular user. The -t off flag at startup turns off the usage data sent to AWS by default (telemetry).
curl -fsSLO https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/latest/aws-emulator_amd64.deb
sudo apt-get install -y ./aws-emulator_amd64.deb
aws-emulator -t off
The emulator keeps running in its terminal, so run Terraform in a different terminal. In that terminal, set the environment variables from the official documentation.
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
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_PROFILE
The Terraform AWS provider also reads these environment variables. The provider documentation says it reads the region from AWS_REGION, the config and credentials files from AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE, and the certificate from AWS_CA_BUNDLE. You can also change the endpoint for all services at once with AWS_ENDPOINT_URL, as described in the custom service endpoints guide. For that reason, I could leave provider "aws" {} empty.
The official documentation warns that if you run a command in a shell where AWS_ENDPOINT_URL is not set, the command sends requests to real AWS using any credentials it finds. On a machine that has real AWS credentials, run terraform apply only in a terminal where all the environment variables above are set.
You can use the AWS CLI to check that requests reach the emulator. If the last part of the ARN is user/emulator, the emulator is responding. Right after startup, there are no buckets or queues.
$ aws sts get-caller-identity --query Arn --output text
arn:aws:iam::<12桁のアカウントID>:user/emulator
$ aws s3api list-buckets --query 'Buckets[].Name'
[]
$ aws sqs list-queues
With newer AWS providers, S3 bucket creation stops
First, I created a single bucket using AWS provider 6.73.0, which was the latest version at the time of testing.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "6.73.0"
}
}
}
provider "aws" {}
resource "aws_s3_bucket" "uploads" {
bucket = "example-uploads"
}
terraform apply failed with an error after about four seconds. The last part of the output is shown below.
$ terraform apply -auto-approve
(略)
Plan: 1 to add, 0 to change, 0 to destroy.
aws_s3_bucket.uploads: Creating...
Error: listing tags for S3 (Simple Storage) Bucket (example-uploads): operation error S3 Control: ListTagsForResource, https response error StatusCode: 0, RequestID: , HostID: , request send failed, Get "https://000000000000.127.0.0.1:9297/v20180820/tags/arn%3Aaws%3As3%3A%3A%3Aexample-uploads": dial tcp: lookup 000000000000.127.0.0.1: no such host
with aws_s3_bucket.uploads,
on main.tf line 12, in resource "aws_s3_bucket" "uploads":
12: resource "aws_s3_bucket" "uploads" {
The bucket itself was created in the emulator, and Terraform's state recorded it.
$ aws s3api list-buckets --query 'Buckets[].Name'
[
"example-uploads"
]
$ terraform state list
aws_s3_bucket.uploads
The error happened when Terraform tried to read the tags of the bucket it had just created. The request was sent to 000000000000.127.0.0.1 instead of 127.0.0.1, with the account ID added to the front. That hostname could not be resolved, so the request failed.

According to the CHANGELOG entry for 6.23.0 in the AWS provider, starting with that version, aws_s3_bucket uses S3 Control APIs (such as ListTagsForResource) to read and write tags. The CHANGELOG says that when the s3:ListTagsForResource permission and similar permissions are missing, the provider falls back to the S3 GetBucketTagging API it used before. However, the AWS Emulator documentation's explanation of SDKs that change the hostname says that S3 Control requests always get the account ID added to the hostname by the SDK, so they do not reach the emulator. Even with AWS_DISABLE_HOST_PREFIX_INJECTION set, this prefix was still added.
When I compared the tag-read requests in the Terraform debug log (TF_LOG=DEBUG), the difference was clear. Version 6.22.1 sent GetBucketTagging to 127.0.0.1. Version 6.73.0 sent S3 Control/ListTagsForResource to 000000000000.127.0.0.1.
The same problem is reported in issue #56 on the AWS Emulator GitHub. At the time I wrote this article, the issue was still open, and the suggested workaround is to pin the provider to a version before 6.23.0.
Pin the provider to a version before 6.23.0 and create the bucket and queue
If you set version to "< 6.23.0", Terraform selects the newest version that matches the condition, which in this case is 6.22.1 (Terraform version constraint syntax). With this configuration, I created an S3 bucket and an SQS queue.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "< 6.23.0"
}
}
}
provider "aws" {}
resource "aws_s3_bucket" "uploads" {
bucket = "example-uploads"
force_destroy = true
tags = {
Env = "local"
}
}
resource "aws_sqs_queue" "jobs" {
name = "example-jobs"
visibility_timeout_seconds = 60
message_retention_seconds = 86400
tags = {
Env = "local"
}
}
output "bucket_name" {
value = aws_s3_bucket.uploads.bucket
}
output "queue_url" {
value = aws_sqs_queue.jobs.url
}
force_destroy = true lets terraform destroy delete the bucket even when it still contains objects. I added it because I planned to upload a file before destroying the bucket.
terraform init installed 6.22.1. The Terraform output is long, so from here I show only the relevant lines. According to the Terraform source code, (unauthenticated) appears when there is no signature or other verification result. In this setup, I verified the SHA256 checksum before placing the provider in the local directory.
$ terraform init
- Installing hashicorp/aws v6.22.1...
- Installed hashicorp/aws v6.22.1 (unauthenticated)
Terraform has been successfully initialized!
After terraform plan showed that two resources would be created, I ran terraform apply.
$ terraform apply -auto-approve
(略)
Plan: 2 to add, 0 to change, 0 to destroy.
(略)
aws_sqs_queue.jobs: Creating...
aws_s3_bucket.uploads: Creating...
aws_s3_bucket.uploads: Creation complete after 0s [id=example-uploads]
aws_sqs_queue.jobs: Still creating... [00m10s elapsed]
aws_sqs_queue.jobs: Still creating... [00m20s elapsed]
aws_sqs_queue.jobs: Creation complete after 25s [id=https://sqs.us-east-1.amazonaws.com/<12-digit account ID>/example-jobs]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
bucket_name = "example-uploads"
queue_url = "https://sqs.us-east-1.amazonaws.com/<12桁のアカウントID>/example-jobs"
The bucket was created right away, but the queue took 25 seconds. The emulator is not slow here. The delay comes from how the provider waits. In the provider source code, after creating or changing a queue, the provider reads the queue attributes at intervals of at least 5 seconds and keeps waiting until six consecutive reads match the configured values. The debug log also showed GetQueueAttributes being called about every 5 seconds.
Check the results with the AWS CLI
I used the AWS CLI to read the bucket and queue that were created. The bucket tags, and the queue attributes and tags, matched the configuration file.
$ aws s3api get-bucket-tagging --bucket example-uploads
{
"TagSet": [
{
"Key": "Env",
"Value": "local"
}
]
}
$ aws sqs get-queue-attributes --queue-url $(terraform output -raw queue_url) --attribute-names VisibilityTimeout MessageRetentionPeriod
{
"Attributes": {
"VisibilityTimeout": "60",
"MessageRetentionPeriod": "86400"
}
}
$ aws sqs list-queue-tags --queue-url $(terraform output -raw queue_url)
{
"Tags": {
"Env": "local"
}
}
The queue_url output has the same form as a real SQS URL, sqs.us-east-1.amazonaws.com. The AWS CLI sends requests to the endpoint set by AWS_ENDPOINT_URL, so even when I passed this URL to --queue-url, the requests still reached the emulator. I was able to upload a file to the bucket and send and receive a message on the queue without any changes.
$ echo hello > hello.txt && aws s3 cp --no-progress hello.txt s3://$(terraform output -raw bucket_name)/hello.txt
upload: ./hello.txt to s3://example-uploads/hello.txt
$ aws sqs send-message --queue-url $(terraform output -raw queue_url) --message-body hello --query MessageId --output text | wc -c
37
$ aws sqs receive-message --queue-url $(terraform output -raw queue_url) --query 'Messages[].Body' --output text
hello
Check whether plan shows drift and whether configuration changes apply
After apply, I ran terraform plan again to check whether the values returned by the emulator differed from the configuration file. There was no drift.
$ terraform plan
(略)
No changes. Your infrastructure matches the configuration.
Next, I changed visibility_timeout_seconds from 60 to 120 and applied the change. The queue was updated in place and was not recreated. This update also took 25 seconds, the same wait as during creation.
$ terraform apply -auto-approve
# aws_sqs_queue.jobs will be updated in-place
~ visibility_timeout_seconds = 60 -> 120
Plan: 0 to add, 1 to change, 0 to destroy.
aws_sqs_queue.jobs: Modifications complete after 25s [id=https://sqs.us-east-1.amazonaws.com/<12-digit account ID>/example-jobs]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
$ aws sqs get-queue-attributes --queue-url $(terraform output -raw queue_url) --attribute-names VisibilityTimeout
{
"Attributes": {
"VisibilityTimeout": "120"
}
}
terraform destroy deleted both resources. The bucket still contained a file, but because I had set force_destroy = true, the destroy did not fail.
$ terraform destroy -auto-approve
Plan: 0 to add, 0 to change, 2 to destroy.
aws_sqs_queue.jobs: Destroying... [id=https://sqs.us-east-1.amazonaws.com/<12-digit account ID>/example-jobs]
aws_s3_bucket.uploads: Destroying... [id=example-uploads]
aws_s3_bucket.uploads: Destruction complete after 0s
aws_sqs_queue.jobs: Destruction complete after 1s
Destroy complete! Resources: 2 destroyed.
$ aws s3api list-buckets --query 'Buckets[].Name'
[]
$ aws sqs list-queues
Restarting the emulator leaves only the state behind
As described in the official limits section, AWS Emulator keeps resources only in memory, and stopping it deletes everything. Terraform state, on the other hand, is stored in a file (terraform.tfstate), so it remains.
After I ran apply, stopped the emulator, and started it again, the bucket was gone but both resources remained in the state. When I ran plan in this state, Terraform noticed that the resources did not exist and planned to create both again. When I applied that plan, both resources were recreated.
$ aws s3api list-buckets --query 'Buckets[].Name'
[]
$ terraform state list
aws_s3_bucket.uploads
aws_sqs_queue.jobs
$ terraform plan
# aws_sqs_queue.jobs has been deleted
# aws_s3_bucket.uploads will be created
# aws_sqs_queue.jobs will be created
Plan: 2 to add, 0 to change, 0 to destroy.
The emulator's contents are cleared each time it starts, but terraform.tfstate keeps the previous contents. If you start the emulator and run apply every time in CI or a similar setup, begin each run without a terraform.tfstate file so that the emulator and the state stay in sync.





