icyxp / lumen-aws-sdk

0 stars 0 forks source link

AWS Service Provider for Lumen 5

This is a simple Lumen service provider for making it easy to include the official AWS SDK for PHP in your Lumen applications.

This README is for version 1.x of the service provider, which is implemented to work with Version 3 of the AWS SDK for PHP and Lumen 5.X.

Installation

The AWS Service Provider can be installed via Composer by requiring the icyboy/lumen-aws-sdk package in your project's composer.json.

{
    "require": {
        "icyboy/lumen-aws-sdk": "^1.0"
    }
}

Then run a composer update

php composer.phar update

To use the AWS Service Provider, you must register the provider when bootstrapping your Lumen application.

Find the providers key in your bootstarp/app.php and register the AWS Service Provider.

    $app->register(Icyboy\LumenAws\AwsServiceProvider::class);

    class_alias('Icyboy\LumenAws\AwsFacade', 'Aws');

Configuration

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

Update your settings in the generated config/aws.php configuration file.

return [
    'credentials' => [
        'key'    => 'YOUR_AWS_ACCESS_KEY_ID',
        'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
    ],
    'region' => 'us-west-2',
    'version' => 'latest',

    // You can override settings for specific services
    'Ses' => [
        'region' => 'us-east-1',
    ],

    // if you use fake s3, you must used endpoint
    'endpoint' => "http://xxxx",
];

Usage

$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',
));

Links