Lambda函数中SQS消息的Typescript类型

0

【以下的问题经过翻译处理】 在lambda函数中,当你接收到一个SQS消息时,事件是哪种类型/接口?例如:export async function handler(event: any): Promise<string> { const records: any[] = event.Records; return "done";}我将事件类型设置为any,因为我没有在“aws-sdk”中找到类型,或者官方没有提供类型?

profile picture
EXPERT
asked 5 years ago37 views
1 Answer
0

【以下的回答经过翻译处理】 我知道这个问题已经一年了,解决方案可能也存在其他地方,但是我能够很容易地使用非官方的@types/aws-lambda包来键入SQS。您可以使用npm install --save @types/aws-lambda来安装它。然后,您的处理程序可能看起来像以下内容:import { SQSHandler, SQSEvent } from "aws-lambda";export const handler: SQSHandler = async (event: SQSEvent) { const records: any[] = event.Records; .... // 在这里进行处理 return;}

profile picture
EXPERT
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions