I am fairly new running lambda functions locally with sam. I have this project setup where a "node express app" acts as an middleware between internet (api gateway) and other lambda functions.
based on resource path another lambda function is invoked.
invocation code block:
const { Lambda } = require ("@aws-sdk/client-lambda");
const client = new Lambda({region: "eu-central-1"});
const input = {
FunctionName: "My-func",
InvocationType: "RequestResponse",
Payload: JSON.stringify(payload)
};
client.invoke(input);
My-func
is a java based lambda function .
This setup works all fine on lambda but when running locally there are few issues that i am unable to fix. following the below setup.
i am using sam to run my lambda functions.
running my java function (My-func) as sam local start-lambda -t my-func.yaml
which runs the lambda on 127.0.0.1:3001.
Now i am trying to invoke this function from my nodejs app, i read some github issues from aws sdk repo to specify the endpoint in lambda client initialization config like
const client = new Lambda({apiVersion: '2015-03-31', endpoint: 'http://127.0.0.1:3001/' });
and use the same code as above to invoke the function. but this does not work fails with error:
'$metadata': { attempts: 1, totalRetryDelay: 0 } (net.js:1144:16) { ERROR Error: connect ECONNREFUSED 127.0.0.1:3001
please help me in figuring out how to invoke one lambda function from another running locally.
Thanks in advance.
running my lambda function as sam local start-lambda -t my-func.yaml --host 0.0.0.0
and modify the lambda config to use dockers ip 172.17.0.1
as endpoint worked const client = new Lambda({region: "eu-central-1", apiVersion: '2015-03-31', endpoint: 'http://172.17.0.1:3001' });