How to Receive S3 Event Notifications with SQS in AWS Emulator
In AWS Emulator, if you allow S3 to send messages in the SQS queue policy and then add a notification configuration to the bucket, events for putting and deleting objects arrive in the queue. These are the steps for testing S3-event-driven processing, such as creating a thumbnail when an image is uploaded, locally or in CI without an AWS account. The page shows the commands and output from my test environment, covering the error when the policy is missing, the shape of the JSON that arrives, URL encoding of keys, and filtering by prefix and suffix.
The test environment was Ubuntu 24.04.5 (x86_64), AWS Emulator 1.0.385 (released November 14, 2026, Debian package), AWS CLI 2.40.3, and jq 1.7. I did not use an AWS account, and all requests were sent to the local emulator. I have not checked how things behave on real AWS (delivery delay, duplicates or reordering, pricing, and so on). Where I mention those, the source is the official documentation. I did not test notifications to SNS, Lambda, or EventBridge, a queue encrypted with KMS, a queue in another account, or calls from an SDK.
- 1. Setup: Start the emulator and point the AWS CLI at it
- 2. Create the bucket and queue, then look up the queue ARN
- 3. Without a queue policy, the notification configuration is refused
- 4. Allow S3 to call SendMessage in the queue policy
- 5. Putting an object delivers a JSON message with Records
- 6. Keys arrive URL-encoded
- 7. Filter by prefix and suffix, and also receive delete events
- 8. Putting an empty configuration stops notifications
- 9. What may differ on real AWS
Setup: Start the emulator and point the AWS CLI at it
I installed the emulator following the official Linux guide, verifying the Debian package signature with gpg first. I started it with telemetry turned off, then set the environment variables from the official docs in another terminal.
aws-emulator -t off
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
In the test, I started the emulator in the background from a script and wrote its standard output to a file named emu.out. In the output below, the twelve-digit account ID made of zeros is written as <12桁の0>.
Create the bucket and queue, then look up the queue ARN

As described in the S3 user guide on granting permissions to notification destinations, you need to allow S3 to send messages in the queue policy. In this article, I set the notification configuration before the policy so I could see what happens when the policy is missing.
$ aws s3api create-bucket --bucket uploads-bucket
{
"Location": "/uploads-bucket",
"BucketArn": "arn:aws:s3:::uploads-bucket"
}
$ aws sqs create-queue --queue-name uploads-queue
{
"QueueUrl": "https://sqs.us-east-1.amazonaws.com/<12桁の0>/uploads-queue"
}
The notification configuration takes the queue's ARN, not its URL. I store the URL and ARN in variables because later commands use them.
QUEUE_URL=$(aws sqs get-queue-url --queue-name uploads-queue --query QueueUrl --output text)
QUEUE_ARN=$(aws sqs get-queue-attributes --queue-url "$QUEUE_URL" --attribute-names QueueArn --query Attributes.QueueArn --output text)
$ echo "$QUEUE_URL"; echo "$QUEUE_ARN"
https://sqs.us-east-1.amazonaws.com/<12 digits of 0>/uploads-queue
arn:aws:sqs:us-east-1:<12桁の0>:uploads-queue
Without a queue policy, the notification configuration is refused
The bucket notification configuration is written in JSON. Put the queue's ARN and the event types to notify in QueueConfigurations. s3:ObjectCreated:* is a wildcard that covers all events for object creation. I embedded the value of QUEUE_ARN and saved the result as notification.json.
{
"QueueConfigurations": [
{
"Id": "uploads-to-sqs",
"QueueArn": "arn:aws:sqs:us-east-1:<12桁の0>:uploads-queue",
"Events": ["s3:ObjectCreated:*"]
}
]
}
When I applied it with put-bucket-notification-configuration, it failed with InvalidArgument.
$ aws s3api put-bucket-notification-configuration --bucket uploads-bucket --notification-configuration file://notification.json
aws: [ERROR]: An error occurred (InvalidArgument) when calling the PutBucketNotificationConfiguration operation: Unable to validate the following destination configurations
Running get-bucket-notification-configuration right afterward printed nothing, so the configuration had not been saved. I pulled the fields from the emulator's log (one JSON object per line) with jq. It says the destination queue's permissions do not allow S3 to publish notifications, so the configuration was refused without being recorded.
$ grep "do not validate" emu.out | jq .fields
{
"message": "this notification configuration names destinations that do not validate; it is refused rather than recorded",
"bucket": "uploads-bucket",
"destinations": "[(\"arn:aws:sqs:us-east-1:<12桁の0>:uploads-queue\", \"Permissions on the destination queue do not allow S3 to publish notifications from this bucket\")]"
}
The PutBucketNotificationConfiguration API reference says that when you put a configuration, S3 sends a test message to each destination, and if that fails the whole configuration fails and is not added to the bucket. The emulator also refused the whole configuration.
Allow S3 to call SendMessage in the queue policy
Following the SQS queue policy example in the guide on granting permissions to destinations, I set Principal to the S3 service (s3.amazonaws.com) and allowed sqs:SendMessage. The aws:SourceArn condition limits the sender to this bucket, and aws:SourceAccount limits it to the bucket owner's account.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "s3.amazonaws.com" },
"Action": "sqs:SendMessage",
"Resource": "arn:aws:sqs:us-east-1:<12桁の0>:uploads-queue",
"Condition": {
"ArnLike": { "aws:SourceArn": "arn:aws:s3:::uploads-bucket" },
"StringEquals": { "aws:SourceAccount": "<12桁の0>" }
}
}
]
}
I saved this as policy.json, turned it into a string with jq's tostring, and set it as the queue's Policy attribute. Then I applied the notification configuration that had been refused before. This time it succeeded with no output.
$ jq -c "{Policy: tostring}" policy.json > attributes.json && aws sqs set-queue-attributes --queue-url "$QUEUE_URL" --attributes file://attributes.json
$ aws s3api put-bucket-notification-configuration --bucket uploads-bucket --notification-configuration file://notification.json
$ aws s3api get-bucket-notification-configuration --bucket uploads-bucket
{
"QueueConfigurations": [
{
"Id": "uploads-to-sqs",
"QueueArn": "arn:aws:sqs:us-east-1:<12桁の0>:uploads-queue",
"Events": [
"s3:ObjectCreated:*"
]
}
]
}
At this point, the queue had one s3:TestEvent message. It arrived even though I had not put any object yet.
$ aws sqs receive-message --queue-url "$QUEUE_URL" --wait-time-seconds 3 > test-event.json; jq -r ".Messages[0].Body | fromjson" test-event.json
{
"Service": "Amazon S3",
"Event": "s3:TestEvent",
"Time": "2026-11-15T02:27:34.090325Z",
"Bucket": "uploads-bucket",
"RequestId": "41821C507A61C1F9",
"HostId": "41821c507a61c1f926c26f5bc0f03822874ceeb69135706afeef1d9eb68d2a1e"
}
The event message structure page also says S3 sends a test message in this form when a notification is configured. The message has no Records. The same page advises that receiving code should handle both test messages and event messages. After checking this, I deleted the message with delete-message.
The official AWS Emulator documentation says it does not evaluate IAM policies and resource-based policies the same way AWS does, and advises against using it for security testing. In this test, the result changed depending on whether the queue policy was present, but the emulator cannot tell you whether your policy is correct on real AWS.
Putting an object delivers a JSON message with Records
I put images/photo.jpg and then received the message. The body was JSON with a Records array.
$ aws s3api put-object --bucket uploads-bucket --key images/photo.jpg --body photo.jpg --query ETag --output text
"b1946ac92492d2347c6235b4d2611184"
$ aws sqs receive-message --queue-url "$QUEUE_URL" --wait-time-seconds 5 > created.json; jq -r ".Messages[0].Body | fromjson" created.json
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "2026-11-15T02:27:37.054893Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "f7b11509f4d675c3c44f0dd37ca830bb02e8cfa58f04c46283c4bfcbdce1ff45"
},
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"responseElements": {
"x-amz-request-id": "40E382E358151959",
"x-amz-id-2": "40e382e358151959ef38b1d2d20929042c0b47ec0dbb7f6fce1191df2147b4af"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "uploads-to-sqs",
"bucket": {
"name": "uploads-bucket",
"ownerIdentity": {
"principalId": "f7b11509f4d675c3c44f0dd37ca830bb02e8cfa58f04c46283c4bfcbdce1ff45"
},
"arn": "arn:aws:s3:::uploads-bucket"
},
"object": {
"key": "images/photo.jpg",
"sequencer": "18E816EC9FB85530",
"size": 6,
"eTag": "b1946ac92492d2347c6235b4d2611184"
}
}
}
]
}
The eventName is ObjectCreated:Put, which is the configured event with the s3: prefix removed. configurationId is the Id I set in the notification configuration. The field names and nesting match the example in the official message structure page. The one difference is eventVersion: the official example shows 2.6, while the emulator returned 2.1. Next, I used jq to pull out the event name, bucket name, key, and size.
$ jq -r ".Messages[0].Body | fromjson | .Records[] | [.eventName, .s3.bucket.name, .s3.object.key, .s3.object.size] | @tsv" created.json
ObjectCreated:Put uploads-bucket images/photo.jpg 6
Next, I deleted this object with aws s3 rm, and nothing arrived in the queue. The configuration only includes s3:ObjectCreated:*, and delete events are not in it.
Keys arrive URL-encoded
When I put an object with a key containing a space and Japanese characters, images/my photo 猫.jpg, the key arrived in a form using + and %.
$ aws s3api put-object --bucket uploads-bucket --key "images/my photo 猫.jpg" --body photo.jpg --query ETag --output text
"b1946ac92492d2347c6235b4d2611184"
$ aws sqs receive-message --queue-url "$QUEUE_URL" --wait-time-seconds 5 > space.json; jq -r ".Messages[0].Body | fromjson | .Records[0].s3.object.key" space.json
images/my+photo+%E7%8C%AB.jpg
The message structure page also says that key values are URL-encoded, and that red flower.jpg becomes red+flower.jpg. The key you receive is not the same string you put. Because spaces are encoded as +, I could recover the original key in Python with urllib.parse.unquote_plus.
$ python3 -c "import json,sys,urllib.parse; b=json.load(open(\"space.json\"))[\"Messages\"][0][\"Body\"]; print(urllib.parse.unquote_plus(json.loads(b)[\"Records\"][0][\"s3\"][\"object\"][\"key\"]))"
images/my photo 猫.jpg
Filter by prefix and suffix, and also receive delete events
I changed the configuration to receive only .jpg files under images/, for both creation and deletion. Key filtering goes in FilterRules under Filter, using prefix and suffix. The format is the same as the example in the guide on filtering by key name.
{
"QueueConfigurations": [
{
"Id": "jpg-under-images",
"QueueArn": "arn:aws:sqs:us-east-1:<12桁の0>:uploads-queue",
"Events": ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"],
"Filter": {
"Key": {
"FilterRules": [
{ "Name": "prefix", "Value": "images/" },
{ "Name": "suffix", "Value": ".jpg" }
]
}
}
}
]
}
I saved this as notification-filter.json and applied it. The queue again received an s3:TestEvent. A test message arrives each time the configuration is put.
$ aws s3api put-bucket-notification-configuration --bucket uploads-bucket --notification-configuration file://notification-filter.json
$ aws sqs receive-message --queue-url "$QUEUE_URL" --wait-time-seconds 3 > test-event2.json; jq -c ".Messages[0].Body | fromjson | {Event, Bucket}" test-event2.json
{"Event":"s3:TestEvent","Bucket":"uploads-bucket"}
After deleting the test message, I put objects with three keys and then deleted two of them.
$ for k in docs/readme.txt images/icon.png images/cat.jpg; do aws s3api put-object --bucket uploads-bucket --key "$k" --body photo.jpg --query ETag --output text; done
"b1946ac92492d2347c6235b4d2611184"
"b1946ac92492d2347c6235b4d2611184"
"b1946ac92492d2347c6235b4d2611184"
$ aws s3 rm s3://uploads-bucket/images/cat.jpg
delete: s3://uploads-bucket/images/cat.jpg
$ aws s3 rm s3://uploads-bucket/images/icon.png
delete: s3://uploads-bucket/images/icon.png
$ aws sqs receive-message --queue-url "$QUEUE_URL" --wait-time-seconds 3 --max-number-of-messages 10 > filtered.json; jq -r ".Messages[].Body | fromjson | .Records[] | [.eventName, .s3.object.key] | @tsv" filtered.json
ObjectCreated:Put images/cat.jpg
ObjectRemoved:Delete images/cat.jpg
Of the five operations, only two arrived: putting and deleting images/cat.jpg. docs/readme.txt has a different prefix, so its put did not arrive. images/icon.png has a different suffix, so neither its put nor its delete arrived. Receiving again afterward returned no other messages.
According to the API reference, put-bucket-notification-configuration replaces the entire existing configuration. When you use multiple destinations or filters, you write all of them into one JSON each time. The key-name filtering guide says that you cannot use multiple rules for the same event type that overlap by prefix, by suffix, or by a combination of prefix and suffix.
Putting an empty configuration stops notifications
The API reference says that putting an empty configuration stops notifications. After I put {}, get-bucket-notification-configuration printed nothing. Then I put images/after.jpg, and nothing arrived in the queue.
$ aws s3api put-bucket-notification-configuration --bucket uploads-bucket --notification-configuration "{}"
$ aws s3api get-bucket-notification-configuration --bucket uploads-bucket
$ aws s3api put-object --bucket uploads-bucket --key images/after.jpg --body photo.jpg --query ETag --output text
"b1946ac92492d2347c6235b4d2611184"
$ aws sqs receive-message --queue-url "$QUEUE_URL" --wait-time-seconds 3 --max-number-of-messages 10 --query "Messages[].Body"
null
What may differ on real AWS
In this test, each notification arrived once. The S3 event notifications overview says that on real AWS, notifications are designed to be delivered at least once. They usually arrive within seconds, but sometimes take a minute or longer. The event types and destinations page also says that the same event is occasionally delivered more than once, and that delivery order may not match the order in which events occurred. The same page says that SQS FIFO queues cannot be used as destinations, and that EventBridge is the way to send to a FIFO queue. Tests that pass on the emulator do not show how real AWS behaves, so the code that receives these messages must be written to handle duplicates and out-of-order delivery.





