Skip to main content

Writing our first client

Let's start with an example to demonstrate a typical usage pattern.

program ListQueues;

{$APPTYPE CONSOLE}

uses
AWS.SQS,
System.SysUtils;

var
SQS: ISQSClient;

begin
try
SQS := TSQSClient.Create;
var Response := SQS.ListQueues;
for var QueueUrl in Response.QueueUrls do
Writeln(QueueUrl);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

The key points to note are:

  1. We use the relevant service unit AWS.SQS.
  2. We declare a variable for the client SQS: ISQSClient.
  3. We create a TSQSClient with default options and assign it to SQS.
  4. We make a ListQueues request and store the Response which will be a ISQSListQueuesResponse.
  5. We enumerate the QueueUrls writing each out to the console. It's worth noting that each client implementation has a corresponding interface and implementation pair like the ISQSClient and TSQSClient as seen in the previous example. You are not required to use the I* interface but if not you will need to manually free the client once you are done using a try/finally block as with any other Delphi object.