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?

posta 5 anni fa9105 visualizzazioni
1 Risposta
1
Risposta accettata

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
con risposta 4 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande