Amazon Web Services for PHP Developers
-
Upload
jeremy-lindblom -
Category
Technology
-
view
1.559 -
download
0
description
Transcript of Amazon Web Services for PHP Developers
![Page 1: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/1.jpg)
Amazon Web Services for PHP Developers
![Page 2: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/2.jpg)
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
![Page 3: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/3.jpg)
What is "The Cloud"?
![Page 4: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/4.jpg)
Cloud computing is the acquisition and use of computing resources that are delivered as a service on an as-needed basis.
![Page 5: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/5.jpg)
"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/ )
![Page 6: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/6.jpg)
![Page 7: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/7.jpg)
Bringing you the “The Cloud” since 2006.
![Page 8: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/8.jpg)
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 )
![Page 9: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/9.jpg)
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
![Page 10: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/10.jpg)
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
![Page 11: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/11.jpg)
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!
![Page 12: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/12.jpg)
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
![Page 13: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/13.jpg)
Customers in 190 Countries
![Page 14: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/14.jpg)
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
![Page 15: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/15.jpg)
How do I use AWS?
![Page 16: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/16.jpg)
AWS Console
![Page 17: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/17.jpg)
AWS SDKs and Tools
PHP • Java • Python • .NET
Ruby • Node.js • iOS • Android
SDKs
Unified CLI • Visual Studio Plugin
Eclipse Plugin • PowerShell Tools
Tools
![Page 18: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/18.jpg)
General SDK Features
• Suite of HTTP clients
• Input and output serialization
• Protocol normalization
• Authentication
• Error handling
• Language-specific conveniences
• Open source
![Page 19: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/19.jpg)
The AWS SDK for PHP
http://github.com/aws/aws-sdk-php
![Page 20: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/20.jpg)
Quick History
• Tarzan (Started by @skyzyx)
• CloudFusion
• AWS SDK for PHP [2010]
• AWS SDK for PHP 2 [Late 2012]
![Page 21: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/21.jpg)
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
![Page 22: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/22.jpg)
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') ));
![Page 23: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/23.jpg)
Built on Guzzle
• Popular HTTP Library – Goutte – AWS SDK for PHP J – Drupal 8
• Foundation of the SDK
• Symfony2 Events
• http://guzzlephp.org
![Page 24: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/24.jpg)
Installing the PHP SDK
• Composer
• PEAR
• Downloadable Phar
• RPM/yum (on Amazon Linux)
![Page 25: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/25.jpg)
Composer
• Dependency management
• Autoloader for project
• http://getcomposer.org
![Page 26: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/26.jpg)
Installing via Composer
In your composer.json file: { "require": { "aws/aws-‐sdk-‐php": "2.*" } }
On the command line. php composer.phar install
![Page 27: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/27.jpg)
Concepts in the SDK
• Commands
• Modeled Results
• Iterators
• Waiters
• Events & Plugins
• High-level Abstractions
![Page 28: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/28.jpg)
Commands
• Encapsulates an operation to AWS
• Contains Request and Response objects
• Allows you set and get parameters
• Returns modeled results
![Page 29: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/29.jpg)
Commands - Shorthand
$result = $s3-‐>listObjects(array( 'Bucket' => 'my-‐bucket-‐name' )); echo $result['Objects'][0]['Key'];
![Page 30: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/30.jpg)
$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
![Page 31: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/31.jpg)
$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
![Page 32: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/32.jpg)
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());
![Page 33: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/33.jpg)
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' ));
![Page 34: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/34.jpg)
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; }
![Page 35: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/35.jpg)
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);
![Page 36: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/36.jpg)
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);
![Page 37: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/37.jpg)
$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
![Page 38: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/38.jpg)
![Page 39: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/39.jpg)
Events & Event Listeners
• Event slots in various parts of SDK • Inject logic without extending classes • Symfony2 Event Dispatcher
$s3-‐>getEventDispatcher() -‐>addListener('<event>', <fn>);
![Page 40: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/40.jpg)
Plugins
• Implemented as event listeners • Many built-in plugins from Guzzle
including easy wire logging
use Guzzle\Plugin\Log\LogPlugin; $s3-‐>addSubscriber( LogPlugin::getDebugPlugin() );
![Page 41: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/41.jpg)
Higher-level Abstractions
• S3 Multipart Uploader
• S3 Stream Wrapper
• DynamoDB Session Handler
• DynamoDB WriteRequestBatch
• SNS Message Validator
• Third-party Modules: ZF2, Silex, Laravel
![Page 42: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/42.jpg)
$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
![Page 43: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/43.jpg)
http://aws.amazon.com/sdkforphp/
https://github.com/aws/aws-sdk-php
![Page 44: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/44.jpg)
PHP Apps on AWS
![Page 45: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/45.jpg)
• http://aws.amazon.com/architecture/ – Reference architectures • http://awsofa.info/ – Obama for America architecture
![Page 46: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/46.jpg)
Hosting
• AWS Elastic Beanstalk
• AWS OpsWorks
• AWS CloudFormation
• Amazon EC2 + Auto Scaling + Elastic Load Balancer + Amazon CloudWatch
Easiest to setup Easiest to customize
![Page 47: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/47.jpg)
Databases
• Amazon RDS – Relational Databases
• Amazon DynamoDB – NoSQL Database
• Amazon Redshift – Data Warehousing
• Amazon ElastiCache – Memcache
![Page 48: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/48.jpg)
File Storage & Delivery
• Amazon S3 – General Storage
• Amazon EBS – Detachable Storage Volumes
• Amazon Glacier – Archiving
• Amazon CloudFront – Global CDN
![Page 49: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/49.jpg)
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
![Page 50: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/50.jpg)
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!
![Page 51: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/51.jpg)
Simple Funny Face Sharing App on
AWS Elastic Beanstalk
![Page 52: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/52.jpg)
Funny Face Sharing App
• AWS Elastic Beanstalk – Amazon EC2 – Auto Scaling – Elastic Load Balancer – Amazon CloudWatch
• Amazon S3 • Amazon DynamoDB
![Page 53: Amazon Web Services for PHP Developers](https://reader033.fdocuments.net/reader033/viewer/2022050921/554ebeb1b4c905de468b49b4/html5/thumbnails/53.jpg)
Questions?
@jeremeamia
Try out "The Cloud", AWS, and the
AWS SDK for PHP