Sample code for 30+ languages & platforms
Lua

Configure AWS Signature Authentication for REST

See more REST Examples

Demonstrates Rest.SetAuthAws, which associates an AuthAws provider so Chilkat signs each request using AWS Signature Version 4. The provider supplies the access key, secret key, region, and service name.

Background. AWS requires each request to be signed with a signature derived from the secret key, region, service, and request contents. Configuring the provider lets Chilkat compute and attach the signature automatically.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local rest = chilkat.Rest.new()
local bTls = true
local bAutoReconnect = true
local success = rest:connect("example.com", 443, bTls, bAutoReconnect)
if not success then
    print(rest.last_error_text)
    return
end

-- Configure AWS Signature Version 4 request signing.  Provide the access key, secret key, region,
-- and service name.
local authAws = chilkat.AuthAws.new()
-- Normally you would not hard-code secrets in source.  You should instead obtain them from an
-- interactive prompt, environment variable, or a secrets vault.
authAws.access_key = "AWS_ACCESS_KEY"
authAws.secret_key = "AWS_SECRET_KEY"
authAws.region = "us-east-1"
authAws.service_name = "s3"

-- Associate the provider so Chilkat signs each request according to AWS requirements.
success = rest:set_auth_aws(authAws)
if not success then
    print(rest.last_error_text)
    return
end

local responseText = rest:full_request_no_body("GET", "/")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

print(responseText)