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?

preguntada hace 5 años9100 visualizaciones
1 Respuesta
1
Respuesta aceptada

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
respondido hace 4 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas