Lambda不会触发SNS事件.使用SNS链接AWS Lambda [英] Lambda does not trigger SNS event. Chaining AWS lambdas with SNS

查看:156
本文介绍了Lambda不会触发SNS事件.使用SNS链接AWS Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS通过将第二个lambda订阅第一个lambda的SNS feed来将lambda链接在一起.第二个Lambda没有收到来自第一个Lambda的任何东西,我也没有在CloudWatch(或我订阅的我的个人电子邮件)中收到有关SNS事件已触发的通知.因此,我想知道一个问题:如何确保我的SNS从我的lambda触发事件中收到事件?

I am using AWS to chain lambdas together by having a second lambda subscribe to the SNS feed of the first 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. So, I am wondering the question: How do I make sure my SNS receives an event from my lambda firing?

当我使用SNS Web UI时,我会收到类似这样的日志,而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.

{
"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"

}

我已经给我的lambda发布权限以角色的身份,但这仅显示在IAM中,当我在GUI上的lambda自身内部查看其策略时,我只会看到lambda触发该lambda本身的权限.我还确保,我的SNS有权写入lambda,因为当您设置lambda时(就像我昨天做过多次一样),它会要求您授予SNS主题特权.但是,即使在测试SNS主题时,也无法达到lambda,但是如果我使用自己的电子邮件帐户进行订阅,我也会收到一封电子邮件.

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. 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. 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.

tl;博士 第一个Lambda应该触发第二个Lambda订阅的SNS事件. SNS事件未从我的第一个lambda接收任何数据,除了深夜的两个日志从未传到我的第二个lambda. 如何确保我的SNS收到了我的lambda触发事件?

tl;dr First lambda should be triggering an SNS event that a second lambda subscribes to. 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. How do I make sure my SNS receives an event from my lambda firing?

推荐答案

通过向我的lambda添加服务以发送消息来解决此问题.

Solved this by adding a service to my lambda to send the message.

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);
}}

这篇关于Lambda不会触发SNS事件.使用SNS链接AWS Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆