I have Lambda function when invoked it creates SNS topic, adds subscribers to it and then publishes a message to it. After publishing the messages it deletes the topic. The name of the topic to be created and the subscribers are supplied to the lambda function as payload.
Sometimes it works and sometimes it fails with Task timed out after x seconds
I have increased the lambda timeout and still same issue.
I dug a little and found out that
sns.createTopic(params, function(err, data) {
if(err) {
console.log('Error Creating SNS Topic:',err);
} else {
console.log('SNS Topic Created Successfully:',data);
}
}
never returns, no error no data and I don't see result of console.log()
When it works, everything is good but when it fails I can't see to find the issue.
EDIT:
So I did a little more digging, I decreased the timeout of SNS topic creation it was 5 minutes by default now it is 5 seconds. When the failing happens I get this"
{ [TimeoutError: Connection timed out after 5000ms]
message: 'Connection timed out after 5000ms',
code: 'NetworkingError',
time: Thu Mar 30 2017 15:35:20 GMT+0000 (UTC),
region: 'us-east-1',
hostname: 'sns.us-east-1.amazonaws.com',
retryable: true }
I think I figured the issue out, my Lambada is in VPC and I had selected a couple of subnets under my Lambada configuration. Some of the selected subnets didn't have access to the internet and I think that was the reason when the lambda container was being created under these subnets(with no internet) it was not able to access SNS and timing out. After removing the violating subnets it starts working. I haven't see the issue since then.
来源:https://stackoverflow.com/questions/43121829/aws-sns-creation-times-out