AWS SDK for PHP
The AWS SDK for PHP
Getting started
- Create a service account.
- Assign the service account the roles required for your project. For more information about roles, see the Identity and Access Management documentation.
- Create a static access key.
Note
A service account is only allowed to view a list of buckets in the folder it was created in.
A service account can perform actions with objects in buckets that are created in folders different from the service account folder. To enable this, assign the service account roles for the appropriate folder or its bucket.
Installation
To install the AWS SDK for PHP, follow the instructions
Setup
-
In your home folder, create a file named
.aws/credentials
with this static key:[default] aws_access_key_id = <key_ID> aws_secret_access_key = <secret_key>
-
If using a LAMP image from Cloud Marketplace, add the
HOME
environment variable referring to your home folder to the Apachehttpd.conf
configuration file (apache2.conf
for Debian and Ubuntu):SetEnv HOME <home_folder>
For more information about the location and name of the Apache configuration file for different operating systems, see the Apache HTTP Server Wiki
.
Instead of the .aws/credentials
file, you can use the AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
environment variables.
Use the Object Storage address to access storage.yandexcloud.net
.
Code snippets
List of bucket names:
// We assume that the AWS SDK is installed via Composer
require '/path/to/vendor/autoload.php';
use Aws\S3\S3Client;
$s3 = new S3Client([
'version' => 'latest',
'endpoint' => 'https://storage.yandexcloud.net',
'region' => 'ru-central1',
]);
$buckets = $s3->listBuckets();
foreach ($buckets['Buckets'] as $bucket) {
echo $bucket['Name'] . "\n";
}
See also the code samples