Search code examples
amazon-web-servicesgoiot

AWS lambda golang iotdataplane.PublishInput() Payload Always Empty


I'm having trouble understanding how to package up the Payload field for iotdataplane.PublishInput() using Golang. Can anyone help with this? My Lambda publishes without error but the payload is always empty showing in CloudWatch and at the subscriber. Here's what I'm doing:

type Response struct {
    SerialNum string `json:"serial_number"`
    Time      int64  `json:"time"`
}

resp := Response{
    SerialNum: sernum,
    Time: utc,
}
payload, _ :=- json.Marshal(resp)  // payload is a byte array

...

params := &iotdataplane.PublishInput{
    Topic: &topic,
    Payload: payload,
    PayloadFormatIndicator: aws.String(iotdataplane.PayloadFormatIndicatorUtf8Data),
    Qos: aws.Int64(0),
}

result, err := svc_client.Publish(params)

...

I've tried all sorts of variations to payload and not getting anywhere. Also thought for a moment that payload needed to be a struct with "locationName" and "type" as fields but that didn't work out either. And my payload byte array is for certain not empty.


Solution

  • Found my issue.

    I was using Mosquito to test my lambda response and the problem wasn't in the lambda function but the Mosquito subscriber entry used for testing. I was using the same id (-i option) as my Mosquito pub which I suppose was confusing the broker. Once I removed the -i option from my subscribe entry the lambda publishing started coming through.