javaquery / Examples

JavaQuery Examples
http://www.javaquery.com
MIT License
13 stars 20 forks source link

aws sigv4 not working with iot endpoint #5

Open jayasai470 opened 5 years ago

jayasai470 commented 5 years ago

Hello,

i am having trouble with signature of aws canonical request, using your util i am trying to make a post call for the iot endpoint https://**-ats.iot.us-east-1.amazonaws.com/topics/test?qos=0 same req was working with postman client

   TreeMap<String, String> awsHeaders = new TreeMap<String, String>();
    awsHeaders.put("host", "***-ats.iot.us-east-1.amazonaws.com");
   TreeMap<String, String> awsQueryParam = new TreeMap<>();
    awsQueryParam.put("qos", "0");

    AWSV4Auth aWSV4Auth = new AWSV4Auth.Builder(accessKey, secretKey)
                            .regionName("us-east-1")
                            .serviceName("iotdata") // es - elastic search. use your service name
                            .httpMethodName("POST") //GET, PUT, POST, DELETE, etc...
                            .canonicalURI("topics/test") //end point
                            .queryParametes(awsQueryParam) //query parameters if any
                            .awsHeaders(awsHeaders) //aws header parameters
                            .payload(payload) // payload if any
                            .debug() // turn on the debug mode
                            .build();

but getting signature error

Client error <403 FORBIDDEN Forbidden,{"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.","traceId":"80e40ad7-9db1-7a60-809a-889c9fecb852"},[date:"Mon, 11 Feb 2019 20:57:32 GMT", x-amzn-ErrorType:"ForbiddenException:", x-amzn-RequestId:"80e40ad7-9db1-7a60-809a-889c9fecb852", connection:"keep-alive", content-type:"application/json", content-length:"241"]>

let me know if i am doing anything wrong

Thank you,

jayasai470 commented 5 years ago

figured it out, needed to stringify my payload properly Thanks for the util

Dagudelot commented 3 years ago

He jayasai470. Can you please tell me how you solved this issue? What is the propr way to stringify the payload?

Thanks