我从事无服务器开发已经有一段时间了,主要是 AWS,并且刚刚开始涉足 SNS 发布/订阅设计模式。我正在使用 typescript 并且类型支持很棒,但是我找不到从 SNS 或 S3 触发器进入 Lambda 的事件的正确类型。这些将使函数之间的接缝确实非常安全。目前我正在定义自己的接口,但这会让人厌烦。例如
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);
}
如果有人能指出我正确的方向,我将不胜感激。
干杯。