SandA
SandA

Reputation: 47

Lambda function times out when calling google sheets after making postgresql query

I am trying to write a Lambda function (using AWS Cloud9) which makes a query to Redshift (using the node-postgres package) and then writes the result to a Google Sheet (using the googleapis package).

I currently have the code spread over two separate Lambda functions - one to make the query, and one to write to the sheet, though this same error occurred when I tried it in a single function.

Both functions individually work fine. The query function makes a query and returns a result, and the writing query writes a test payload to the sheet. However, if I try to invoke the writing function from the query function, the whole thing freezes up and eventually times out. This is the exact log from a run.

Error: 
Read timeout on endpoint URL: "https://lambda.us-east-2.amazonaws.com/2015-03-31/functions/queryRedshift/invocations"

    at convertStderrToError (https://d28a1z68q19s1r.cloudfront.net/content/ce0bff16a8467f5a19e655ab833e28a385f3a62f/@aws/aws-toolkit-cloud9/configs/bundle.js:424:33)
    at exports.EventEmitter.<anonymous> (https://d28a1z68q19s1r.cloudfront.net/content/ce0bff16a8467f5a19e655ab833e28a385f3a62f/@aws/aws-toolkit-cloud9/configs/bundle.js:416:70)
    at exports.EventEmitter.EventEmitter.emit (https://d373lap04ubgnu.cloudfront.net/c9-af167ac416de-ide/build/configs/ide/@aws/cloud9/configs/ide/environment-default.js:20:23)
    at Consumer.onExit (https://d373lap04ubgnu.cloudfront.net/c9-af167ac416de-ide/build/configs/ide/@aws/cloud9/configs/ide/environment-default.js:47444:80)
    at Consumer.<anonymous> (https://d373lap04ubgnu.cloudfront.net/c9-af167ac416de-ide/build/configs/ide/@aws/cloud9/configs/ide/environment-default.js:47204:4)
    at Consumer.Agent._onMessage (https://d373lap04ubgnu.cloudfront.net/c9-af167ac416de-ide/build/configs/ide/@aws/cloud9/configs/ide/environment-default.js:47289:4)
    at EngineIoTransport.EventEmitter.emit (https://d373lap04ubgnu.cloudfront.net/c9-af167ac416de-ide/build/configs/ide/@aws/cloud9/configs/ide/environment-default.js:47041:16)
    at module.exports.onMessage (https://d373lap04ubgnu.cloudfront.net/c9-af167ac416de-ide/build/configs/ide/@aws/cloud9/configs/ide/environment-default.js:47348:6)
    at module.exports.EventEmitter.emit (https://d373lap04ubgnu.cloudfront.net/c9-af167ac416de-ide/build/configs/ide/@aws/cloud9/configs/ide/environment-default.js:19:23)
    at module.exports.ReliableSocket.onMessage (https://d373lap04ubgnu.cloudfront.net/c9-af167ac416de-ide/build/configs/ide/@aws/cloud9/configs/ide/environment-default.js:47560:76)

I have tried re-working the code to separate things, but I'm not actually sure where to start, as I can only find one other similar problem with no answer, and the log isn't pointing to where things are getting stuck (as far as I can tell - I'm not super experienced at this).

If someone can at least point me in the right direction, it would be super helpful!

Thanks in advance!


EDIT: I have now also tried the node-redshift package with the same result.

Upvotes: 0

Views: 387

Answers (1)

karthikeayan
karthikeayan

Reputation: 5010

From the info you provided, below may be the situation:

  • Querying lambda is able to connect to redshift within AWS.
  • Writing lambda is able to connect to google sheet api through Internet.

Querying lambda doesn't have internet connectivity to connect to

lambda.us-east-2.amazonaws.com

For a Lambda function inside the VPC to access internet you have to do the below,

https://aws.amazon.com/premiumsupport/knowledge-center/internet-access-lambda-function/

You have all your subnets attached to Internet Gateway but none of them having NAT Gateway, if I am correct.

Upvotes: 1

Related Questions