sigv4 2.0.0 sigv4: ^2.0.0 copied to clipboard
Library for signing AWS requests with Signature Version 4
sigv4 #
A Dart library for signing AWS requests with Signature Version 4.
Usage #
Create a Sigv4Client
. This will hold your secrets and configuration. Some omitted default values:
region
defaults toeu-west-1
serviceName
defaults toexecute-api
final client = Sigv4Client(
accessKey: 'your_access_key',
secretKey: 'your_secret_key',
);
The easier way to create a request is by getting a package:http
request object:
// A simple GET-request
final request = client.request('https://service.aws.com/endpoint');
// package:http get
get(request.url, headers: request.headers);
// A larger request
final request = client.request(
'https://service.aws.com/endpoint',
method: 'POST',
queryParameters: {'key': 'value'},
headers: {'header': 'value'},
body: {'content': 'some-content'},
);
// package:http post
post(request.url, headers: request.headers, body: request.body);
Alternatively, you can get the canonical string and signed headers separately:
final path = 'https://service.aws.com/endpoint';
final queryParameters = {'key': 'value'};
final url = client.canonicalUrl(path, queryParameters: queryParameters);
final headers = client.signedHeaders(
path,
queryParameters: queryParameters,
);
// package:http get
get(url, headers: headers);