Reputation: 11
I was creating a lambda function using node js and executing the simple function, in case of the function returns failure need to trigger an email.
exports.handler = async function(event) {
const promise = new Promise(function(resolve, reject) {
https.get(url, (res) => {
resolve(res.statusCode)
}).on('error', (e) => {
reject(Error(e))
})
})
return promise
}
AWSLambdaSNSTopicDestinationExecutionRole JSON format
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": "arn:aws:sns:xxx-xxxxxx-x:12435693:XXXXXXX"
}
]
}
AWSLambdaVPCAccessExecutionRole
{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"SNS:Publish",
"SNS:RemovePermission",
"SNS:SetTopicAttributes",
"SNS:DeleteTopic",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:AddPermission",
"SNS:Subscribe"
],
"Resource": "arn:aws:sns:xxxx-2:xxxxxx1:xxxxxx",
"Condition": {
"StringEquals": {
"AWS:SourceOwner": "xxxxxxxx"
}
}
},
{
"Sid": "__console_sub_0",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::xxxxxx1:root",
"arn:aws:iam::xxxxxx2:root"
]
},
"Action": "SNS:Subscribe",
"Resource": "arn:aws:sns:xxxx-2:xxxxxx1:xxxxxx_TP"
}
]
}
When I tied to execute the lambda function in case of failure, I am not getting any email. Even I tried to subscribe to the topic for success case as well I am not getting any email. Could anyone face this issue?
Upvotes: 0
Views: 662
Reputation: 238051
Lambda's destination is only for asynchronous invocations of your functions. If you run the function from a console, or a normal synchronous way, destination are not triggered.
Upvotes: 2