1

I want to connect a HTTP device to IoT core.

I have tried this with the curl command all goes well.

Now I want to try to use POST with signatyure version 4

I'm using postmand to send a POST request, but I got this output:

"message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.",

In authorization fields I have chosen "AWS Signature" and I have completed all of them: access and secret key, aws region and service name=iotdata

I want to get the same results as when I use the curl command:

curl --tlsv1.2 --cacert YY.pem --cert XX.pem.crt --key ZZ.pem.key -X POST -d "{ \"Trama\": \"message\"}" "https://PPPPPP.iot.eu-west-1.amazonaws.com:8443/topics/topicname?qos=1"

1 Answer 1

2

The problem here is that both of your commands are a little different, because of the various ways you can send data to AWS IoT.

In the curl command you're actually using x.509 certificate approach (you can see here for further information: https://docs.aws.amazon.com/iot/latest/developerguide/managing-device-certs.html) This doesn't need the payload to be signed, it's already trusted because the certificate is.

This approach is mostly unique to AWS IoT, because the aim is that the data comes from lots of devices- and you wouldn't want to give them all an IAM Role. In fact, certificate is the recommended way to send data from a device.

You can use these certificates with Postman if you want, by adding them to the request under certificates tab (you only need the .crt and .key files). See https://www.getpostman.com/docs/v6/postman/sending_api_requests/certificates for more detailed instructions.

You still can use AWS v4 signatures (https://docs.aws.amazon.com/iot/latest/developerguide/iam-users-groups-roles.html) so the suggestion is that you're not forming the request properly.

Looking at this documentation (https://docs.aws.amazon.com/iot/latest/apireference/API_iotdata_Publish.html) you should be using:

Method: POST

Uri: <AWS IoT Endpoint>/<url_encoded_topic_name>?qos=1 (e.g. https://a1pn10j0v8htvw.iot.us-east-1.amazonaws.com:8443/topics/iotbutton/virtualButton?qos=1)

Authorisation Type: AWS Signature

AccessKey / SecretKey: As per your credentials

AWS Region: Region you AWS IoT instances is in

Service Name: iotdata

Session Token: Leave blank

2
  • Thanks for your reply, finally I got the solution trying all kind of combination with Uri and host. Uri is like you said and host is only <AWS IoT Endpoint>. Now the question is, It would be possible to do this with GET? Can I send a message to an IoT device using GET from the POST parameters?
    – IoT user
    Oct 16, 2018 at 8:37
  • you have to POST to update the device (GET would be a weird verb to make changes), but you can get the status of anything published to the shadow using: https://docs.aws.amazon.com/iot/latest/apireference/API_iotdata_GetThingShadow.html. Notw that you can't GET messages on just any topic, because that's not how the broker works- you have to listen on the websocket. Oct 16, 2018 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.