Reputation: 735
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?
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"
}
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;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?
Upvotes: 2
Views: 588
Reputation: 735
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);
}}
Upvotes: 0