英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论