fedemotta/yii2-aws-sdk
最新稳定版本:v2.0
Composer 安装命令:
composer require fedemotta/yii2-aws-sdk
包简介
This extension provides the AWS SDK integration for the Yii2 framework
README 文档
README
This extension provides the AWS SDK 3 integration for the Yii2 framework
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fedemotta/yii2-aws-sdk "*"
or add
"fedemotta/yii2-aws-sdk": "*"
to the require section of your composer.json file.
Note: You can still use AWS version 2 if you specify fedemotta/yii2-aws-sdk "1.*"
Usage
To use this extension, simply add the following code in your application configuration:
return [ //.... 'components' => [ 'awssdk' => [ 'class' => 'fedemotta\awssdk\AwsSdk', '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->awssdk->getAwsSdk(); $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->awssdk->getAwsSdk(); //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'];
统计信息
- 总下载量: 411.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-16