簡體   English   中英

節點 AWS SDK v3:Lambda 函數中的“事件”和“上下文”arguments 的類型?

[英]Node AWS SDK v3: Types for `event` and `context` arguments in Lambda functions?

我正在切換到新的節點 AWS SDK (v3) 以利用其模塊化和 Typescript 支持。 我需要做的第一件事是編寫 Lambda function,但我找不到支持處理程序 function 簽名的類型。 @aws/client-lambda中的類型似乎都與管理Lambda 的客戶端有關。

節點 SDK 是否有用於在某處編寫Lambda 的官方類型? 尤其是:

  • context參數的類型在哪里?
  • 對於event參數,是否有可能來自其他 AWS 服務及其相應類型的事件列表?
interface Event {
  // This could be anything -- a custom structure or something 
  // created by another AWS service, so it makes sense that
  // there isn't a discoverable type for this. There should be
  // corresponding types for each service that can send events
  // to Lambda functions though. Where are these?
}

interface Context {
  // This is provided by Lambda, but I can't find types for it anywhere.
  // Since it's always the same, there should be a type defined somewhere,
  // but where?
}

exports.handler = ( event: Event, context: Context )=>{
  // While `event` could anything so it makes sense to not have a single type available,
  // `context` is always the same thing and should have a type somewhere.
}

使用aws-lambda 類型,它具有大多數事件的類型。

示例處理程序:

import { SQSHandler, SNSHandler, APIGatewayProxyHandler } from 'aws-lambda';

export const sqsHandler: SQSHandler = async (event, context) => {
  
}

export const snsHandler: SNSHandler = async (event, context) => {
}

export const apiV2Handler: APIGatewayProxyHandler = async (event, context) => {
  return {
    body: 'Response body',
    statusCode: 200
  }
}

暫無
暫無

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

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