Yii-AWS ¶
Provides a simple way to configure and use Amazon AWS SDK PHP 2. For more information regarding its services, please go to http://docs.aws.amazon.com/aws-sdk-php-2/latest/namespace-Aws.html.
Before you start ¶
The wrapper is in "alpha" version. Obviously, I couldn't test all the possibilities of Amazon SDK, I have tested just a couple. But being just a wrapper, it should not have any issues whatsoever but those related to the SDK itself.
I published, in order to get good feedback from you guys and again, provide another utility to the Yii framework. If you wish to collaborate, comment, whatever, please, do not hesitate to add your two cents via its github repository. Everybody welcome.
Overview ¶
The main purpose of this extension was to be able to configure the sdk in a very easy way, and then be able to make use of its classes with an easy and configurable import at my main config file.
Install ¶
I assume that if you wish to use this extension, you already have your AWS credentials.
Since schmunk convinced me about composer wonders. From now on, you will be able to install my extensions using composer (https://packagist.org/packages/2amigos/).
Via Composer ¶
- Add
2amigos/yii-aws
as a dependency in your project'scomposer.json
file.{ "require": { "2amigos/yii-aws": "dev-master" } }
- Download and install Composer.
curl -s "http://getcomposer.org/installer" | php
- Install your dependencies.
php composer.phar install
- Require Composer's autoloader.
Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process.
require '/path/to/vendor/autoload.php';
You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at getcomposer.org.
The Old Fashion Way ¶
If you do not work with composer, then simply download or clone from its repository and place it wherever you wish.
After you do that, make sure you "import" on your main.php
config file, the classes within the yii-aws/components/*
folder.
Configuration ¶
The library has a config
folder where you will find a file named "aws-config" to setup the configuration options for the services. For more information about configuring your services, please have a look at http://docs.aws.amazon.com/awssdkdocsphp2/latest/gettingstartedguide/sdk-php2-using-the-sdk.html
note do not forget to add your AWS credentials there :)
How to use it ¶
// This import is better to be included in your main
// config file. For those newbies to the framework,
// please recall that this is a path alias, you should
// write exactly where it is
Yii::import('path.to.amazon.components.*');
$s3 = new A2S3();
$response = $s3->listBuckets(); // we are going to list the buckets
// just for the sake of the example
print_r($response);
Requirements ¶
- Fulfill the requirements of the new SDK
- aws.phar file (already included)
Resources ¶
web development has never been so fun
www.2amigos.us
Thank you
Antonio,
First of all thanks a lot for the AWS wrapper.
I have developed a website using Yii and found recently about Amazon AWS. So now I am thinking to host with Amazon AWS.
Do I need to rewrite the entire code to use AWS(of course with this wrapper)?
Can we expect a Wiki article like your other extensions?
I am completely new to AWS.. Started reading ... Please can you suggest?
@venuk
This is a wrapper to the latest library AWS PHP SDK 2 and some of the documentation is not yet completed.
I think that is best to go to the latest as it will replace in the future version one.
Using the code gives blank page
Hey All
I am trying to use this extension in my web app. Am using AWS for the first time.
In this app, when the user saves the form I make a call to the aws to put an object and then redirect the user to some page. Here is the code for putting the object to AWS S3.
It appears that just instantiating A2S3 causes this.
$s3 = new A2S3(); $result = $s3->putObject(array( 'Bucket' => 'moriarty', 'Key' => $name, 'Body' => $text, 'ACL' => 'public-read' )); $this->redirect(array('update','id'=>$model->id));//this does not do what I think it should do
I have verified that the object is saved in S3, the form model is saved in the database, it all works, but when I redirect the user to the page, it throws up with no error.
I thought that it might be a problem with phar file, but not really sure. Not using Suhosin as well. Using MAC MAMP server. PHP 5.3.6.
Thanks!
Kunal
Demo returns error
I'm getting this error when I run sample code:
Argument 2 passed to Guzzle\Service\Client::getCommand() must be of the type array, boolean given, called in \protected\vendors\2amigos\yii-aws\components\A2Base.php on line 80 and defined
Any ideas?
Arguments become false
@canreo
current($args) returns false when it is called with an empty array as an argument. Whereas the argument 2 of getCommand expects array.
http://php.net/manual/en/function.current.php
What I tried to fix this was adding the below code just above the try block, after calling current()
if($args == false){ $args = array(); }
Though not the best of solutions, it helped me overcome this problem.
Fatal error
Hi, i got below error when i tried to run the page. I have followed all the instructions above. Please anyone do me a favour. I am in the need of this extension.
Error : Fatal error: Cannot redeclare class Aws\Common\Enum\ClientOptions in phar:///home2/rifluxyss3/public_html/demo.rifluxyss.com/T2/ARCHIEVE/yiiapp/protected/lib/aws.phar/src/Aws/Common/Enum/ClientOptions.php on line 25
Thanks
Waiters not functional
Firstly, thanks so much for the extension. It's much better than what I was doing (setting path aliases).
I tried to use the waiter functions, but I'm getting an error:
exception 'CException' with message 'Command was not found matching WaitUntilInstanceRunning' in /var/www/registration/protected/vendor/2amigos/yii-aws/components/A2Base.php:109
Issue with some AWS API functions
I get same issue like @jbowler, waiter functions not working and also I found some other functions too. I fix it by accessing direct AWS object and use its native functions, but than I not see too much reason to not switch to native SDK.
Here is how I handle it:
$s3 = new A2S3(); ... $s3->getClient()->waitUntilObjectExists(array( 'Bucket' => 'mybucket', 'Key' => 'myimage.png' ));
(y)
Nice !!
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.