Timeout when publishing from AWS Lambda to SNS

task timed out after 3.00 seconds aws lambda nodejs
aws sns publish not working
aws lambda timeout
aws sns publish example
aws sns python example
lambda publish to sns
aws socket timeout
sns lambda retry

I'm trying to publish some data to SNS from a Lambda function call, but it doesn't seem to be working. My function code is -

public class Handler implements RequestHandler<DynamodbEvent, Void> {

    private static final String SNS_TOPIC_ARN = "arn:aws:sns:us-west-2:account_number:function_name";

    public Void handleRequest(DynamodbEvent dynamodbEvent, Context context) {

        LambdaLogger logger = context.getLogger();

        AmazonSNSClient snsClient = new AmazonSNSClient(new DefaultAWSCredentialsProviderChain());

        for (DynamodbStreamRecord record : dynamodbEvent.getRecords()) {
            Map<String, AttributeValue> newImage = record.getDynamodb().getNewImage();

            if (newImage == null) {

            String sensorId = newImage.get("sensorID").getS();
            long timestamp = Long.parseLong(newImage.get("timestamp").getS());
            double temperature = Double.parseDouble(newImage.get("payload").getM().get("temp").getN());

            String data = sensorId + " " + timestamp + " " + temperature;


            PublishRequest publishRequest = new PublishRequest(SNS_TOPIC_ARN, data);

            PublishResult publishResult = snsClient.publish(publishRequest);

            logger.log("Publish Successful " + publishResult.getMessageId());


        return null;

This call results in a timeout (10 seconds) and the lambda invocation fails. If I comment out the SNS publishing part, i.e., if I just log the data received from DynamoDB, it works just fine. As soon as the SNS publishing code is added, it times out.

The timeout message logged in CloudWatch is -

START RequestId: 8db74187-459b-42c5-8a06-b3a74873b236 Version: $LATEST END RequestId: 8db74187-459b-42c5-8a06-b3a74873b236 REPORT RequestId: 8db74187-459b-42c5-8a06-b3a74873b236 Duration: 10001.66 ms Billed Duration: 10000 ms Memory Size: 128 MB Max Memory Used: 37 MB Task timed out after 10.00 seconds

I have all the proper permissions in place, and I'm able to publish to SNS using just the following code running on my PC -

PublishRequest publishRequest = new PublishRequest(SNS_TOPIC_ARN, data);
PublishResult publishResult = snsClient.publish(publishRequest);
System.out.println("Publish Successful " + publishResult.getMessageId());

I have also tried using AmazonSNSAsyncClient instead of AmazonSNSClient, it gives the same result.

What am I missing here ?

Well, since none of the people who commented on my question are answering, I'll answer it myself.

Increasing the memory usage to 256 MB and timeout to 30 seconds seems to have solved the issue.

Timeout when publishing from AWS Lambda to SNS, Well, since none of the people who commented on my question are answering, I'​ll answer it myself. Increasing the memory usage to 256 MB  1.Firstly, our lambda function will invoke AWS CloudWatch event or from API Gateway. 2.When Lambda timeout about to come, it sends SNS Message to AWS SNS with necessary information. 3.AWS SNS will then invoke AWS Lambda and provide the details to Lambda which provided to SNS via SNS Messages.

Increase the amount of memory allocated for the Lambda operation.

Lambda Publish to SNS Timeout, Amazon Web Services · AWS Products & Solutions. AWS Product Information. Entire Site, AMIs from AWS Marketplace, AMIs from All Sources  You can use a Lambda function in one AWS account to subscribe to an Amazon SNS topic in a separate AWS account. In this tutorial, you use the AWS Command Line Interface to perform AWS Lambda operations such as creating a Lambda function, creating an Amazon SNS topic and granting permissions to allow these two resources to access each other.

Increasing the memory allocated to the lambda function worked for me as well (this setting is in the lambda console under basic settings).

This one was maddening for me - I was using the same JAR file for 2 different lambda functions with identical configurations, and the SNS call was working for one but timing out for the other. Maddening!

Tutorial: Using AWS Lambda with Amazon Simple Notification Service, When I try to invoke my AWS Lambda function using an AWS SDK, the function times out, execution hangs, or an API action is duplicated. How do  When the message is published, Amazon SNS attempts to deliver the message to every endpoint (such as AWS Lambda, Amazon SQS, HTTP/S, or an email address) subscribed to the topic. The following tutorial shows how you can use the AWS Management Console, the AWS SDK for Java, and the AWS SDK for .NET to publish a message to a topic.

Troubleshoot Retry and Timeout Issues When Invoking a Lambda , Tried using this library to send an SMS directly to a phone number in a lambda function. It always times out. Same issue with publishing to a  Another way: skip SNS and just use lambdas to call the external API (it wouldn't take more than 1 sec to get a response), and then the lambda would update the database with the result (success/failure/timeout). In that case I'd need to orchestrate lambdas fetching all 50-100K records, retrying, etc.

Timeout · Issue #2 · SamVerschueren/aws-sns-publish · GitHub, My pair of lambda functions cannot communicate via SNS. SNS published events timeout: 90 events: - sns: topicName: myTopic Manually publishing messages to the topic via the AWS console works as expected. Amazon SNS is a service used for push notification. In this chapter, we will explain working of AWS Lambda and Amazon SNS with the help of an example where will perform the following actions − Create Topic in SNS Service and use AWS Lambda Add Topics to CloudWatch. Send SNS text message on phone number given. Requisites

Solved: Publishing to created SNS topic, Are you already using AWS Lambda, or planning to launch your next to make sure this metric is not running dangerously close to the function timeout. queue or SNS topic of your choice, so it can be processed or analyzed later. the text “​submit_order” is found in CloudWatch Logs, you could publish a  For asynchronous invocation, Lambda queues the message and handles retries. If Amazon SNS is unable to reach Lambda or the message is rejected, Amazon SNS retries at increasing intervals over several hours. For details, see Reliability in the Amazon SNS FAQ.