aws_request

Pub Package Open Issues Code size License CI pipeline status Coverage

Easily create, sign, and send API requests to AWS.


Resources

Documentation       Pub Package       GitHub Repository

If you have feedback or have a use case that isn't covered feel free to open an issue.

Getting Started

Create a request and send it!

import 'package:aws_request/aws_request.dart';

main() {
  final AwsRequest request = new AwsRequest(
    awsAccessKey: 'awsAccessKey',
    awsSecretKey: 'awsSecretKey', 
    region: 'region',
  );
  request.send(type: AwsRequestType.post);
}

The following parameters can be provided to the send() function:

type: request type (GET, POST, PUT, etc)
service: aws service you are sending request to
signedHeaders: a list of headers aws requires in the signature.
   Default included signed headers are: (content-type, host, x-amz-date)
   (You do not need to provide these in [headers])
headers: any required headers. Any non-default headers included in the signedHeaders 
         must be added here.
jsonBody: the body of the request, formatted as json
queryPath: the aws query path
queryString: the url query string as a Map

Supported HTTP methods are GET, POST, DELETE, PATCH, PUT, HEAD.

Important Notes:

Android

If running on android, make sure you have

<uses-permission android:name="android.permission.INTERNET" />

in your app's android/app/src/main/AndroidManifest.xml

Examples

Example 1

Here's an example of using aws_request to send a CloudWatch PutLogEvent request:

import 'package:aws_request/aws_request.dart';
import 'package:http/http.dart';

Future<void> awsRequestFunction(String logString) async {
  final AwsRequest request = new AwsRequest(
    awsAccessKey: 'awsAccessKey',
    awsSecretKey: 'awsSecretKey',
    region: 'region',
  );
  final Response result = await request.send(
    type: AwsRequestType.post,
    jsonBody: "{'jsonKey': 'jsonValue'}",
    service: 'lambda',
    queryString: {'X-Amz-Expires': '10'},
    headers: {'X-Amz-Security-Token': 'XXXXXXXXXXXX'},
  );
  print(result.statusCode);
}

Example 2

There is also a static method if you find that more useful:

import 'package:aws_request/aws_request.dart';
import 'package:http/http.dart';

void awsRequestFunction(String logString) async {
  Response result = await AwsRequest.staticSend(
    awsAccessKey: 'awsAccessKey',
    awsSecretKey: 'awsSecretKey',
    region: 'region',
    type: AwsRequestType.post,
    jsonBody: "{'jsonKey': 'jsonValue'}",
    service: 'logs',
    queryString: {'X-Amz-Expires': '10'},
    headers: {'X-Amz-Security-Token': 'XXXXXXXXXXXX'},
  );
}

MIT License

Copyright (c) Zachary Merritt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Libraries

aws_request
testing