为什么这个 Go AWS Lambda 的 S3PutEvent 是空的?

huangapple go评论77阅读模式
英文:

Why is S3PutEvent empty for this Go AWS Lambda?

问题

我有一个非常基本的Go Lambda在AWS上运行:

package main

import (
	"context"
	"fmt"
	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
)

func HandleRequest(ctx context.Context, event events.S3Event) {
	fmt.Printf("%+v", event)
}

func main() {
	lambda.Start(HandleRequest)
}

使用go.mod文件:

module xxx

go 1.18

require github.com/aws/aws-lambda-go v1.32.1

这个Lambda函数是由S3上的PUT触发的,使用了一个SQS队列。事件到达Lambda函数时,但当我上传文件到S3时,日志打印出一个空的事件:

{Records:[{EventVersion: EventSource:aws:sqs AWSRegion:eu-central-1 EventTime:0001-01-01 00:00:00 +0000 UTC EventName: PrincipalID:{PrincipalID:} RequestParameters:{SourceIPAddress:} ResponseElements:map[] S3:{SchemaVersion: ConfigurationID: Bucket:{Name: OwnerIdentity:{PrincipalID:} Arn:} Object:{Key: Size:0 URLDecodedKey: VersionID: ETag: Sequencer:}}}]}

现在,当我进入AWS Lambda控制台并使用提供的S3 PUT示例进行测试事件时,事件被正确地打印出来,包括示例值。

我认为这可能是因为来自SQS的事件格式与预期的不同?这不是一个测试事件,我也尝试过这个。

我如何查看传递给我的Lambda函数的事件是什么?

英文:

I have a very basic Go lambda running in AWS:

package main

import (
	"context"
	"fmt"
	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
)

func HandleRequest(ctx context.Context, event events.S3Event) {
	fmt.Printf("%+v", event)
}

func main() {
	lambda.Start(HandleRequest)
}

With go.mod

module xxx

go 1.18

require github.com/aws/aws-lambda-go v1.32.1

This lambda is triggered by PUT on S3, using an SQS queue. The events arrive at the lambda, but when I upload a file to S3, the logs print an empty event:

{Records:[{EventVersion: EventSource:aws:sqs AWSRegion:eu-central-1 EventTime:0001-01-01 00:00:00 +0000 UTC EventName: PrincipalID:{PrincipalID:} RequestParameters:{SourceIPAddress:} ResponseElements:map[] S3:{SchemaVersion: ConfigurationID: Bucket:{Name: OwnerIdentity:{PrincipalID:} Arn:} Object:{Key: Size:0 URLDecodedKey: VersionID: ETag: Sequencer:}}}]}

Now when I go in the AWS lambda console and click Test Event using the provided S3 PUT example, the event is printed correctly, including the example values.

I'm thinking that this might be because the event from SQS is in a different format than expected? It's not a test event, I tried this as well.

How can I see which event is being passed to my lambda?

答案1

得分: 2

啊,原来应该是一个SQSEvent,它包装了S3Event

英文:

Ah. Turns out it should be a SQSEvent, which wraps the S3Event.

huangapple
  • 本文由 发表于 2022年7月6日 17:05:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/72880689.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定