A Lua library for interacting with AWS (Amazon Web Services).
Implements the AWS Signature v4 algorithm. This can be used to sign requests to a variety of Amazon services.
CanonicalURI = canonicalise_path(path)Canonicalises the given string argument according to the v4 signature rules for paths:
- Removes redundant path components, e.g.
..and. - Ensures (only) the correct characters are escaped
CanonicalQueryString = canonicalise_query_string(query)Canonicalises the given string argument according to the v4 signature rules for query strings:
- Ensures (only) the correct characters are escaped
- Query arguments are sorted
kSigning = derive_signing_key(kSecret, Date, Region, Service)Derives the signing key as specified in http://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html Uses a SHA256 HMAC.
request, extra = prepare_request(tbl)Prepares a signed HTTP(S) request.
Currently does not support Authentication parameters in the query string.
The fields of tbl are:
| Field | Type | Description |
|---|---|---|
.Domain |
`string | nil` |
.Region |
string |
The Amazon region. e.g. "us-east-1" |
.Service |
string |
The Amazon service. e.g. "kinesis" |
.method |
string |
e.g. "GET" |
.CanonicalURI |
`string | nil` |
.path |
`string | nil` |
.CanonicalQueryString |
`string | nil` |
.query |
`string | nil` |
.headers |
`{string:string | false} |
.body |
`string | nil` |
.AccessKey |
string |
Your Amazon access key. |
.SigningKey |
`string | nil` |
.SecretKey |
`string | nil` |
.timestamp |
`number | nil` |
.tls |
`boolean | nil` |
.port |
`number | nil` |
The returned request object has fields:
| Field | Type | Description |
|---|---|---|
.url |
string |
URL representing the Host, |
.host |
string |
Host to connect to. e.g. "kinesis.us-east-1.amazonaws.com" |
.port |
number |
TCP port to connect to. e.g. 443 |
.tls |
boolean |
Should SSL/TLS be used to connect? e.g. true |
.method |
string |
e.g. "GET" |
.target |
string |
The target (the part between method and HTTP/) ready to be used in a HTTP request. i.e. path and query string |
.headers |
{string:string} |
Table of headers |
.body |
`string | nil` |
The returned extra object has intermediary values calculated by the AWS v4 signing algorithm.
| Field | Type |
|---|---|
.CanonicalURI |
string |
.CanonicalQueryString |
string |
.SignedHeaders |
string |
.CanonicalHeaders |
string |
.CanonicalRequest |
string |
.StringToSign |
string |
.SigningKey |
string |
.Signature |
string |
.Authorization |
string |
If not provided, certain headers will be added.
To prevent a header from getting added, provide it in .headers with a boolean value of false
HostX-Amz-DateAuthorization
This example prepares a HTTP request to Amazon Kinesis to ListStreams
local prepare_request = require "aws.v4".prepare_request
local request, extra = prepare_request {
Region = "us-east-1";
Service = "kinesis";
method = "POST";
headers = {
["X-Amz-Target"] = "Kinesis_20131202.ListStreams";
["Content-Type"] = "application/x-amz-json-1.1";
};
body = '{}';
AccessKey = "AKIDEXAMPLE";
SecretKey = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY";
}