简体   繁体   English

使用节点 aws sdk 在本地调用 aws lambda 函数

[英]invoking aws lambda functions locally with node aws sdk

I am fairly new running lambda functions locally with sam.我是相当新的运行 lambda 函数在本地与 sam。 I have this project setup where a "node express app" acts as an middleware between internet (api gateway) and other lambda functions.我有这个项目设置,其中“节点快速应用程序”充当互联网(api 网关)和其他 lambda 功能之间的中间件。

based on resource path another lambda function is invoked.基于资源路径调用另一个 lambda function。

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. My-func是基于 lambda function 的 java。

This setup works all fine on lambda but when running locally there are few issues that i am unable to fix.此设置在 lambda 上运行良好,但在本地运行时,我无法修复一些问题。 following the below setup.按照以下设置。

i am using sam to run my lambda functions.我正在使用 sam 运行我的 lambda 函数。 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. 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 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.并使用与上述相同的代码来调用 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但这不起作用失败并出现错误: '$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.请帮助我弄清楚如何从另一个本地运行的 lambda function 调用一个。

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' }); 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' });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM