LambdaからLambdaを呼び出す方法
環境
AWS SDK for JavaScript v3
Node.js 18
code:javascript
import { LambdaClient, InvokeCommand } from "@aws-sdk/client-lambda";
export const handler = async (event) => {
const client = new LambdaClient();
const input = {
FunctionName: "test_method_B"
};
const command = new InvokeCommand(input);
const res = await client.send(command);
//Uint8Arrayで返却されるためデコードする。
const decoder = new TextDecoder();
const text = decoder.decode(res.Payload);
console.log(text);
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};