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 ElasticSearch #29

Closed berlin2 closed 5 years ago

berlin2 commented 5 years ago

Great library! Please provide an example on signing an ElasticSearch and a DynamoDB request.

berlin2 commented 5 years ago

It's actually very simple:

final awsSigV4Client = new AwsSigV4Client('xxx', 'xxx/', endpoint, serviceName: 'es', sessionToken: 'xxx', region: 'us-east-2');
final query = {
    'query': {
      'bool': {
        'must': {
          'match': {'any': 'data'}
        }
      }
    }
  };

  final signedRequest = new SigV4Request(awsSigV4Client,
      method: 'POST',
      path: '/my-index/test-type/_search',
      headers: new Map<String, String>.from(
          {'Content-Type': 'application/json; charset=utf-8'}),
      body: query);

  http.Response response;
  try {
    response = await http.post(signedRequest.url,
        headers: signedRequest.headers, body: signedRequest.body);
  } catch (e) {
    print(e);
  }
  print(response.body);