gpt4 book ai didi

go - 接收 lambda InvokeInput 的 lambda 的方法签名是什么?

转载 作者:数据小太阳 更新时间:2023-10-29 03:10:47 25 4
gpt4 key购买 nike

我想让我的两个 lambda 表达式相互通信。 Lambda A 使用 InvokeInput,传递此处示例中使用的有效载荷:

https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/go/example_code/lambda/aws-go-sdk-lambda-example-run-function.go

但是,该示例没有显示接收端,即 Lambda B。我正在尝试访问 Payload,因此我尝试了一个具有方法签名的处理程序:

func Handler(ctx context.Context, lambdaInput messages.InvokeRequest) (api.Response, error)

还有

func Handler(ctx context.Context, lambdaInput lambda.InvokeInput) (api.Response, error)

在前者上调用 lambdaInput.Payload 时,它会返回 [],尽管它是作为有效负载发送的。

我找不到这方面的文档,有人知道我应该使用的正确签名吗?

最佳答案

来自 AWS 文档:https://docs.aws.amazon.com/lambda/latest/dg/go-programming-model-handler-types.html

The following lists valid handler signatures. TIn and TOut represent types compatible with the encoding/json standard library. For more information, see func Unmarshal to learn how these types are deserialized.

func ()
func () error
func (TIn), error
func () (TOut, error)
func (context.Context) error
func (context.Context, TIn) error
func (context.Context) (TOut, error)
func (context.Context, TIn) (TOut, error)

所以这取决于您的有效负载中的内容。 AWS 将尝试反序列化您的数据并将其与函数中的 TIn 参数匹配。已经有一些类型代表 AWS 事件类型,但在您的情况下,您应该编写自己的结构。查看链接以获取一些示例。

关于go - 接收 lambda InvokeInput 的 lambda 的方法签名是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52261661/

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