![](/img/trans.png)
[英]How to include in the lambda function javascript aws-sdk?
[英]How to invoke a lambda function in aws-sdk v3
如何使用 Javascript (TypeScript) aws-sdk v3 調用 lambda 函數?
我使用以下似乎不起作用的代碼:
// the payload (input) to the "my-lambda-func" is a JSON as follows:
const input = {
name: 'fake-name',
serial: 'fake-serial',
userId: 'fake-user-id'
};
// Payload of InvokeCommandInput is of type Uint8Array
const params: InvokeCommandInput = {
FunctionName: 'my-lambda-func-name',
InvocationType: 'RequestResponse',
LogType: 'Tail',
Payload: input as unknown as Uint8Array, // <---- payload is of type Uint8Array
};
console.log('params: ', params); // <---- so far so good.
const result = await lambda.invoke(params);
console.log('result: ', result); // <---- it never gets to this line for some reason.
我在 CloudWatch 中看到此錯誤消息,不確定它是否與我的問題有關:
第一個參數必須是字符串類型或 Buffer、ArrayBuffer 或 Array 的實例或類似 Array 的對象。 接收到一個 Object 實例
題:
上面調用 lambda 函數的代碼是否正確? 或者有什么更好的方法嗎?
看起來您對lambda.invoke()
調用拋出了一個 TypeError 因為當它需要是字符串或緩沖區時,您傳遞給它的有效負載是一個對象。
您可以按如下方式修改代碼以對有效負載進行字符串化:
Payload: JSON.stringify(input),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.