borko84
borko84

Reputation: 41

aws-sdk nodejs socket timeout after successful aws lambda run

I am running aws-sdk 2.1500 on nodejs client and run the AWS-Lambda AWS-Lambda ended successfully (in aws lambda logfile), but the nodejs client didn't receive any reponse and is still working until timeout.

Any idea what should I check ? Or is there a way to debug connection to see what is happening underneath ?

            const lambda = new AWS.Lambda({
                httpOptions: {
                    connectTimeout: LAMBDA_CONNECTION_TIMEOUT_MS,
                    timeout: LAMBDA_CONNECTION_TIMEOUT_MS, // = 15min
                },
                maxRetries: 0,
            });


    try {
        response = await lambda
            .invoke({
                FunctionName: lambdaName,
                Payload: payload ? JSON.stringify(payload) : undefined,
            }, (err, data) => {
                    if (err){
                        console.error(`Could not invoke lambda: \n ${err}`);
                    }
                }
            )

            .promise();
    } catch (e) {
           ...
    }

ERROR STACK: at ClientRequest. (/app/node_modules/aws-sdk/lib/http/node.js:87:34) at ClientRequest. (/app/node_modules/aws-sdk/lib/http/node.js:87:34) 2023-12-08T15:48:55.864+01:00 at Object.onceWrapper (node:events:628:28) 2023-12-08T15:48:55.864+01:00 at ClientRequest.emit (node:events:514:28) 2023-12-08T15:48:55.864+01:00 at ClientRequest.emit (node:domain:488:12) 2023-12-08T15:48:55.864+01:00 at TLSSocket.emitRequestTimeout (node:_http_client:840:9) 2023-12-08T15:48:55.864+01:00 at Object.onceWrapper (node:events:628:28) 2023-12-08T15:48:55.864+01:00 at TLSSocket.emit (node:events:526:35) 2023-12-08T15:48:55.864+01:00 at TLSSocket.emit (node:domain:488:12) 2023-12-08T15:48:55.864+01:00 at Socket._onTimeout (node:net:589:8) 2023-12-08T15:48:55.864+01:00 at listOnTimeout (node:internal/timers:573:17)

Upvotes: 0

Views: 619

Answers (1)

ParisNakitaKejser
ParisNakitaKejser

Reputation: 14929

Its hard to help you whitout a way its can be reproduces the error, but its sound as you have some node app running inside lambda and try to keep it running, if that's the case i will not recommend this way to use a Lambda function, its build to start application, run your code and the close the app down.

If you application should run take a look on ECS, build your application as a container and push it to ECR, or spin a EC2 instance up and try a sample out here.

Late me know about its your case or I'm total wrong?

Upvotes: 0

Related Questions