Skip to content

Latest commit

 

History

History
297 lines (231 loc) · 10.4 KB

File metadata and controls

297 lines (231 loc) · 10.4 KB

Amazon Web Services Bundle

This is a Symfony2 Bundle for interfacing with Amazon Web Services (AWS).

AWS SDK for PHP

This bundle utilizes the AWS SDK for PHP by loading the SDK and providing the means to instantiate the SDK's various web service objects, passing them back to you for direct use.

The AWS SDK for PHP is the the official Amazon-supported library for interfacing with with Amazon's Web Service offerings. As such, the bundle merely provides a means (via Dependency Injection) to get at the SDK's various web service objects. There is no additional functionality at present time.

Once objects have been created, you have full access to the SDK. Please see the AWS SDK for PHP documentation for a list of each service's API calls.

Installation

AmazonWebServicesBundle may be installed via the deps file (Symfony 2.0.x) or via Composer (2.1+)

  1. Via Composer

Go to the require section of your composer.json file and add

"thephalcons/amazon-webservices-bundle": ">=2.1"

OR using command line

composer require thephalcons/amazon-webservices-bundle

to the section, along with other packages you require. Now run composer.phar install if this is a new installation, or composer.phar update if you are updating an existing installation.

  1. Add AmazonWebServicesBundle to your application kernel:
<?php

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new AmazonWebServicesBundle\ThePhalconsAmazonWebServicesBundle(),
        // ...
    );
}
  1. If you are using Composer (1b), you may skip this step

Register the ThePhalcons namespace:

<?php

// app/autoload.php
$loader->registerNamespaces(array(
    // ...
    'ThePhalcons' => __DIR__.'/../vendor/bundles',
    // ...
));
  1. Run bin/vendors install to have Symfony download and install the packages

  2. Set up your configuration.

5a) First configure your parameters.ini:

// app/config/parameters.ini
[parameters]
    ...

    ; Amazon Web Services Configuration. Found in the AWS Security Credentials.
    aws_key                        = YOUR_KEY
    aws_secret                     = YOUR_SECRET_KEY
    aws_account_id                 = YOUR_ACCOUNT_ID
    aws_canonical_id               = YOUR_CONONICAL_ID
    aws_canonical_name             = YOUR_CONONICAL_NAME
    aws_mfa_serial                 = YOUR_MFA_SERIAL
    aws_cloudfront_keypair         = YOUR_CLOUDFRONT_KEYPAIR_ID
    aws_cloudfront_pem             = YOUR_CLOUDFRONT_PRIVATE_KEY_PEM
    aws_region                     = YOUR_REGION
    aws_version                    = 'latest' #or YOUR_VERSION 

Note, presently only aws_key and aws_secret are being used when constructing objects. Setting them is fine, but it won't do anything.

aws_cloudfront_pem should be contents of your pem file, including startline and endline. To work with multiline add double quotes. Example:

  aws_cloudfront_private_key_pem = "-----BEGIN RSA PRIVATE KEY-----
*private key goes here*
-----END RSA PRIVATE KEY-----"

5b) Set up your application configuration:

// app/config/config.yml
# Amazon Web Services Configuration
the_phalcons_amazon_web_services:
    # for stream wrapper use : [S3, SES ...]
    enable_extensions:              []
    credentials:
        key:                        <YOUR APP KEY>
        secret:                     <YOUT APP SECRET>
    shared_config:
        region:                     %aws_region%
        version:                    %aws_version%
        account_id:                 %aws_account_id%
        canonical_id:               %aws_canonical_id%
        canonical_name:             %aws_canonical_name%
        mfa_serial:                 %aws_mfa_serial%
        cloudfront_keypair:         %aws_cloudfront_keypair%
        cloudfront_pem:             %aws_cloudfront_pem%
        default_cache_config:       null
        certificate_authority:      false
        disable_auto_config:        false

Note, as in 5a) above, only the key and secret are presently being used, so it is safe to omit the rest if you wish.

The AWS SDK by default looks for configuration files in various standard locations. If they're not found, error messages are emitted to the web server's log, though performance is not impacted. If you do not use the auto-configuration and wish to suppress the error messages, enable the disable_auto_config option.

You're welcome to skip setting the configurations in parameters.ini (5a) and set the values directly in config.yml, however, the setup shown here is following the example that Sensio used for Symfony with regards to database setup, and keeping the actual private configuration values in parameters.ini and utilizing them in config.yml.

Usage

Once installed, you simply need to request the appropriate service for the Amazon Web Service object you wish to use. The returned object will then allow you full access the the API for the requested service.

Please see the AWS SDK for PHP documentation for a list of each service's API calls.

In this example, we get an AmazonSQS object from the AWS SDK for PHP library by requesting the aws_sqs service. We then use that object to retrieve a message from an existing Amazon SQS queue.

<?php

// src/Acme/DemoBundle/Controller/YourController.php
public function someAction()
{
    // Get a AmazonSQS object
    $sqs = $this->container->get('aws_sqs');

    // Get a message from an existing queue
    $response = $sqs->receive_message($queueUrl);

    // Do stuff with the received message response object
    // ...
}

Available Services

The following services are available, each returning an object allowing access to the respective Amazon Web Service

Please note, at this time, thorough testing has not been completed. Because this bundle merely creates object from the SDK and passes them though to you, there shouldn't be any issues. However, this message is here as warning, just in case. In the event that a bug exists within the bundle's service definitions (and not within the SDK itself), please let me know!

Symfony Service Name AWS SDK for PHP Object Description
aws_as AmazonAS Amazon Auto Scaling
aws_cloud_formation AmazonCloudFormation Amazon CloudFormation
aws_cloud_front AmazonCloudFront Amazon CloudFront
aws_cloud_search AmazonCloudSearch Amazon CloudSearch
aws_cloud_watch AmazonCloudWatch Amazon CloudWatch
aws_dynamo_db AmazonDynamoDB Amazon DynamoDB
aws_ec2 AmazonEC2 Amazon Elastic Compute Cloud (EC2)
aws_elb AmazonELB Amazon Elastic Load Balancing
aws_emr AmazonEMR Amazon Elastic MapReduce
aws_elasti_cache AmazonElastiCache Amazon ElastiCache
aws_elastic_beanstalk AmazonElasticBeanstalk Amazon Elastic Beanstalk
aws_iam AmazonIAM Amazon Identity and Access Management
aws_import_export AmazonImportExport Amazon Import/Export
aws_rds AmazonRDS Amazon Relational Database Service
aws_s3 AmazonS3 Amazon Simple Storage Service (S3)
aws_sdb AmazonSDB Amazon SimpleDB
aws_ses AmazonSES Amazon Simple Email Service
aws_sns AmazonSNS Amazon Simple Notification Service
aws_sqs AmazonSQS Amazon Simple Queue Service
aws_sts AmazonSTS Amazon Security Token Service
aws_swf AmazonSWF Amazon Simple Workflow
aws_Route53 AmazonRoute53 Amazon Route 53