A new relevant open source project is now available for Delphi community on GitHub:
Для просмотра ссылки Войдиили Зарегистрируйся.
The AWS SDK for Delphi enables Delphi developers to easily work with Для просмотра ссылки Войди Для просмотра ссылки Войди
About Amazon Web Services
From Amazon Web Services (AWS) Для просмотра ссылки ВойдиAWS includes useful services for developers to send notifications (Для просмотра ссылки Войди
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;
Код:
// 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
- Credentials that are explicitly set on the AWS service client, as described in below.
- A credentials profile with the name specified by a value in TAWSConfigs.AWSProfileName.
- A credentials profile with the name specified by the AWS_PROFILE environment variable.
- 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);