My data flow is as follows:
I tried to do like strconv.Unquote but that didn't work. How do I unmarshal this string? Here is my relevant code:
func Handler(request events.SNSEvent) {
for _, record := range request.Records {
message := record.SNS.Message
x := make(map[string]string)
jsonErr := json.Unmarshal([]byte(message),&x)
if jsonErr!=nil {
logger.Errorf("Welp couldn't convert json to a map %s",jsonErr.Error())
}
Actually, that structure exists in github.com/aws/aws-lambda-go/events
. Instead of unmarshaling into a map, use the s3Event
struct.
This is how I use this:
for _, snsEventRecord := range event.Records {
var s3Event events.S3Event
err = json.Unmarshal([]byte(snsEventRecord.SNS.Message), &s3Event)
if err != nil {
return err
}
for _, s3EventRecord := range s3Event.Records {
fmt.Println(s3EventRecord.S3.Object.Key)
}