I’m trying to do a request to appsync from a node server, using aws4 module.
My keys and iam policy in the user seem correct, but I’m getting this error
{"errors":[{"errorType":"BadRequestException","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.
The Canonical String for this request should have been
'POST
/graphql
content-type:application/json
host:*****.appsync-api.eu-central-1.amazonaws.com
x-amz-date:20230303T180202Z
content-type;host;x-amz-date
7f0fb133cf00e6ce0efa197c0e1737c04608f5bc1ee1316a56e0ab5929311496'
The String-to-Sign should have been
'AWS4-HMAC-SHA256
20230303T180202Z
20230303/eu-central-1/appsync/aws4_request
201966c7d6de1f6a0d30748e5e4db678a6dd8eae8011cc4d8a3c91a793f0bbb9'
"}]}
I have a user with a policy to access my graphql api, and his keys are stored in process.env AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
here is the code calling it
const options = {
hostname: hostname,
path: path,
service: service,
method: 'POST',
region: process.env.AWS_REGION,
timeout: 5000,
headers: { ...headers, 'Content-Type' : 'application/json' }
};
return new Promise((resolve, reject) => {
const req = https.request(aws4.sign(options), (res) => {.....}
.....
2
Answers
Probably a bug or something with
aws4
, I switched to@aws-sdk/signature-v4
with the same configuration and it worksOmg, this costed me an entire day..
It seems like somebody messed up a query string normalization. The query params sorting used to work perfectly up until a couple of days ago. Now it requires a bit of work.
Hopefully, I was using the aws-provided libraries to do everything on my end. The solution is also part of their library:
Edit: Or it can be the
%2B
vs+