Sample code for 30+ languages & platforms
Lua

S3 List Bucket Objects (Bucket-in-Path)

See more Amazon S3 (new) Examples

Demonstrates how to fetch a list of objects in an S3 bucket, but using the bucket-in-path request format instead of putting the bucket name in the HOST header.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local rest = chilkat.Rest.new()

-- Connect to the Amazon AWS REST server.
local bTls = true
local port = 443
local bAutoReconnect = true
local success = rest:connect("s3.amazonaws.com", port, bTls, bAutoReconnect)

-- ----------------------------------------------------------------------------
-- Important: For buckets created in regions outside us-east-1,
-- there are three important changes that need to be made.
-- See Working with S3 Buckets in Non-us-east-1 Regions for the details.
-- ----------------------------------------------------------------------------

-- Provide AWS credentials for the REST call.
local authAws = chilkat.AuthAws.new()
authAws.access_key = "AWS_ACCESS_KEY"
authAws.secret_key = "AWS_SECRET_KEY"
authAws.service_name = "s3"
success = rest:set_auth_aws(authAws)

-- The bucket name is "chilkat100"
local sbResponse = chilkat.StringBuilder.new()
success = rest:full_request_no_body_sb("GET", "/chilkat100", sbResponse)
if not success then
    print(rest.last_error_text)
    return
end

local statusCode = rest.response_status_code
print("Response status code = " .. statusCode)

local xml = chilkat.Xml.new()
xml:load_sb(sbResponse, true)
print(xml:get_xml())

if statusCode ~= 200 then
    print("Failed.  See error information in the XML.")
    return
end

-- Use this online tool to generate code from sample XML:
-- Generate Code to Create XML

local Key = ""
local LastModified = ""
local ETag = ""
local SizeDecimalStr = ""
local ID = ""
local DisplayName = ""
local StorageClass = ""

local Name = xml:get_child_content("Name")
local MaxKeys = xml:get_child_int_value("MaxKeys")
local IsTruncated = xml:get_child_content("IsTruncated")
local i = 0
local count_i = xml:num_children_having_tag("Contents")
while i < count_i do
    xml.i = i
    Key = xml:get_child_content("Contents[i]|Key")
    LastModified = xml:get_child_content("Contents[i]|LastModified")
    ETag = xml:get_child_content("Contents[i]|ETag")
    SizeDecimalStr = xml:get_child_content("Contents[i]|Size")
    ID = xml:get_child_content("Contents[i]|Owner|ID")
    DisplayName = xml:get_child_content("Contents[i]|Owner|DisplayName")
    StorageClass = xml:get_child_content("Contents[i]|StorageClass")
    i = i + 1
end

print("Success.")