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?

demandé il y a 5 ans9100 vues
1 réponse
1
Réponse acceptée

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
répondu il y a 4 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions