简体   繁体   中英

AWS Lambda SNS trigger Event Type?

I've been doing serverless dev for a while, mainly AWS, and just starting to get into SNS pub/sub design patters. I'm using typescript and the type support is fantastic, however I can't find the correct type for the event that comes in to a Lambda from SNS or an S3 trigger. These would make the seams between functions very safe indeed. For the moment I'm defining my own interfaces, this will get tiresome though. eg

 interface IAWSSNSTriggerPayload { Records: [ { EventSource: string, EventVersion: string, EventSubscriptionArn: string, Sns: { Type: string, MessageId: string, TopicArn: string, Subject: string, Message: string, Timestamp: string, SignatureVersion: string, Signature: string, SigningCertUrl: string, UnsubscribeUrl: string, MessageAttributes: {}, } } ] } export const handler = (event: IAWSSNSTriggerPayload, context, cb) => { const response = { statusCode: 200, body: JSON.stringify({ message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully! And from the SNS', input: event, }), }; console.log('SNS Received from Lambda Publisher!!!') console.log(JSON.stringify(event.Records)) cb(null, response); }

If anyone can point me in the right direction I'd be much obliged.

Cheers.

You can use SNSEvent from @types/aws-lambda .

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/56c1ea26b59ed0e4634b1ba27096ab3b90371875/types/aws-lambda/index.d.ts#L211

Please do remember that the typings are not maintained by AWS themselves so there may be some cases where it is not up to date.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM