icyxp / lumen-aws-sdk by icyboy

A simple lumen 5 service provider for including the AWS SDK for PHP.
13,899
0
3
Package Data
Maintainer Username: icyboy
Package Create Date: 2016-11-01
Package Last Update: 2016-11-01
Language: PHP
License: Apache-2.0
Last Refreshed: 2024-11-15 15:11:55
Package Statistics
Total Downloads: 13,899
Monthly Downloads: 87
Daily Downloads: 0
Total Stars: 0
Total Watchers: 3
Total Forks: 0
Total Open Issues: 1

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