Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Hello tutorial for the AWS SDK for PHP

Focus mode
Hello tutorial for the AWS SDK for PHP - AWS SDK for PHP

Say hello to Amazon S3 using the AWS SDK for PHP. The following example displays a list of your Amazon S3 buckets.

Including the SDK in your code

No matter which technique you used to install the SDK, you can include the SDK in your code with just a single require statement. See the following table for the PHP code that best fits your installation technique. Replace any instances of /path/to/ with the actual path on your system.

Installation Technique Require 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';

In this topic, we assume the Composer installation method. If you’re using a different installation method, you can refer back to this section to find the correct require code to use.

Write the code

Copy and paste the following code into a new source file. Save and name the file hello-s3.php.

require 'vendor/autoload.php'; use Aws\S3\S3Client; /** * List your Amazon S3 buckets. * * This code expects that you have AWS credentials set up per: * https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html */ //Create a S3Client $s3Client = new S3Client([ 'profile' => 'default', 'region' => 'us-west-2', 'version' => '2006-03-01' ]); //Listing all S3 Bucket $buckets = $s3Client->listBuckets(); foreach ($buckets['Buckets'] as $bucket) { echo $bucket['Name'] . "\n"; }

Running the program

Open a command prompt to run your PHP program. The typical command syntax to run a PHP program is:

php [source filename] [arguments...]

This sample code uses no arguments. To run this code, enter the following into the command prompt:

$ php hello-s3.php

Next steps

To test out many other Amazon S3 operations, check out the AWS Code Examples Repository on GitHub.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.