简体   繁体   English

Lambda不会触发SNS事件。 使用SNS链接AWS Lambda

[英]Lambda does not trigger SNS event. Chaining AWS lambdas with SNS

I am using AWS to chain lambdas together by having a second lambda subscribe to the SNS feed of the first lambda. 我正在使用AWS通过让第二个Lambda订阅第一个Lambda的SNS feed来将Lambda链接在一起。 The second lambda was not receiving anything from the first lambda and I also get no notification in CloudWatch (or my personal email that I subscribed with) that the SNS event has been triggered. 第二个Lambda没有收到来自第一个Lambda的任何东西,我也没有在CloudWatch(或我订阅的个人电子邮件)中收到有关SNS事件已触发的通知。 So, I am wondering the question: How do I make sure my SNS receives an event from my lambda firing? 因此,我想知道一个问题: 如何确保我的SNS接收到来自Lambda触发的事件?

When I use the SNS web UI I get logs like these and my lambda logs show they have been touched, but only when I manually send a message. 当我使用SNS Web UI时,我会收到类似这些的日志,而lambda日志显示它们已被触摸,但仅当我手动发送消息时才如此。

{
"notification": {
    "messageMD5Sum": "e9a72884afc5d9568f2748e34a4e50a4",
    "messageId": "04f4a199-cd25-5a45-a877-f054df9b2adf",
    "topicArn": "arn:aws:sns:us-east-1:xxxxxxxxxxxx:first-lambda",
    "timestamp": "2017-06-28 02:12:14.098"
},
"delivery": {
    "deliveryId": "173dca7a-7b31-55a2-8ee9-9bb7698f35f6",
    "destination": "arn:aws:lambda:us-east-1:xxxxxxxxxx:function:second-labmda",
    "providerResponse": "{\"lambdaRequestId\":\"33972992-5ba7-11e7-b363-09e0f6dc8594\"}",
    "dwellTimeMs": 134,
    "attempts": 1,
    "statusCode": 202
},
"status": "SUCCESS"

} }

I've given my lambda publish permissions in it's role, but that only shows up in IAM and when I view its policy inside of the lambda itself on the GUI I just see lambda firing permissions for the lambda itself. 我已经给我的lambda发布权限以角色的身份,但这仅显示在IAM中,当我在GUI上的lambda自身内部查看其策略时,我只会看到lambda触发该lambda本身的权限。 I also am sure that my SNS has permissions to write to the lambda because when you set up the lambda (as I did more than once yesterday) it asks for you to grant privileges to the SNS topic. 我还确定我的SNS有权写入lambda,因为在设置lambda时(就像我昨天做过多次一样),它要求您授予SNS主题特权。 However, even when testing the SNS topic the lambda is never reached, but I do get an email if I subscribe with my email account. 但是,即使在测试SNS主题时,也不会达到lambda,但是如果我使用自己的电子邮件帐户订阅,我会收到一封电子邮件。

tl;dr First lambda should be triggering an SNS event that a second lambda subscribes to. tl; dr第一个lambda应该触发第二个lambda订阅的SNS事件。 The SNS event is not receiving any data from my first lambda except for two logs in the middle of the night that never went through to my second lambda. SNS事件未从我的第一个lambda接收任何数据,除了深夜的两个日志从未传到我的第二个lambda。 How do I make sure my SNS receives an event from my lambda firing? 如何确定我的SNS收到了我的Lambda触发事件?

Has this been solved for the OP? OP是否解决了这个问题? I'm experiencing the same issue at the moment, happening out of the blue. 我目前遇到同样的问题,突然发生。 I'm actually thinking AWS may have troubles. 我实际上是在考虑AWS可能会有麻烦。 I am in us-east-1. 我在us-east-1。

(I wanted to comment, but I don't have enough reputation points for that yet...) (我想发表评论,但我对此没有足够的声誉积分...)

Solved this by adding a service to my lambda to send the message. 通过向我的lambda添加服务以发送消息来解决此问题。

import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.sns.AmazonSNSClient;
import com.amazonaws.services.sns.model.PublishRequest;

public class SNSPublishService {

private static final String ACCESS_KEY = "credential1";
private static final String SECRET_KEY = "credential2";
private static final String ARN = "arn:aws:sns:<region>:<id>:<topicname>";

public static void publish(String body) throws InterruptedException {
    AmazonSNSClient service = new AmazonSNSClient(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY));
    PublishRequest publishRequest = new PublishRequest()
            .withTargetArn(ARN)
            .withMessage(body);

    service.publish(publishRequest);
}}

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

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