Reputation: 3049
I'm using serverless to create a lambda function using the nodejs template.
serverless.yml
. When I try to serverless invoke local -f functionName
, it always times out, so I have to deploy it to test it.
Is it possible to test this out locally with serverless
?
Upvotes: 4
Views: 2856
Reputation: 571
I'm leaving this link here because it helped me when I ran into this issue:
https://github.com/aws/aws-sam-cli/issues/318#issuecomment-377770815
I couldn't access Elasticache from my Lambda (all local with Localstack) and this was happening because they couldn't communicate internally via localhost
Upvotes: 0
Reputation: 3652
Elasticache is not directly accessible from outside AWS environment by default. According to their documentation, the service is designed to be accessed exclusively from within AWS. In your case, serverless invoke local
times out because the connection itself cannot be established and the lambda function times out. So you can't run invoke locally to test this connection the way you are trying to do.
To connect to Elasticache redis from your local machine, you can use a NAT instance in your public subnet and setup the security groups to open up the correct ports and enable IP forwarding to allow connection to your redis cache cluster. The steps are given here.
However, I would just install redis locally and use an environment variable to change the connection string to connect to local redis on local machine and the actual Elasticache cluster when running on lambda.
Upvotes: 8