This extension provides the AWS SDK integration for the Yii2 framework

Installs: 32

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0


dev-master 2019-04-09 14:02 UTC

This package is not auto-updated.

Last update: 2022-06-22 01:11:12 UTC


This extension provides the AWS SDK 3 integration for the Yii2 framework

Latest Stable Version Total Downloads Latest Unstable Version License


The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist alkurn/yii2-aws "dev-master"

or add

"alkurn/yii2-aws": "dev-master"

to the require section of your composer.json file.

Note: You can still use AWS version 2 if you specify alkurn/yii2-aws "dev-master"


To use this extension, simply add the following code in your application configuration:

return [
    'components' => [
        's3' => [
            'class' => 'alkurn\aws\S3',
            'credentials' => [ //you can use a different method to grant access
                'key' => 'your-aws-key',
                'secret' => 'your-aws-secret',
            'region' => 'your-aws-region', //i.e.: 'us-east-1'
            'version' => 'your-aws-version', //i.e.: 'latest'

Getting all balancer names from AWS:

$aws = Yii::$app->s3->getS3();
$elb = $aws->createElasticloadbalancing();
$load_balancers = $elb->describeLoadBalancers()->toArray();
if (isset($load_balancers['LoadBalancerDescriptions'])){
    foreach ($load_balancers['LoadBalancerDescriptions'] as $balancer){
        if (isset($balancer['LoadBalancerName'])){ 
            echo $balancer['LoadBalancerName'];

Download an object from S3:

//specify the region if it is different than the main configuration region
Yii::$app->awssdk->region = 'sa-east-1';
$aws = Yii::$app->s3->getS3();

//use s3
$s3 = $aws->createS3();
$result = $s3->listObjects(['Bucket' => 'your-bucket-id',"Prefix" => "your-path"])->toArray();
//get the last object from s3
$object = end($result['Contents']);
$key = $object['Key'];
$file = $s3->getObject([
    'Bucket' => 'your-bucket-id',
    'Key' => $key
//download the file
header('Content-Type: ' . $file['ContentType']);
echo $file['Body'];