Delphi AWS (Amazon Web Services) SDK for Delphi

ADSoft

Местный
Регистрация
1 Окт 2007
Сообщения
223
Реакции
86
Credits
1,092
A new relevant open source project is now available for Delphi community on GitHub:
Для просмотра ссылки Войди или Зарегистрируйся.


aws-buliding.jpg

The AWS SDK for Delphi enables Delphi developers to easily work with Для просмотра ссылки Войди или Зарегистрируйся and build scalable solutions with Для просмотра ссылки Войди или Зарегистрируйся, Для просмотра ссылки Войди или Зарегистрируйся, and more. It is a non-official SDK based on the official Для просмотра ссылки Войди или Зарегистрируйся. A few selected popular services are added, and more will be added very soon.

About Amazon Web Services​

From Amazon Web Services (AWS) Для просмотра ссылки Войди или Зарегистрируйся: “AWS is the world’s most comprehensive and broadly adopted cloud platform, offering over 200 fully featured services from data centers globally. Millions of customers—including the fastest-growing startups, largest enterprises, and leading government agencies—are using AWS to lower costs, become more agile, and innovate faster.

AWS includes useful services for developers to send notifications (Для просмотра ссылки Войди или Зарегистрируйся), send and receive e-mails (Для просмотра ссылки Войди или Зарегистрируйся), use queue systems (Для просмотра ссылки Войди или Зарегистрируйся), several database systems (Для просмотра ссылки Войди или Зарегистрируйся, Amazon Для просмотра ссылки Войди или Зарегистрируйся), memory cache (Amazon ElastiCache), content delivery network (Для просмотра ссылки Войди или Зарегистрируйся), storage (Для просмотра ссылки Войди или Зарегистрируйся and Для просмотра ссылки Войди или Зарегистрируйся), and many more!.

Using the SDK​

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.SQS. 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 examples receive a message from an SQS queue and output the id and body of each message received:

Код:
// 1. Use main unit
uses AWS.SQS;

procedure WriteMessageIds(const QueueUrl: string);
var
  Client: IAmazonSQS;
  Response: IReceiveMessageResponse;
  Request: IReceiveMessageRequest;
  Msg: AWS.SQS.TMessage;
begin
  // 2. Instantiate client interface
  Client := TAmazonSQSClient.Create;

  // 3. Create and fill the request
  Request := TReceiveMessageRequest.Create;
  Request.QueueUrl := QueueUrl;

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

  // 5. Process the response
  for Msg in Response.Messages do
  begin
    WriteLn(Msg.MessageId);
    WriteLn(Msg.Body);
    WriteLn;
  end;
end;
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.

Credential search order​

  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.

Passing access and secret keys directly to client​

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

Код:
CODE]Client := TAmazonSQSClient.Create(myAccessKey, mySecretKey);
Although using credentials profile is recommended as it’s easier to manage and also compatible with Для просмотра ссылки Войди или Зарегистрируйся.