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:
grannyno: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.
nmarley: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.
NeedsMoreTests: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
andcontext
. It's not Go either, it's Python. The concepts are still the same.
9gPgEpW82IUTRbCzC5qr:/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.
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.
