簡體   English   中英

AWS SDK V3 with TypeScirpt 的 Lambda 處理程序簽名是什么

[英]What is the Lambda handler Signature for AWS SDK V3 with TypeScirpt

我正在將現有項目從 AWS SDK 的 V2 更新到 JavaScript 的 V3,並將我們的使用從 JavaScript 移動到 TypeScript。

我正在努力為 Lamda 定義強類型處理程序。

我發現的例子與此類似。 我猜他們正在使用 SDK 的 V2。

export const lambdaHandler = async (event: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> => {
    return {
        statusCode: 200,
        body: JSON.stringify({
            message: 'hello world',
        }),
    };
};

我已經查看了類似於APIGatewayEventContextAPIGatewayProxyResult的類的V3 源代碼,但在填補這些角色時我沒有想到什么。

有人可以告訴我如何強烈輸入這些簽名嗎?

我一直在研究這個並提出以下內容:

import {HttpRequest as __HttpRequest,} from "@aws-sdk/protocol-http";
export const handler = async (
    eventIn: { Records: { body: string }[] },
    context: __HttpRequest
) => {}

請注意,我只實現了正文,但當然您可以將 messageId、receiptHandle 等放在同一級別。

使用這個結果如下

export type EventIn = {
  Records: Array<{
    messageId: string
    receiptHandle: string
    body: string
    attributes: {
      ApproximateReceiveCount: string
      SentTimestamp: string
      SenderId: string
      ApproximateFirstReceiveTimestamp: string
    }
    messageAttributes: {}
    md5OfBody: string
    eventSource: string
    eventSourceARN: string
    awsRegion: string
  }>
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM