How to use Amazon PHP AWS SDK

If you have to use one of their services with the new PHP SDK 3.31 you will have to first install it using composer

composer install aws/aws-sdk-php

then you have to

And the sample PHP code is:

use Aws\Sdk;
$sdk = new Sdk([
    'region' => 'eu-west-1', // your account region
    'version' => 'latest',
]);
// This is example using AWS SQS
$sqs = $sdk->createSqs([
    'region' =>'eu-west-1', // your account region
    'version' => 'latest',
    'credentials' => [
        'key' => 'access_key',
        'secret' => 'secret_access_key',
    ],
]);

You can also put the access key and secret access key in the environment vars and the SDK will get them from there or you can check this URL for how to use credentials

putenv('AWS_ACCESS_KEY_ID=' . $accessKey);
putenv('AWS_SECRET_ACCESS_KEY=' . $secretAccessKey);
putenv('AWS_SESSION_TOKEN=' . $sessionToken);

In the PHP SDK they are using Promises and because of that you will need these Class reference docs to check all properties and methods of all services

Leave a Reply

Your email address will not be published. Required fields are marked *