gpt4 book ai didi

amazon-web-services - AWS Lambda SNS 触发事件类型?

转载 作者:行者123 更新时间:2023-12-04 00:05:33 25 4
gpt4 key购买 nike

我从事无服务器开发已经有一段时间了,主要是 AWS,并且刚刚开始涉足 SNS 发布/订阅设计模式。我正在使用 typescript 并且类型支持很棒,但是我找不到从 SNS 或 S3 触发器进入 Lambda 的事件的正确类型。这些将使函数之间的接缝确实非常安全。目前我正在定义自己的接口(interface),但这会让人厌烦。例如

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);
}


如果有人能指出我正确的方向,我将不胜感激。

干杯。

最佳答案

您可以使用 SNSEvent来自 @types/aws-lambda .
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/56c1ea26b59ed0e4634b1ba27096ab3b90371875/types/aws-lambda/index.d.ts#L211
请记住,这些类型不是由 AWS 自己维护的,因此在某些情况下它可能不是最新的。

关于amazon-web-services - AWS Lambda SNS 触发事件类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47643871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com