jonsaw / amazon-cognito-identity-dart

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
204 stars 93 forks source link

Signing Request for DynamoDB #41

Closed berlin2 closed 5 years ago

berlin2 commented 5 years ago

The API returns a "The request signature we calculated does not match the signature you provided" error for this request:

final awsSigV4Client = new AwsSigV4Client(accessKeyId,
      secretAccessKey, 'https://dynamodb.us-east-2.amazonaws.com',
      serviceName: 'dynamodb', sessionToken: sessionToken, region: 'us-east-2', defaultContentType: 'application/x-amz-json-1.0');

  final query = {
    "TableName": "xxx",
    "KeyConditionExpression": "(#0 = :0 AND begins_with (#1, :1))",
    "ExpressionAttributeNames": {
      "#0" : "pk",
      "#1" : "sk"
    },
    "ExpressionAttributeValues": {
      ":0": {"S": "Foo"},
      ":1": {"S": "C10108000"},
    },
    "ReturnConsumedCapacity": "TOTAL"
  };

  final signedRequest = new SigV4Request(awsSigV4Client,
      method: 'POST',
      path: '/',
      headers: new Map<String, String>.from(
          {'X-Amz-Target': 'DynamoDB_20120810.Query'}),
      body: query);
berlin2 commented 5 years ago

Found the solution thanks to https://github.com/jonsaw/amazon-cognito-identity-dart/issues/35

final awsSigV4Client = new AwsSigV4Client(accessKeyId,
      secretAccessKey, 'https://dynamodb.us-east-2.amazonaws.com',
      serviceName: 'dynamodb', sessionToken: sessionToken, region: 'us-east-2', defaultContentType: 'application/json; charset=utf-8');
jonsaw commented 5 years ago

35 #37