Golang + AWS lambda listening from more than 1 source.

blov · 2018-03-25 17:30:12 · 613 次点击    
这是一个分享于 2018-03-25 17:30:12 的资源,其中的信息可能已经有所发展或是发生改变。

Hi gophers,

Has anyone had any success making golang lambda function to listen to more than one source. For example API Gateway call and Cloudwatch event?

AWS documentation says: // Handler is your Lambda function handler // It uses Amazon API Gateway request/responses provided by the aws-lambda-go/events package, // However you could use other event sources (S3, Kinesis etc), or JSON-decoded primitive types such as 'string'.

However, I had no luck receiving data that was send from 2 different sources.


评论:

nmarley:

A Lambda function can be mapped to many event types, and yes, I've done it with different event types (I believe it was a DynamoDb stream and a s3 notification, but it's been a few months).

Why this isn't working for you depends on a number of factors. Without any other information, my guess is that you don't have the event mapping or access policy set up properly.

TBH, this question is probably better suited for /r/aws than this sub.

grannyno:

Would you mind sharing the definition of your handler func that can decode 2 different events?

In my case I need to make it work with events.APIGatewayProxyRequest and events.CloudWatchEvent. But any example will work.

nmarley:

I can't remember exactly where it is (could probably look it up), but that's not relevant honestly. It's just JSON, you need to handle event and context. It's not Go either, it's Python. The concepts are still the same.

NeedsMoreTests:

/u/grannyno if you look at the docs you'll notice it does not declare an explicit type and the private signature is just []byte. You should be able to make a function signature like this:

func(context.Context, interface{}) error

You'll just have to handle the encoding/decoding yourself.

9gPgEpW82IUTRbCzC5qr:

actually, if your function takes an "events.S3Event" struct (https://github.com/aws/aws-lambda-go/blob/master/events/s3.go#L9), you don't have to take care of any parsing.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

613 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传