Hướng dẫn aws php tutorial

Bắt đầu sử dụng nhanh chóng AWS với AWS SDK cho PHP. SDK là thư viện PHP nguồn mở hiện đại giúp bạn dễ dàng tích hợp ứng dụng PHP với các dịch vụ AWS như Amazon S3, Amazon Glacier và Amazon DynamoDB.

Nội dung chính

  • Credentials
  • Including the SDK¶
  • Creating a client object¶
  • Factory method¶
  • Service builder¶
  • Performing service operations¶
  • Working with modeled responses¶
  • Detecting and handling errors¶
  • Iterators¶

Các API tài nguyên của AWS cung cấp một phần rút gọn tập trung vào đối tượng của giao diện "cấp thấp" tức giao diện kiểu RPC trong AWS SDK cho PHP, để đem lại trải nghiệm viết mã trực quan hơn. Đối tượng tài nguyên là tham chiếu đến tài nguyên AWS [ví dụ như phiên bản Amazon EC2 hoặc đối tượng Amazon S3] tiết lộ các thuộc tính của tài nguyên và thao tác theo thuộc tính và phương pháp của đối tượng tài nguyên. Thông tin chi tiết của yêu cầu API HTTP ngầm trở nên rõ ràng và bạn sẽ được làm việc với tài nguyên AWS như thể đó là các đối tượng PHP cục bộ. Đoạn mã mẫu bên dưới sẽ minh họa cách thức hoạt động của quá trình này. Các dịch vụ được hỗ trợ gồm có Amazon EC2, Amazon S3, Amazon SNS, Amazon SQS, AWS IAM, Amazon Glacier và AWS CloudFormation, với thêm nhiều dịch vụ khác sẽ được bổ sung trong tương lai.

// Đoạn mã mẫu bên dưới sẽ minh họa cách thức hoạt động của các API tài nguyên

$aws = new Aws[$config];

// Lấy tham chiếu đến đối tượng tài nguyên

$bucket = $aws->s3->bucket['my-bucket'];

$object = $bucket->object['image/bird.jpg'];

// Truy cập thuộc tính của tài nguyên

echo $object['LastModified'];

// Ra lệnh cho phương pháp của tài nguyên thực hiện thao tác

$object->delete[];

$bucket->delete[];

Bạn muốn tìm các phiên bản cũ của AWS SDK cho PHP?

AWS sẽ ngừng hỗ trợ cho Internet Explorer vào 07/31/2022. Các trình duyệt được hỗ trợ là Chrome, Firefox, Edge và Safari. Tìm hiểu thêm »

This section contains code examples that demonstrate common AWS scenarios that use the AWS SDK for PHP.

All the example code for the AWS SDK for PHP is available here on GitHub.

Credentials

Before running the example code, configure your AWS credentials, as described in Setting credentials. Then import the AWS SDK for PHP, as described in Basic usage.

Topics

  • Amazon CloudFront examples
  • Amazon CloudSearch
  • Amazon CloudWatch examples
  • Amazon EC2 examples
  • Amazon OpenSearch Service
  • AWS Identity and Access Management examples
  • AWS Key Management Service
  • Kinesis examples
  • AWS Elemental MediaConvert
  • Amazon S3 examples
  • AWS Secrets Manager
  • Amazon SES examples
  • Amazon SNS examples
  • Amazon SQS examples

Document Conventions

Amazon S3 client side encryption

Amazon CloudFront examples

This "Getting Started Guide" focuses on basic usage of the AWS SDK for PHP. After reading through this material, you should be familiar with the SDK and be able to start using the SDK in your application. This guide assumes that you have already downloaded and installed the SDK and retrieved your AWS access keys.

Including the SDK¶

No matter which technique you have used to to install the SDK, the SDK can be included into your project or script with just a single include [or require] statement. Please refer to the following table for the PHP code that best fits your installation technique. Please replace any instances of /path/to/ with the actual path on your system.

Installation TechniqueInclude Statement
Using Composer require '/path/to/vendor/autoload.php';
Using the Phar require '/path/to/aws.phar';
Using the Zip require '/path/to/aws-autoloader.php';

For the remainder of this guide, we will show examples that use the Composer installation method. If you are using a different installation method, then you can refer to this section and substitute in the proper code.

Creating a client object¶

To use the SDK, you first you need to instantiate a client object for the service you are using. We'll use the Amazon Simple Storage Service [Amazon S3] client as an example. You can instantiate a client using two different techniques.

Factory method¶

The easiest way to get up and running quickly is to use the web service client's factory[] method and provide your credential profile [via the profile option], which identifies the set of credentials you want to use from your ~/.aws/credentials file [see Using the AWS credentials file and credential profiles].

Chủ Đề