Lua Requires Chilkat v9.5.0.61+
Lua
SQS Send Message
See more Amazon SQS Examples
Delivers a message to the specified queue. With Amazon SQS, you now have the ability to send large payload messages that are up to 256KB (262,144 bytes) in size.See SQS SendMessage or detailed information.
Chilkat Lua Downloads
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.
-- such as https://sqs.us-west-2.amazonaws.com/
local bTls = true
local port = 443
local bAutoReconnect = true
local success = rest:connect("sqs.us-west-2.amazonaws.com", port, bTls, bAutoReconnect)
-- Provide AWS credentials for the REST call.
local authAws = chilkat.AuthAws.new()
authAws.access_key = "AWS_ACCESS_KEY"
authAws.secret_key = "AWS_SECRET_KEY"
-- the region should match our URL above..
authAws.region = "us-west-2"
authAws.service_name = "sqs"
rest:set_auth_aws(authAws)
rest:add_query_param("Action", "SendMessage")
rest:add_query_param("MessageBody", "This is the message body which can be up to 256K in size.")
rest:add_query_param("MessageAttribute.1.Name", "test_attribute_name_1")
rest:add_query_param("MessageAttribute.1.Value.StringValue", "test_attribute_value_1")
rest:add_query_param("MessageAttribute.1.Value.DataType", "String")
rest:add_query_param("MessageAttribute.2.Name", "test_attribute_name_2")
rest:add_query_param("MessageAttribute.2.Value.StringValue", "test_attribute_value_2")
rest:add_query_param("MessageAttribute.2.Value.DataType", "String")
-- Use the actual path part of your SQS queue URL here:
local responseXml = rest:full_request_form_url_encoded("POST", "/123456789123/chilkatTest")
if not rest.last_method_success then
print(rest.last_error_text)
return
end
local xml = chilkat.Xml.new()
-- A successful response will have a status code equal to 200.
if rest.response_status_code ~= 200 then
print("request header = " .. rest.last_request_header)
print("response status code = " .. rest.response_status_code)
print("response status text = " .. rest.response_status_text)
print("response header: " .. rest.response_header)
xml:load_xml(responseXml)
print(xml:get_xml())
return
end
-- Examine the successful XML response.
xml:load_xml(responseXml)
print(xml:get_xml())
print("----")
-- A successful response looks like this:
-- <?xml version="1.0" encoding="utf-8" ?>
-- <SendMessageResponse>
-- <SendMessageResult>
-- <MD5OfMessageBody>
-- fafb00f5732ab283681e124bf8747ed1
-- </MD5OfMessageBody>
-- <MD5OfMessageAttributes>
-- 3ae8f24a165a8cedc005670c81a27295
-- </MD5OfMessageAttributes>
-- <MessageId>
-- 5fea7756-0ea4-451a-a703-a558b933e274
-- </MessageId>
-- </SendMessageResult>
-- <ResponseMetadata>
-- <RequestId>
-- 27daac76-34dd-47df-bd01-1f6e873584a0
-- </RequestId>
-- </ResponseMetadata>
-- </SendMessageResponse>
-- Get some values from the response XML:
print("Body: " .. xml:chilkat_path("SendMessageResult|MD5OfMessageBody|*"))
print("MessageId: " .. xml:chilkat_path("SendMessageResult|MessageId|*"))
print("RequestId: " .. xml:chilkat_path("ResponseMetadata|RequestId|*"))