PHPackages                             andrewfenn/aws-helper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. andrewfenn/aws-helper

ActiveLibrary[File &amp; Storage](/categories/file-storage)

andrewfenn/aws-helper
=====================

A small helper library to make intergration of the AWS SDK easier

0.3.0(10y ago)11.2kMITPHPPHP &gt;=5.5

Since May 26Pushed 10y ago1 watchersCompare

[ Source](https://github.com/andrewfenn/awshelper)[ Packagist](https://packagist.org/packages/andrewfenn/aws-helper)[ Docs](https://github.com/andrewfenn/awshelper/)[ RSS](/packages/andrewfenn-aws-helper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

AWS Helper
==========

[](#aws-helper)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/376e8598f36c924bb6789442e8e653f066680f61820e8f3cfc8935870579d6d3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616e6472657766656e6e2f61777368656c7065722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/andrewfenn/awshelper)

[![Total Downloads](https://camo.githubusercontent.com/46be4db4c2c560e7be46fcc2b2782beb23d86ebd3e25db32df7133f4da1e0f54/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f616e6472657766656e6e2f6177732d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewfenn/aws-helper)[![Total Downloads](https://camo.githubusercontent.com/9369dcd0e09a94f6097a32457db32326d896b6e2bf585b55f3c0029bd271c407/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f616e6472657766656e6e2f6177732d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewfenn/aws-helper)[![Total Downloads](https://camo.githubusercontent.com/2ce780d051a2c05cea9f6efe37a0a06d7514dbc2babb1e22e776f8ab64f71a2e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e6472657766656e6e2f6177732d68656c7065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewfenn/aws-helper)

This library is an extension of the AWS SDK to make it easier to intergrate AWS security token service where you refresh the access and secret token via the AWS API on the server itself.

This is better than having a static access and secret key as it constantly changes and only your server on AWS can get access to this information. I have provided a small step by step list below on how to set this up on your AWS account.

It's not meant to be an all inclusive library that can do everything, if you need more advanced use cases then please consider using the AWS SDK directly.

### How to install

[](#how-to-install)

Add the following to your composer.json file and run `composer update`.

```
    "require": {
        "andrewfenn/aws-helper": "0.3.0"
    }
```

This library is set up to use amazon's roles for getting the access and secret key. If you don't want to do this then, for example you're developing on your own system outside of AWS then see below.

### How to setup your AWS account

[](#how-to-setup-your-aws-account)

If you wish to use amazon's roles so that you're not storing the access or secret key to your services in the code base, do the following.

- Login to your amazon console
- Go to Identity and Access Management
- Click the Roles link
- Create a new role, open it up and click on "attach role policy"
- Select from the policy template for the service you wish to use i.e. "Amazon S3 Full Access", "Amazon SQS Full Access"
- Add the role name you created to the "iam\_role" configuration option

Once you've done these steps the key, secret, and security tokens will be downloadable from the a url inside amazon's infrastructure that will provide your server with access.

### How to setup for development outside of amazon

[](#how-to-setup-for-development-outside-of-amazon)

For local development make a file like below called development.json

```
{
  "Code" : "Success",
  "LastUpdated" : "2015-02-06T07:50:20Z",
  "AccessKeyId" : "",
  "SecretAccessKey" : "",
  "Token" : "",
  "Expiration" : "2030-02-19T04:45:53+00:00"
}
```

Change the AccessKeyId, and SecretAccessKey fields to your appropiate settings. Make sure the Expiration date is a date in the future or the code will attempt to grab a new key every time you run your code.

```
$awsHelper = new AwsHelper('development.json', 'http://url-to-root-folder-with-file/');
```

*I recommend you do not commit the development.json file*. This file should sit somewhere secure that only your development team can access as it contains your AWS Access and Secret key details.

### Quick use of the S3 Helper

[](#quick-use-of-the-s3-helper)

To use the S3 helper library you'll do something similar as below.

A quick note that $file\_pointer returns a file pointer instead of the contents of the file as a design choice, as some files may be too big to fit into PHP memory. Please also consider this when using this code so that you don't make mistakes in loading huge files into PHP.

```
