Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SNS Creation times out

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 }
like image 961
johnny Avatar asked Mar 30 '17 15:03

johnny


People also ask

Is SNS real time?

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.

How do you deal with Lambda timeouts?

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.

What happens when a lambda times out?

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.


1 Answers

For a lambda function to have internet access (while also being attached to a VPC)

  • Select only private subnets for your lambda function
  • Security group can be default.
  • The private subnet should be attached to a route table which has a route 0.0.0.0/0 to a NAT gateway (X)
  • The tricky part is that NAT gateway X should be attached to a public subnet(AWS console asks for a subnet while creation)
  • The trickier part is that the public subnet we just used in step 4 should be attached to a route table which has a route 0.0.0.0/0 to a IGW. (The configuration of this route makes it a public subnet)

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

like image 163
Karan Bhomia Avatar answered Sep 22 '22 06:09

Karan Bhomia