Package Data | |
---|---|
Maintainer Username: | mtdowling |
Package Create Date: | 2013-02-13 |
Package Last Update: | 2024-09-12 |
Home Page: | http://aws.amazon.com/sdkforphp/ |
Language: | PHP |
License: | Apache-2.0 |
Last Refreshed: | 2024-12-11 15:20:34 |
Package Statistics | |
---|---|
Total Downloads: | 26,780,743 |
Monthly Downloads: | 495,739 |
Daily Downloads: | 23,526 |
Total Stars: | 1,660 |
Total Watchers: | 83 |
Total Forks: | 243 |
Total Open Issues: | 4 |
This is a simple Laravel service provider for making it easy to include the official AWS SDK for PHP in your Laravel and Lumen applications.
This README is for version 3.x of the service provider, which is implemented to work with Version 3 of the AWS SDK for PHP and Laravel 5.1.
Major Versions:
laravel/framework:~5.1
and aws/aws-sdk-php:~3.0
laravel/framework:5.0.*
and aws/aws-sdk-php:~2.4
laravel/framework:4.*
and aws/aws-sdk-php:~2.4
The AWS Service Provider can be installed via Composer by requiring the
aws/aws-sdk-php-laravel
package in your project's composer.json
.
{
"require": {
"aws/aws-sdk-php-laravel": "~3.0"
}
}
Then run a composer update
php composer.phar update
To use the AWS Service Provider, you must register the provider when bootstrapping your application.
In Lumen find the Register Service Providers
in your bootstrap/app.php
and register the AWS Service Provider.
$app->register(Aws\Laravel\AwsServiceProvider::class);
In Laravel find the providers
key in your config/app.php
and register the AWS Service Provider.
'providers' => array(
// ...
Aws\Laravel\AwsServiceProvider::class,
)
Find the aliases
key in your config/app.php
and add the AWS facade alias.
'aliases' => array(
// ...
'AWS' => Aws\Laravel\AwsFacade::class,
)
By default, the package uses the following environment variables to auto-configure the plugin without modification:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION (default = us-east-1)
To customize the configuration file, publish the package configuration using Artisan.
php artisan vendor:publish --provider="Aws\Laravel\AwsServiceProvider"
The settings can be found in the generated config/aws.php
configuration file. By default, the credentials and region settings will pull from your .env
file.
return [
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID', ''),
'secret' => env('AWS_SECRET_ACCESS_KEY', ''),
],
'region' => env('AWS_REGION', 'us-east-1'),
'version' => 'latest',
// You can override settings for specific services
'Ses' => [
'region' => 'us-east-1',
],
];
Note that you can always delete the credentials
line from this file if you'd like to use the default SDK Configuration Provider chain instead.
Referring Laravel 5.2.0 Upgrade guide, you must using config
file instead of environment variable option if using php artisan config:cache
.
Learn more about configuring the SDK on the SDK's User Guide.
In order to use the AWS SDK for PHP within your app, you need to retrieve it from the Laravel IoC Container. The following example uses the Amazon S3 client to upload a file.
$s3 = App::make('aws')->createClient('s3');
$s3->putObject(array(
'Bucket' => 'YOUR_BUCKET',
'Key' => 'YOUR_OBJECT_KEY',
'SourceFile' => '/the/path/to/the/file/you/are/uploading.ext',
));
If the AWS facade is registered within the aliases
section of the application configuration, you can also use the
following technique.
$s3 = AWS::createClient('s3');
$s3->putObject(array(
'Bucket' => 'YOUR_BUCKET',
'Key' => 'YOUR_OBJECT_KEY',
'SourceFile' => '/the/path/to/the/file/you/are/uploading.ext',
));