Home > Blockchain >  Sign Request with AWS Sig V4 in Dart - Stream was terminated by peer (errorCode: 1)
Sign Request with AWS Sig V4 in Dart - Stream was terminated by peer (errorCode: 1)

Time:10-18

I am building a Flutter app for my personal use. I have deployed a lambda that is triggered via API Gateway, it fetches some data from dynamoDB, processes them, and returns them to the client. The lambda can be triggered by a specific IAM User.

I have the correct access key and secret, when I do the request via Postman, everything works as expected.

When I try to do the request in the Flutter app, however, I get the error

failed: HTTP/2 error: Stream error: Stream was terminated by peer (errorCode: 1).

I am using the AWS SigV4 to sign my request. When printing the canonical request and headers, I don't see any difference from the request that postman does. And when I search for the above error I only find results regarding the case of the headers, but this is something that I can't control with SigV4. Also most results from my search point to gRPC requests, which is not what I'm doing (at least I think I am not).

Apparently, I am doing something wrong. Would appreciate any hints.

Below is the part of the code that signs and performs the request

const signer = AWSSigV4Signer(
      credentialsProvider: AWSCredentialsProvider(AWSCredentials(
          "ACCESS_KEY", "SECRET_KEY")),
  );

final request = AWSHttpRequest.get(
  Uri.https('HOST.execute-api.REGION.amazonaws.com',
      'PATH', {
    'QUERY_PARAM_1': 'ALPHA',
    'QUERY_PARAM_2': 'BETA'
  }),

);
const region = 'REGION';
final scope =
    AWSCredentialScope(region: region, service: AWSService.apiGatewayManagementApi);
final signedRequest = await signer.sign(request, credentialScope: scope);
try {
  final createResponse = signedRequest.send();
  final createStatus = await createResponse.response;
  print("Response: ${createStatus.statusCode}");
} catch (e) {
  print("Exception: $e");
}

CodePudding user response:

Something broken in the latest libs. I changed the versions to 0.1.0 and it is working fine. aws_common: ^0.1.0 aws_signature_v4: ^0.1.0

  • Related