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 }
Similar to Amazon Kinesis, Amazon SNS is designed for near real-time event processing. It decouples the input from the individual processing nodes. But, unlike Kinesis, SNS is designed to trigger multiple actions based on one event.
To troubleshoot the retry and timeout issues, first review the logs of the API call to find the problem. Then, change the retry count and timeout settings of the AWS SDK as needed for each use case. To allow enough time for a response to the API call, add time to the Lambda function timeout setting.
The default timeout of a Lambda function is three seconds. This means, if you don't explicitly configure a timeout, your function invocations will be suspended after three seconds. Now, if you call a few services, some of which are currently at capacity, a request can very well take a second on its own.
For a lambda function to have internet access (while also being attached to a VPC)
There is a great video by Amazon on this and it was very helpful for someone like me who had 0 knowledge on all the AWS jargon. https://www.youtube.com/watch?v=JcRKdEP94jM#action=share
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With