Voy a cambiar al nuevo SDK de Node AWS (v3) para aprovechar su modularidad y compatibilidad con TypeScript. Lo primero que tenía que hacer era escribir una función Lambda, pero no puedo encontrar tipos que admitan la firma de la función del controlador. Los tipos en @aws/client-lambda parecen estar todos relacionados con, bueno, un cliente para administrar Lambda.
¿El SDK de Node tiene tipos oficiales para escribir Lambdas en alguna parte? En particular:
context ?event , ¿hay una lista en alguna parte de los eventos que pueden provenir de otros servicios de AWS y sus tipos correspondientes? interface Event { // This could be anything -- a custom structure or something // created by another AWS service, so it makes sense that // there isn't a discoverable type for this. There should be // corresponding types for each service that can send events // to Lambda functions though. Where are these? } interface Context { // This is provided by Lambda, but I can't find types for it anywhere. // Since it's always the same, there should be a type defined somewhere, // but where? } exports.handler = ( event: Event, context: Context )=>{ // While `event` could anything so it makes sense to not have a single type available, // `context` is always the same thing and should have a type somewhere. }Use tipos aws-lambda , tiene tipos para la mayoría de los eventos.
Controladores de ejemplo:
import { SQSHandler, SNSHandler, APIGatewayProxyHandler } from 'aws-lambda'; export const sqsHandler: SQSHandler = async (event, context) => { } export const snsHandler: SNSHandler = async (event, context) => { } export const apiV2Handler: APIGatewayProxyHandler = async (event, context) => { return { body: 'Response body', statusCode: 200 } }