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.
Installing
To install the AWS SDK for PHP, follow the instructions
Setup
-
In your home directory, create a file named
.aws/credentials
with the static key:[default] aws_access_key_id = <key_ID> aws_secret_access_key = <secret_key>
-
If you are using a LAMP image from Cloud Marketplace, add to the Apache
httpd.conf
configuration file (for Debian and Ubuntu —apache2.conf
), theHOME
environment variable with the home directory:SetEnv HOME <home_directory>
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 samples
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