Typescript - Types for SQS messages in lambda function

1

In lambda function, which type/interface is the event when you get an SQS?. For example:

export async function handler(event: any): Promise<string> {
	const records: any[] = event.Records;
	return "done";
}

I set the event type as any because I didn't find a type in "aws-sdk". Or there is not an official type?

已提問 5 年前檢視次數 9103 次
1 個回答
1
已接受的答案

I know this question is one year old already, and the solution might exist elsewhere as well, but I was able to easily type an SQS even using the unofficial @types/aws-lambda package. You can install it with npm install --save @types/aws-lambda.

Then your handler could look like the following:

import { SQSHandler, SQSEvent } from "aws-lambda";

export const handler: SQSHandler = async (event: SQSEvent) {
	const records: any[] = event.Records;
       .... // do work here
	return;
}
gautier
已回答 4 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南