Skip to main content

AWS SDK for Delphi: cross-platform and open-source

aws-buliding

The AWS SDK for Delphi has reached a major milestone:

AWS SDK for Delphi GitHub Repository

AWS SDK for Delphi Samples GitHub Repository

It now supports Delphi 12, Delphi 11, Delphi 10.4.3 Sydney and Delphi 10.4.2 Rio, and supports all platforms available in those Delphi versions, which means Windows 32-bit and 64-bit, Linux, Android, iOS and macOS.

And more important, we removed the dependency on 3rd party libraries and it is now fully open-source written in 100% native Delphi code. It's available to everyone, for all Delphi editions.

We have written about the SDK in a previous blog post, but here is a quick overview about it.

About Amazon Web Services and the SDK for Delphi

The AWS SDK for Delphi enables Delphi developers to easily work with Amazon Web Services and build scalable solutions with Amazon SES, Amazon SQS, and more.

Each Amazon web service has its own package and unit name scheme, which is AWS < service > .dproj and AWS.< service >.*.pas, respectively. For example, for Amazon SQS (Simple Queue Service), the package name is AWSSQS.dproj and unit name is AWS.SQS.pas (and all other units in the package follow same pattern, like AWS.SQS.Client.pas or AWS.SQS.ClientIntf.pas.

Most types you need will be in the main unit, which for example is AWS.SES. So that’s the only unit you will need to use most of the functions. From there you can access all the available API operations. Each operation method receives a request interface and returns a response interface.

The following example sends an e-mail to the specified address using the specified subject and message:

// 1. Use main unit
uses AWS.SES;

procedure SendEmail(const Recipient, Subject, Content: string);
var
Client: IAmazonSimpleEmailService;
Request: ISendEmailRequest;
Response: ISendEmailResponse;
begin
// 2. Instantiate client interface
Client := TAmazonSimpleEmailServiceClient.Create;

// 3. Create and fill the request
Request := TSendEmailRequest.Create;
Request.Source := SenderEmail;
Request.Destination := TDestination.Create;
Request.Destination.ToAddresses.Add(Recipient);
Request.Message := TMessage.Create(
TContent.Create(Subject),
TBody.Create(TContent.Create(Content)));

// 4. Call operation method passing the request to receive the response;
Response := Client.SendEmail(Request);

// 5. Process the response
WriteLn(Response.MessageId);
end;

Credentials

The AWS SDK for Delphi searches for credentials in a certain order and uses the first available set for the current application, and follows the AWS conventions for credentials. It can retrieve credentials in several ways:

  1. Credentials that are explicitly set on the AWS service client, as described in below
  2. A credentials profile with the name specified by a value in TAWSConfigs.AWSProfileName.
  3. A credentials profile with the name specified by the AWS_PROFILE environment variable.
  4. The [default] credentials profile.

AWS documentation explains about credentials profiles and how AWS retrieves credentials.

The SDK also supports EC2 instance profile credentials.

Passing access and secret keys directly to client:

You can simply pass the Access key ID and Secret key directly in the client constructor:

    Client := TAmazonSQSClient.Create(myAccessKey, mySecretKey);

Although using credentials profile is recommended as it’s easier to manage and also compatible with AWS Command Line Interface.

Enjoy and comment!

Thanks for being with me so far. AWS SDK was born to grow and make the whole AWS world accessible to you. It is fair-code distributed under Apache 2.0 with Commons Clause license.

(*) AWS building photo by Tony Webster. Original picture was cropped to better fit in the page.

Discuss about this article in our forum!