Slide 1

Slide 1 text

Amazon Web Services for PHP Developers

Slide 2

Slide 2 text

Oh Hai! I'm Jeremy Lindblom! •  I work on the AWS SDK for PHP at •  Co-organizer of the Seattle PHP Meetup Group •  B.S. in Computer Science from •  @jeremeamia on •  I like to make funny faces

Slide 3

Slide 3 text

What is "The Cloud"?

Slide 4

Slide 4 text

Cloud computing is the acquisition and use of computing resources that are delivered as a service on an as-needed basis.

Slide 5

Slide 5 text

"The Cloud" •  Evolution of distributed computing and Service-oriented Architecture (SOA). •  Benefits – No upfront investment – Low ongoing cost – Flexible capacity – Speed & agility – Apps not ops – Global reach ( http://aws.amazon.com/what-is-cloud-computing/ )

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Bringing you the “The Cloud” since 2006.

Slide 8

Slide 8 text

Amazon Web Services offers a complete set of infrastructure and application services that enable you to run virtually everything in the cloud: from enterprise applications and big data projects to social games and mobile apps. ( http://aws.amazon.com )

Slide 9

Slide 9 text

Amazon CloudFormation Amazon CloudFront Amazon CloudSearch Amazon CloudWatch Amazon Direct Connect Amazon DynamoDB Amazon EBS Amazon EC2 Amazon ElastiCache Amazon Elastic Transcoder Amazon EMR Amazon Glacier Amazon IAM Amazon Mechanical Turk Amazon RDS Amazon Redshift Amazon Route53 Amazon S3 Amazon SES Amazon SimpleDB Amazon SNS Amazon SQS Amazon SWF Amazon VPC AWS CloudHSM AWS Data Pipeline AWS Elastic Beanstalk AWS Import/Export AWS Marketplace AWS OpsWorks AWS Storage Gateway AWS Support Auto Scaling Elastic Load Balancing

Slide 10

Slide 10 text

Amazon CloudFormation Amazon CloudFront Amazon CloudSearch Amazon CloudWatch Amazon Direct Connect Amazon DynamoDB Amazon EBS Amazon EC2 Amazon ElastiCache Amazon Elastic Transcoder Amazon EMR Amazon Glacier Amazon IAM Amazon Mechanical Turk Amazon RDS Amazon Redshift Amazon Route53 Amazon S3 Amazon SES Amazon SimpleDB Amazon SNS Amazon SQS Amazon SWF Amazon VPC AWS CloudHSM AWS Data Pipeline AWS Elastic Beanstalk AWS Import/Export AWS Marketplace AWS OpsWorks AWS Storage Gateway AWS Support Auto Scaling Elastic Load Balancing

Slide 11

Slide 11 text

Amazon CloudFormation Amazon CloudFront Amazon CloudSearch Amazon CloudWatch Amazon Direct Connect Amazon DynamoDB Amazon EBS Amazon EC2 Amazon ElastiCache Amazon Elastic Transcoder Amazon EMR Amazon Glacier Amazon IAM Amazon Mechanical Turk Amazon RDS Amazon Redshift Amazon Route53 Amazon S3 Amazon SES Amazon SimpleDB Amazon SNS Amazon SQS Amazon SWF Amazon VPC AWS CloudHSM AWS Data Pipeline AWS Elastic Beanstalk AWS Import/Export AWS Marketplace AWS OpsWorks AWS Storage Gateway AWS Support Auto Scaling Elastic Load Balancing 2+ trillion objects

Slide 12

Slide 12 text

Amazon CloudFormation Amazon CloudFront Amazon CloudSearch Amazon CloudWatch Amazon Direct Connect Amazon DynamoDB Amazon EBS Amazon EC2 Amazon ElastiCache Amazon Elastic Transcoder Amazon EMR Amazon Glacier Amazon IAM Amazon Mechanical Turk Amazon RDS Amazon Redshift Amazon Route53 Amazon S3 Amazon SES Amazon SimpleDB Amazon SNS Amazon SQS Amazon SWF Amazon VPC AWS CloudHSM AWS Data Pipeline AWS Elastic Beanstalk AWS Import/Export AWS Marketplace AWS OpsWorks AWS Storage Gateway AWS Support Auto Scaling Elastic Load Balancing NEW!

Slide 13

Slide 13 text

Amazon CloudFormation Amazon CloudFront Amazon CloudSearch Amazon CloudWatch Amazon Direct Connect Amazon DynamoDB Amazon EBS Amazon EC2 Amazon ElastiCache Amazon Elastic Transcoder Amazon EMR Amazon Glacier Amazon IAM Amazon Mechanical Turk Amazon RDS Amazon Redshift Amazon Route53 Amazon S3 Amazon SES Amazon SimpleDB Amazon SNS Amazon SQS Amazon SWF Amazon VPC AWS CloudHSM AWS Data Pipeline AWS Elastic Beanstalk AWS Import/Export AWS Marketplace AWS OpsWorks AWS Storage Gateway AWS Support Auto Scaling Elastic Load Balancing Compute & Networking Storage & Content Delivery Databases Application Services Deployment & Management

Slide 14

Slide 14 text

Customers in 190 Countries

Slide 15

Slide 15 text

Customers in 190 Countries 37 Signals Airbnb Engine Yard Etsy Flipboard Foursquare Hoot Suite IMDb Outback Steakhouse PBS Pinterest Reddit Samsung Sega Shazam Spotify Ticketmaster Yelp

Slide 16

Slide 16 text

How do I use AWS?

Slide 17

Slide 17 text

AWS Console

Slide 18

Slide 18 text

AWS SDKs and Tools PHP • Java • Python • .NET Ruby • Node.js • iOS • Android SDKs Unified CLI • Visual Studio Plugin Eclipse Plugin • PowerShell Tools Tools

Slide 19

Slide 19 text

General SDK Features •  Suite of HTTP clients •  Input and output serialization •  Protocol normalization •  Authentication •  Error handling •  Language-specific conveniences •  Open source

Slide 20

Slide 20 text

The AWS SDK for PHP http://github.com/aws/aws-sdk-php

Slide 21

Slide 21 text

Quick History •  Tarzan (Started by @skyzyx) •  CloudFusion •  AWS SDK for PHP [2010] •  AWS SDK for PHP 2 [Late 2012]

Slide 22

Slide 22 text

AWS SDK for PHP Features •  PHP 5.3+, PSR compliant •  Persistent connections, parallel requests •  Event hooks, plugins, and wire logging •  Simple array-style inputs and outputs •  Iterators, waiters, and batching helpers •  Higher-level abstractions

Slide 23

Slide 23 text

require  'vendor/autoload.php';   use  Aws\S3\S3Client;     $s3  =  S3Client::factory(array(        'key'        =>  'your-­‐aws-­‐access-­‐key-­‐id',      'secret'  =>  'your-­‐aws-­‐secret-­‐key',   ));     $result  =  $s3-­‐>putObject(array(      'Bucket'  =>  'my-­‐cool-­‐photos',      'Key'        =>  'photo.jpg',      'Body'      =>  fopen('./photo.jpg',  'r')   ));  

Slide 24

Slide 24 text

Built on Guzzle •  Popular HTTP Library – Goutte – AWS SDK for PHP J – Drupal 8 •  Foundation of the SDK •  Symfony2 Events •  http://guzzlephp.org

Slide 25

Slide 25 text

Installing the PHP SDK •  Composer •  PEAR •  Downloadable Phar •  RPM/yum (on Amazon Linux)

Slide 26

Slide 26 text

Composer •  Dependency management •  Autoloader for project •  http://getcomposer.org

Slide 27

Slide 27 text

Installing via Composer In your composer.json file:   {      "require":  {          "aws/aws-­‐sdk-­‐php":  "2.*"      }   }   On the command line. php  composer.phar  install  

Slide 28

Slide 28 text

Concepts in the SDK •  Commands •  Modeled Results •  Iterators •  Waiters •  Events & Plugins •  High-level Abstractions

Slide 29

Slide 29 text

Commands •  Encapsulates an operation to AWS •  Contains Request and Response objects •  Allows you set and get parameters •  Returns modeled results

Slide 30

Slide 30 text

Commands - Shorthand $result  =  $s3-­‐>listObjects(array(      'Bucket'  =>  'my-­‐bucket-­‐name'   ));     echo  $result['Objects'][0]['Key'];  

Slide 31

Slide 31 text

$command  =  $s3-­‐>getCommand('ListObjects');   $command-­‐>set('Bucket',  'my-­‐bucket-­‐name');     $result  =  $command-­‐>getResult();   echo  $result['Contents'][0]['Key'];     $response  =  $command-­‐>getResponse();   echo  $response-­‐>getStatusCode();   echo  $response-­‐>getHeader('Content-­‐Length');     The Command Object

Slide 32

Slide 32 text

$c1  =  $s3-­‐>getCommand('PutObject',  array(      'Bucket'  =>  'my-­‐bucket-­‐name',      'Key'        =>  'my-­‐first-­‐key',      'Body'      =>  fopen('path/to/file1',  'r')   ));   $c2  =  $s3-­‐>getCommand('PutObject',  array(      'Bucket'  =>  'my-­‐bucket-­‐name',      'Key'        =>  'my-­‐second-­‐key',      'Body'      =>  fopen('path/to/file2',  'r')   ));     $s3-­‐>execute(array($c1,  $c2));   Parallel Commands

Slide 33

Slide 33 text

Modeled Results •  Array-like object •  Follows schema from service description •  Convenience methods like getPath()   $result  =  $s3-­‐>listBuckets();     $result['Buckets'][0]['Name'];   $result-­‐>get('Buckets');   $result-­‐>getPath('Buckets/0/Name');   $result-­‐>get('Buckets');   print_r($result-­‐>toArray());  

Slide 34

Slide 34 text

Waiters •  Poll resources until available •  Handle asynchronous and eventually consistent operations more easily $s3-­‐>createBucket(array(      'Bucket'  =>  'my-­‐bucket'   ));   $s3-­‐>waitUntilBucketExists(array(      'Bucket'  =>  'my-­‐bucket'   ));  

Slide 35

Slide 35 text

Iterators •  Iterate through entire result sets •  No handling of markers or tokens •  Uses SPL iterators and interfaces $list  =  $s3-­‐>getIterator('ListObjects',  [      'Bucket'  =>  'my-­‐bucket'   ]);   foreach  ($list  as  $object)  {      echo  $object['Key']  .  PHP_EOL;   }  

Slide 36

Slide 36 text

SDK 1.x – Before Iterators $dynamo_db  =  new  AmazonDynamoDB();   $start_key  =  null;   $people  =  array();       do  {      $params  =  array(          'TableName'  =>  'people',      );          if  ($start_key)  {        $params['ExclusiveStartKey']  =  array(            'HashKeyElement'  =>  array(                'S'  =>  $start_key            )        );        $start_key  =  null;    }      $response  =  $dynamo_db-­‐>scan($params);    if  ($response-­‐>isOK())  {        foreach  ($response-­‐>body-­‐>Items  as   $item)  {            echo  (string)  $item-­‐>name-­‐>S;        }                  if  ($response-­‐>body-­‐>LastEvaluatedKey)  {            $start_key  =  (string)  $response-­‐>body-­‐ >LastEvaluatedKey-­‐>HashKeyElement-­‐>S;        }      }  else  {                  throw  new  DynamoDB_Exception('DynamoDB   Scan  operation  failed.');    } }  while  ($start_key);

Slide 37

Slide 37 text

SDK 1.x – Before Iterators $dynamo_db  =  new  AmazonDynamoDB();   $start_key  =  null;   $people  =  array();       do  {      $params  =  array(          'TableName'  =>  'people',      );          if  ($start_key)  {        $params['ExclusiveStartKey']  =  array(            'HashKeyElement'  =>  array(                'S'  =>  $start_key            )        );        $start_key  =  null;    }      $response  =  $dynamo_db-­‐>scan($params);    if  ($response-­‐>isOK())  {        foreach  ($response-­‐>body-­‐>Items  as   $item)  {            echo  (string)  $item-­‐>name-­‐>S;        }                  if  ($response-­‐>body-­‐>LastEvaluatedKey)  {            $start_key  =  (string)  $response-­‐>body-­‐ >LastEvaluatedKey-­‐>HashKeyElement-­‐>S;        }      }  else  {                  throw  new  DynamoDB_Exception('DynamoDB   Scan  operation  failed.');    } }  while  ($start_key);

Slide 38

Slide 38 text

$db  =  $aws-­‐>get('DynamoDb');     $scan  =  $db-­‐>getIterator('Scan',  array(      'TableName'              =>  'People',      'AttributesToGet'  =>  array('Id',  'Name')   ));     foreach  ($scan  as  $person)  {      echo  $item['Name']['S'];   }     Example: Scan Iterator

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Events & Event Listeners •  Event slots in various parts of SDK •  Inject logic without extending classes •  Symfony2 Event Dispatcher $s3-­‐>getEventDispatcher()        -­‐>addListener('',  );  

Slide 41

Slide 41 text

Plugins •  Implemented as event listeners •  Many built-in plugins from Guzzle including easy wire logging use  Guzzle\Plugin\Log\LogPlugin;   $s3-­‐>addSubscriber(          LogPlugin::getDebugPlugin()   );  

Slide 42

Slide 42 text

Higher-level Abstractions •  S3 Multipart Uploader •  S3 Stream Wrapper •  DynamoDB Session Handler •  DynamoDB WriteRequestBatch •  SNS Message Validator •  Third-party Modules: ZF2, Silex, Laravel

Slide 43

Slide 43 text

$s3  =  $aws-­‐>get('S3');   $uploader  =  UploadBuilder::newInstance()      -­‐>setClient($s3)      -­‐>setSource('/path/to/large/file.mov')      -­‐>setBucket('my-­‐bucket')      -­‐>setKey('my-­‐object-­‐key')      -­‐>setConcurrency(3)      -­‐>build();   Multipart Uploader

Slide 44

Slide 44 text

http://aws.amazon.com/sdkforphp/ https://github.com/aws/aws-sdk-php

Slide 45

Slide 45 text

PHP Apps on AWS

Slide 46

Slide 46 text

•  http://aws.amazon.com/architecture/ – Reference architectures •  http://awsofa.info/ – Obama for America architecture

Slide 47

Slide 47 text

Hosting •  AWS Elastic Beanstalk •  AWS OpsWorks •  AWS CloudFormation •  Amazon EC2 +  Auto Scaling +  Elastic Load Balancer +  Amazon CloudWatch Easiest to setup Easiest to customize

Slide 48

Slide 48 text

Databases •  Amazon RDS – Relational Databases •  Amazon DynamoDB – NoSQL Database •  Amazon Redshift – Data Warehousing •  Amazon ElastiCache – Memcache

Slide 49

Slide 49 text

File Storage & Delivery •  Amazon S3 – General Storage •  Amazon EBS – Detachable Storage Volumes •  Amazon Glacier – Archiving •  Amazon CloudFront – Global CDN

Slide 50

Slide 50 text

Sessions •  Amazon RDS •  Amazon DynamoDB (via PHP SDK) •  Amazon ElastiCache (custom extension) •  Elastic Load Balancer ("sticky sessions") –  http://docs.aws.amazon.com/ElasticLoadBalancing/latest/ DeveloperGuide/US_StickySessions.html

Slide 51

Slide 51 text

Other •  Message Passing – Amazon SQS, Amazon SNS •  Sending Emails – Amazon SES •  Workflows – Amazon SWF, AWS Data Pipeline •  Monitoring – Amazon CloudWatch •  Big Data Processing – Amazon EMR •  DNS Management – Amazon Route 53 •  Search – Amazon CloudSearch There's an app a service for that!

Slide 52

Slide 52 text

Simple Funny Face Sharing App on AWS Elastic Beanstalk

Slide 53

Slide 53 text

Funny Face Sharing App •  AWS Elastic Beanstalk – Amazon EC2 – Auto Scaling – Elastic Load Balancer – Amazon CloudWatch •  Amazon S3 •  Amazon DynamoDB

Slide 54

Slide 54 text

Questions? @jeremeamia Try out "The Cloud", AWS, and the AWS SDK for PHP