简体   繁体   English

为什么 S3 文件上传不会触发事件到 SNS 主题?

[英]Why does S3 file upload not trigger event to SNS topic?

I want a certain HTTPS service to be called every time a file has been uploaded to an S3 bucket.我希望每次将文件上传到 S3 存储桶时都调用某个 HTTPS 服务。

I have created the S3 bucket and a SNS topic with a verified subscription with the HTTPS service as an endpoint.我已经创建了 S3 存储桶和一个 SNS 主题,其中包含一个经过验证的订阅,HTTPS 服务作为端点。 I can publish a message on the SNS topic via the AWS UI, and see that the HTTPS service is called as expected.我可以通过 AWS UI 在 SNS 主题上发布消息,并看到 HTTPS 服务按预期调用。 On the S3 bucket I created an Event, which should link the bucket and the topic.在 S3 存储桶上,我创建了一个事件,它应该链接存储桶和主题。 On my first attempt I got an error because the bucket was not allowed to write to the topic, so cf the documentation, I changed the topic access policy to:在我第一次尝试时出现错误,因为存储桶不允许写入主题,因此请参阅文档,我将主题访问策略更改为:

{
  "Version": "2008-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sns:Publish",
      "Resource": "arn:aws:sns:eu-central-1:TOPIC_ID:OrderUpdates",
      "Condition": {
        "StringEquals": {
          "AWS:SourceAccount": "ACCOUNT_ID"
        },
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:s3:*:*:*"
        }
      }
    }
  ]
}

where TOPIC_ID is the topic owner id which can be seen when the topic is shown in the AWS UI, and the ACCOUNT_ID is the account id shown under account settings in the AWS UI.其中 TOPIC_ID 是在 AWS UI 中显示主题时可以看到的主题所有者 ID,而 ACCOUNT_ID 是在 AWS UI 中的帐户设置下显示的帐户 ID。 This change in the topic access policy allowed me to create the event on the bucket:主题访问策略中的这一更改允许我在存储桶上创建事件: 在此处输入图片说明

When I call the API method getBucketNotificationConfiguration I get:当我调用 API 方法 getBucketNotificationConfiguration 时,我得到:

{
    "TopicConfigurations": [
        {
            "Id": "OrderFulfilled",
            "TopicArn": "arn:aws:sns:eu-central-1:TOPIC_ID:OrderUpdates",
            "Events": [
                "s3:ObjectCreated:*"
            ]
        }
    ],
    "QueueConfigurations": [],
    "LambdaFunctionConfigurations": []
}

But the HTTPS service is not called.但是没有调用HTTPS服务。 What am I missing in this setup, that will trigger the HTTPS service to be called by the SNS topic subscription every time a file is uploaded to the S3 bucket?我在此设置中缺少什么,每次将文件上传到 S3 存储桶时,都会触发 SNS 主题订阅调用 HTTPS 服务?

Thanks, -Louise谢谢,-路易斯

Having the same issue S3 upload event does not trigger sns message even though our sns access policy is correctly set.遇到同样的问题,即使我们的 sns 访问策略设置正确,S3 上传事件也不会触发 sns 消息。 Turns out we can NOT use the Enable encryption option, since S3 events are triggered via CloudWatch Alarms which do not work with SNS encrypted topics as of now.事实证明我们不能使用Enable encryption选项,因为 S3 事件是通过 CloudWatch 警报触发的,这些警报目前不适用于 SNS加密主题。

Switch back to Disable encryption option, everything works again.切换回禁用加密选项,一切正常。

To reproduce this situation, I did the following:为了重现这种情况,我执行了以下操作:

  • Created an Amazon SNS topic and subscribed my phone via SMS (a good way to debug subscriptions!)创建了一个Amazon SNS 主题并通过短信订阅了我的手机(调试订阅的好方法!)
  • Created an Amazon S3 bucket with an Event pointing to the Amazon SNS topic使用指向 Amazon SNS 主题的事件创建了一个Amazon S3 存储桶

I received this error message:我收到此错误消息:

Unable to validate the following destination configurations.无法验证以下目标配置。 Permissions on the destination topic do not allow S3 to publish notifications from this bucket.目标主题的权限不允许 S3 从此存储桶发布通知。

  • I then added the policy you show above (adjusted for my account and SNS ARN)然后我添加了您在上面显示的策略(针对我的帐户和 SNS ARN 进行了调整)
  • This allowed the Event to successfully save这允许事件成功保存

Testing测试

  • I then tested the event by uploading a file to the S3 bucket.然后我通过将文件上传到 S3 存储桶来测试该事件。
  • I received an SMS very quickly我很快就收到了一条短信

So, it would appear that your configuration should successfully enable a message to be sent via Amazon SNS.因此,您的配置似乎应该成功启用通过 Amazon SNS 发送的消息。 This suggests that the problem lies with the HTTPS subscription , either from sending it from SNS or receiving it in the application.这表明问题出在HTTPS 订阅上,无论是从 SNS 发送它还是在应用程序中接收它。

I recommend that you add an Email or SMS subscription to verify whether Amazon SNS is receiving the topic and forwarding it to subscribers.我建议您添加电子邮件或 SMS 订阅以验证 Amazon SNS 是否正在接收主题并将其转发给订阅者。 If this works successfully, then you will need to debug the receipt of the message in the HTTPS application.如果此操作成功,那么您将需要在 HTTPS 应用程序中调试消息的接收。

You must add TopicConfiguration您必须添加 TopicConfiguration

Read more about enable event notification阅读有关启用事件通知的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM