To send S3 event notifications to an Amazon SNS topic, the topic needs an access policy that lets the S3 service (s3.amazonaws.com) call SNS:Publish, and only on behalf of your bucket and your account. This page explains each line of the topic policy above and fixes the account ID error in it. It then covers applying the policy, connecting the bucket and testing the setup with the AWS CLI.
What this policy is and where it goes
The JSON above is not an IAM identity policy that you attach to a user or role. It is a resource-based policy, also called a topic access policy, and it is stored on the SNS topic itself. When an S3 bucket has an event notification that points at the topic, the S3 service publishes messages to the topic on your behalf. SNS checks this policy and allows the publish only if a statement grants SNS:Publish to s3.amazonaws.com.
The gist file is named sns-s3-aws.yaml, but the content is JSON. SNS only accepts topic policies as JSON, so save the file as sns-policy.json.
Line-by-line explanation
| Element | Meaning |
|---|---|
Version: 2012-10-17 | The current policy language version. Always use this value. |
Principal.Service: s3.amazonaws.com | Gives permission to the Amazon S3 service, not to a user or account. |
Action: SNS:Publish | The only action S3 needs. Do not grant SNS:*. |
Resource | The ARN of the topic this policy is attached to: arn:aws:sns:<region>:<account-id>:<topic-name>. |
ArnLike aws:SourceArn | Allows publishing only when the request comes from this bucket. Without it, any bucket in any account could publish to your topic if it knew the ARN. |
StringEquals aws:SourceAccount | The 12-digit account ID of the account that owns the bucket. This prevents the confused deputy problem, for example if your bucket is deleted and someone else creates a bucket with the same name. |
Corrected policy
In the example above, aws:SourceAccount is set to 62509999767. That value has only 11 digits, so it can never match a real account, and it is different from the account in the topic ARN. Because the condition never matches, S3 cannot publish to the topic, and saving the bucket notification fails. The version below uses placeholders. Replace 111122223333 with your bucket owner's account ID, and replace the region, topic name and bucket name with your own.
{
"Version": "2012-10-17",
"Id": "s3-to-sns-policy",
"Statement": [
{
"Sid": "AllowS3Publish",
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:ap-south-1:111122223333:s3-events",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:::my-upload-bucket"
},
"StringEquals": {
"aws:SourceAccount": "111122223333"
}
}
}
]
}Code language: JSON / JSON with Comments (json)
S3 bucket ARNs do not include a region or an account ID, so the exact form is arn:aws:s3:::bucket-name. The original form, arn:aws:s3:*:*:bucket, still matches under ArnLike, but the exact ARN is clearer and less permissive. To allow several buckets, make aws:SourceArn a JSON array of bucket ARNs.
Note: To find your account ID, run aws sts get-caller-identity --query Account --output text.
Apply the policy and connect the bucket with the AWS CLI
- Create a standard topic in the same region as the bucket. S3 event notifications cannot publish to an SNS topic in a different region, and they do not support FIFO topics.
- Attach the corrected policy to the topic with
set-topic-attributes. - Subscribe an endpoint, such as an email address, and confirm the subscription from the email that SNS sends.
- Save the bucket notification configuration that points to the topic.
- Upload a test object.
# 1. Create the topic
aws sns create-topic --name s3-events --region ap-south-1
# 2. Attach the access policy (this replaces the whole existing policy)
aws sns set-topic-attributes \
--region ap-south-1 \
--topic-arn arn:aws:sns:ap-south-1:111122223333:s3-events \
--attribute-name Policy \
--attribute-value file://sns-policy.json
# 3. Subscribe an email address, then confirm from the inbox
aws sns subscribe \
--region ap-south-1 \
--topic-arn arn:aws:sns:ap-south-1:111122223333:s3-events \
--protocol email \
--notification-endpoint ops@example.comCode language: PHP (php)
Next, create notification.json. This example sends an event for every object created under the uploads/ prefix:
{
"TopicConfigurations": [
{
"Id": "uploads-created",
"TopicArn": "arn:aws:sns:ap-south-1:111122223333:s3-events",
"Events": ["s3:ObjectCreated:*"],
"Filter": {
"Key": {
"FilterRules": [
{ "Name": "prefix", "Value": "uploads/" }
]
}
}
}
]
}Code language: JSON / JSON with Comments (json)
# 4. Apply the notification configuration (replaces any existing one)
aws s3api put-bucket-notification-configuration \
--bucket my-upload-bucket \
--notification-configuration file://notification.json
# 5. Test
echo hello > test.txt
aws s3 cp test.txt s3://my-upload-bucket/uploads/test.txtCode language: PHP (php)
Note: put-bucket-notification-configuration replaces the bucket's whole notification configuration. If the bucket already sends events to Lambda or SQS, first run aws s3api get-bucket-notification-configuration --bucket my-upload-bucket and merge the existing entries into your file.
Expected result
When the notification configuration is saved, S3 sends an s3:TestEvent message to the topic. After the upload, the subscriber gets a JSON message with a Records array. Each record includes eventName (for example ObjectCreated:Put), s3.bucket.name and s3.object.key. Object keys are URL-encoded in the event, so a key with spaces arrives with + in place of each space.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
InvalidArgument: Unable to validate the following destination configurations | The topic policy is missing or does not allow S3. Common reasons are a wrong aws:SourceAccount, a wrong bucket name in aws:SourceArn, or a wrong topic ARN in Resource. | Check each value against your real account ID, bucket and topic ARN, then apply the policy again. |
| The same validation error even though the policy is correct | The topic is in a different region from the bucket, or it is a FIFO topic | Use a standard topic in the bucket's region. |
| The same validation error on an encrypted topic | The topic uses SSE-KMS and S3 cannot use the key | Allow S3 in the KMS key policy (see the next section). |
| The configuration saves, but no emails arrive | The subscription is still PendingConfirmation, or the object key does not match the prefix or suffix filter | Confirm the subscription. Run aws sns list-subscriptions-by-topic to check its status, and check the filter rules. |
Encrypted topics and security practices
If the topic uses server-side encryption, you must use a customer managed KMS key. The AWS managed key alias/aws/sns will not work, because you cannot edit its key policy to add the S3 service. Add this statement to the customer managed key's policy:
{
"Sid": "AllowS3ToUseKeyForSNS",
"Effect": "Allow",
"Principal": { "Service": "s3.amazonaws.com" },
"Action": ["kms:GenerateDataKey", "kms:Decrypt"],
"Resource": "*"
}Code language: JSON / JSON with Comments (json)
- Always keep both conditions,
aws:SourceArnandaws:SourceAccount. A policy that allowss3.amazonaws.comwithout them lets any bucket in any account publish to the topic. - Grant only
SNS:Publishto S3. set-topic-attributesoverwrites the default topic policy. Principals in the same account still get access through their IAM permissions. Other accounts that need to subscribe or publish must be added back explicitly.- Manage the topic, policy and bucket notification together in CloudFormation or Terraform so they cannot drift apart.
Frequently asked questions
Is the SNS policy for S3 events an IAM policy?
No. It is a resource-based access policy attached to the SNS topic. The principal is the S3 service, so you do not create an IAM role for this integration.
Can an S3 bucket send events to an SNS topic in another region?
No. The SNS topic must be in the same AWS region as the bucket. The topic can be in a different account if its policy allows it.
Do S3 event notifications support SNS FIFO topics?
No. S3 event notifications can only publish to standard SNS topics. If you need ordering, send the events to SQS or EventBridge and process them from there.
How do I let several buckets publish to one SNS topic?
Make the aws:SourceArn condition a JSON array of bucket ARNs, or use a wildcard pattern such as arn:aws:s3:::logs-* with ArnLike. Keep aws:SourceAccount set to the account that owns the buckets.
Why does S3 say it is unable to validate the destination configuration?
S3 test-publishes to the topic when you save the notification configuration, and the publish was denied. Check the topic policy's account ID, bucket ARN and topic ARN, the region and topic type, and the KMS key policy if the topic is encrypted.
Related tutorials
- More AWS tutorials
- Complete Guide of AWS Organization and AWS access portal
- AWS Tutorials: AWS Identity Center Guide
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals