aruna470
(Aruna470)
July 15, 2014, 4:39am
1
Hi,
I want to integrate Amazon Web Service PHP SDK(http://docs.aws.amazon.com/aws-sdk-php/guide/latest/installation.html ) with Yii. I`ve red several articles but non of them helped me. I installed it using a zip archive. Do you have proper steps of integrating it?
Thanks,
Aruna
aruna470
(Aruna470)
July 16, 2014, 5:10am
2
Hi,
After spending several hours I managed to come up with a solution. Here are the steps.
Place extracted aws folder inside protected/vendor
In your config/main.php
Yii::setPathOfAlias(‘AwsSDK’,Yii::getPathOfAlias(‘application.vendor.aws.*’)); // Place on top of the page
‘application.vendor.aws.*’ // Add this to import section
In your action
require ‘aws-autoloader.php’;
$awsConfigPath = Yii::app()->basePath . ‘/config/awsConfig.php’;
$aws = Aws\Common\Aws::factory($awsConfigPath);
$s3Client = $aws->get(‘s3’);
Thanks,
Aruna
If you are using the SDK to host your Yii app on AWS, then a simpler way is to use a managed hosting PaaS, like Cloudways PHP hosting platform, to deploy your app. This method is much easier because using this platform, you don’t have to manually setup a server or install the Stack and OS. These packages are preconfigure. You can directly start with deploying your Yii app through Git or SFTP.
composer require aws/aws-sdk-php
then include Composer’s autoloader
require 'vendor/autoload.php';
after you can instantiate AWS services directly
$client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'your-region',
'credentials' => [
'key' => 'YOUR_ACCESS_KEY',
'secret' => 'YOUR_SECRET_KEY',
],
]);