0
votes

I have written a Lambda function as Websocket and API Gateway using Serverless and Redis. Also using AWS-CLI to deploy project on AWS S3. I am receiving:

Task timed out after 6.01 seconds

Increasing the timeout or request size gives me the same message but with higher amount of timeout seconds. The strange thing is that it works locally, but not when it's deployed to AWS. Code should work. I think something is missing in AWS configurations.

I created separate VPC with 3 subnets: 2 private and 1 public. I created also NAT using public subnet Internet Network. I added route to 0.0.0.0/0. I maintained IAM Role to permit API execution etc.

It happens here:

        return this.ws
            .postToConnection({
                ConnectionId: connId,
                Data: payloadStr
            })

Where ws is

        this.ws = new ApiGatewayManagementApi({
            apiVersion: '2018-11-29',
            endpoint: endpoint
        });

I checked connId and it's not null.

I update with schema how my network looks like:

schema

1
It sounds like the code is hanging on a particular call. Is the AWS Lambda function configured to use a VPC? Please show us the specific part of the code on which it is hanging. You can insert some debugging statements to try and identify where it is getting stuck. - John Rotenstein
@JohnRotenstein done :) I added some code. - blue rabbit
Does it work if Lambda is configured without VPC? If so, you might want to double check routes, security group. aws.amazon.com/premiumsupport/knowledge-center/… - Suraj Bhatia
@SurajBhatia Yes I did. - blue rabbit
@SurajBhatia i added schema of my network architecture - blue rabbit

1 Answers

0
votes

I've just finally fixed this issue. My mistake was that I attached Nat gateway to private subnet instead of public, so this diagram is wrong.