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年前9097ビュー
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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ