You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Boto3配置S3 Put请求触发SNS通知时遇异常求助

Troubleshooting S3 Bucket Notification to SNS Topic Error

Let’s walk through the most likely causes for the error you’re seeing when setting up S3 object creation notifications to an SNS topic, along with actionable fixes:

1. Missing Permissions (Most Common)

S3 needs explicit permission to publish messages to your SNS topic, and the IAM entity running your code needs permissions to modify the bucket’s notification configuration.

Fixes:

  • Update the SNS Topic Policy: Add a statement that allows S3 to publish to the topic. Here’s an example policy (replace placeholders with your actual values):
    {
        "Version": "2008-10-17",
        "Id": "S3-Publish-To-SNS",
        "Statement": [
            {
                "Sid": "AllowS3ToPublish",
                "Effect": "Allow",
                "Principal": {
                    "Service": "s3.amazonaws.com"
                },
                "Action": "sns:Publish",
                "Resource": "YOUR_SNS_TOPIC_ARN",
                "Condition": {
                    "ArnLike": {
                        "aws:SourceArn": "arn:aws:s3:::YOUR_BUCKET_NAME"
                    }
                }
            }
        ]
    }
    
  • Verify IAM Permissions: The IAM role/user running your infra_setup.py script needs these permissions:
    • s3:PutBucketNotificationConfiguration for your target bucket
    • (Optional but helpful) sns:GetTopicAttributes to validate the SNS topic ARN exists

2. Invalid or Malformed SNS Topic ARN

Double-check that your sns_arn variable is correctly formatted. A valid SNS ARN looks like:
arn:aws:sns:REGION:ACCOUNT_ID:TOPIC_NAME

Fixes:

  • Confirm the region, account ID, and topic name match your actual SNS topic.
  • Test the ARN by running a simple API call to fetch topic attributes (this will also validate your permissions):
    sns_client.get_topic_attributes(TopicArn=sns_arn)
    

3. Non-Existent or Misnamed S3 Bucket

Ensure the event_name variable holds the exact name of an existing S3 bucket. S3 bucket names are case-sensitive and must be globally unique.

Fixes:

  • Validate the bucket exists and is accessible with:
    s3.head_bucket(Bucket=event_name)
    
  • Correct any typos in the bucket name.

4. Outdated Botocore/Boto3 Version

You’re using Python 2.7 with an older botocore version, which might have bugs or compatibility issues with newer AWS API behaviors.

Fixes:

  • Upgrade to the latest compatible version of botocore (note: Python 2.7 is end-of-life, but you can use the last supported versions):
    pip install botocore==1.12.201 --user
    
  • Alternatively, migrate your code to Python 3.x with up-to-date SDK versions for long-term support.

5. Get the Full Error Message

Your current error snippet is truncated—full error details (like AccessDenied, InvalidParameterValue, etc.) will pinpoint the exact issue immediately.

Fixes:

Wrap your code in a try/except block to capture and print the full error:

try:
    s3.put_bucket_notification_configuration(
        Bucket=event_name,
        NotificationConfiguration={
            'TopicConfigurations': [
                {
                    'TopicArn': sns_arn,
                    'Events': ['s3:ObjectCreated:*'],
                },
            ]
        }
    )
except Exception as e:
    print("Full error details:", str(e))
    if hasattr(e, 'response'):
        print("Error response metadata:", e.response)

内容的提问来源于stack exchange,提问作者user3816764

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:48:18