SlideShare a Scribd company logo
Shahar Evron | Zend Technologies
Amazon Cloud Services
and Zend Framework
A few things about me...
●
Shahar Evron (‫ֹן‬‫ו‬‫ְר‬‫ב‬ֶ‫ע‬ ‫ַר‬‫ח‬ָ‫ש‬)
●
Working with PHP since 2002
●
In Zend since 2005
●
“Technical Product Manager”
●
I'm not a programmer, I decide stuff ;)
●
I get to play with cool technical sh!t
●
My boss is in marketing (but I do not talk about
it)
●
I also try to contribute to Zend Framework
Agenda
●
This is a code talk!
●
A quick introduction to the AWS platform
●
Showcase some of the Amazon services
through ZF-based examples
●
Amazon Simple Storage Service
●
Amazon Elastic Compute Cloud
●
Elastic Block Storage
●
Elastic Load Balancing
Usual Zend Framework Mantras
●
ZF is also a component library
...you all already know this right?
●
Everything I'll show today can be used
with any PHP 5.2+ code
Hype Aside, Why Cloud?
●
Lets take a deep breath for a minute..
●
We're not all moving to the cloud
...right?
●
It's not the solution for
everything!
●
It's not only a hosting platform
●
It can be used at will
Amazon Cloud Services
●
The biggest, most complete and best
known public cloud platform today
●
Amazon started externalizing (and
selling) internal infrastructures
●
EC2 public beta in 2006
●
Includes services for computing, file
storage, data storage, queueing and more
●
...no free development offering
Common Initialization Code
All code samples in this tutorial assume:
// Have ZF in your include_path
set_include_path('/path/to/zf/library');
// Load and register the ZF autoloader
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
// Set AWS access keys
define('AWS_ACCESS_KEY', 'YOURACCESSKEYID');
define('AWS_SECRET_KEY', '5om3R4Ndom53Cr3757uFf');
Amazon S3
●
“Simple Storage Service”
●
Object (file, blob) storage
●
Allows access control on files
●
Simple HTTP REST interface
●
Public objects can be accessed directly using
any regular web browser
●
Fault-tolerant
●
Not to be confused with: EBS, CloudFront
Amazon S3
The Basics:
/* Keys can also be set globally using the static
Zend_Service_Amazon_S3::setKeys() method */
$s3 = new Zend_Service_Amazon_S3(
AWS_ACCESS_KEY, AWS_SECRET_KEY
);
// Create a bucket
$bucket = 'shahar-talks';
$s3->createBucket($bucket);
// Store the current file in our bucket
$s3->putFile(
__FILE__,
$bucket . '/' . basename(__FILE__)
);
Amazon S3
●
The object we have just created is at
http://s3.amazonaws.com/shahar-talks/filename
●
...but it's private (objects are private by default)
so you can't access it without authenticating
●
You can access it using API after authenticating,
but not using a browser
●
More about access control later on
// Get the file we just uploadad
$file = $s3->getObject(
$bucket . '/' . basename(__FILE__)
);
but what's that about buckets!?!
Amazon S3 - Buckets
●
S3 stores files in “buckets”
●
Think of them as storage namespaces
●
Buckets are globally unique!
/** DON'T TRY THIS AT HOME, KIDS **/
$buckets = $s3->getBuckets();
foreach ($buckets as $bucket) {
$objects = $s3->getObjectsByBucket($bucket);
echo "Deleting " . count($objects) .
" from bucket $bucket...n";
$s3->cleanBucket($bucket);
$s3->removeBucket($bucket);
}
Amazon S3 – Access Control
●
Access Control can be set using the 3rd
parameter of putObject():
$location = 'shahar-talks/picture.jpg';
$s3->putObject('picture.jpg', $location, array(
// Make the picture publicly readable
Zend_Service_Amazon_S3::S3_ACL_HEADER =>
Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,
// Specify content type
Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER =>
'image/jpeg'
));
Amazon S3 – Streaming
●
By default, the getObject and putObject
methods load entire files into memory
●
Dealing with large files, you will very
quickly hit PHP's memory limit
●
(or you'll just crash your server)
●
Solution: use the streaming methods!
Amazon S3 - Streaming
// Store a potentially large object
$localFile = '/home/shahar/pirated-movie-dvd.iso';
$destination = 'my-stuff/' . basename($localFile);
$s3->putFileStream($localFile, $destination, $meta);
// Or:
$fp = fopen($localFile);
$s3->putObject($destination, $fp, $meta);
// Get a potentially large object
$s3->getObjectStream($destination, $localFile);
// Or:
$response = $s3->getObjectStream($destination);
$fp = fopen($response->getStreamName(), 'r');
while ($data = fread($fp, 4096)) {
file_put_contents('/dev/null', $data);
}
fclose($fp);
The Amazon S3 Stream Wrapper
●
Even Cooler: ZF provides a user-space
stream wrapper for S3!
// Register the stream wrapper
$s3->registerStreamWrapper("s3");
// Now we can use S3 files more or less as regular files
$bucket = "my-secret-stuff";
mkdir("s3://$bucket");
$localFp = fopen($localFile, 'r');
$remoteFp = fopen("s3://$bucket/secret-dvd.iso", 'w');
stream_filter_append($remoteFp, 'mcrypt.tripledes',
STREAM_FILTER_WRITE, $filterOpts);
// Copy my local file to S3, encrypting it as we go
stream_copy_to_stream($localFp, $remoteFp);
Amazon EC2
●
Amazon Elastic Compute Cloud
●
On-demand virtual servers in the cloud
●
You are “guaranteed” CPU and memory
●
You are not-so-guaranteed I/O and
network throughput
●
Different machine types are available,
pricing varies
●
Useful for hosting, and for other stuff!
Amazon EC2 - Instances
$ec2 = new Zend_Service_Amazon_Ec2_Instance(
AWS_SECRET_KEY, AWS_ACCESS_KEY
);
// Set EC2 region
$ec2->setRegion('us-west-1');
// Start an EC2 machine instance
$result = $ec2->run(array(
'instanceType' => 'm1.large',
'imageId' => 'ami-123456',
'securityGroup' => array('default', 'ssh'),
'keyName' => 'my-ssh-key',
'userData' => $myUserData,
));
Amazon EC2 - Instances
// ... continued
// Wait for machine to be up and running
$instance = $result['instances'][0];
$state = $instance['instanceState']['name'];
while ($state != 'running') {
sleep(5);
$result = $ec2->describe($instance['instanceId']);
$instance = $result['instances'][0];
$state = $instance['instanceState']['name'];
}
// Print out the machine's public hostname
echo $instance['dnsName'];
Amazon EC2 - EBS
●
Allows you to create permanent storage
for EC2 instances
●
EBS volumes - block devices that can be
attached to any EC2 instance
●
Can be attached to a single EC2 machine at
a time, and detached while not in use
●
You can create EBS snapshots of volumes
●
These are stored in S3
●
You can quickly create multiple volumes
from a single snapshot
Amazon EC2 - EBS
$ebs = new Zend_Service_Amazon_Ec2_Ebs(
AWS_ACCESS_KEY, AWS_SECRET_KEY
);
/* Create and attach a 10gb volume */
$result = $ebs->createNewVolume(10, 'eu-west-1a');
while($result['status'] != 'available') {
sleep(1);
$result = array_shift(
$ebs->describeVolume($result['volumeId'])
);
}
$ebs->attachVolume(
$result['volumeId'], $instanceId, '/dev/sdf'
);
Amazon EC2 - EBS
/* Create a snapshot of a volume */
$snapInfo = $ebs->createSnapshot($volumeId);
while ($snapInfo['status'] != 'completed') {
sleep(1);
$snapInfo = array_shift(
$ebs->describeSnapshot($snapInfo['snapshotId'])
);
}
/* Create volumes from snapshot and attach to machines */
foreach($myInstances as $instInfo) {
$result = $ebs->createVolumeFromSnapshot(
$snapInfo['snapshotId'],$instInfo['availabilityZone']
);
$ebs->attachVolume(
$result['volumeId'], $instInfo['instanceId'], '/dev/sdf'
);
}
Amazon EC2 - ELB
●
Elastic Load Balancing – load balancing
service for EC2 machine clusters
●
Can do TCP or HTTP load balancing
●
Optionally provides session stickiness
●
Either TCP or HTTP based stickiness
●
You can set up health pings and add /
remove machines based on health
●
Can distribute load across availability
zones
Amazon EC2 - ELB
●
Ok, not really in ZF... but still useful
http://github.com/shevron/zf-amazonaws-elasticlb
●
I needed access to Amazon ELB, so I
wrote a ZF-compatible class for it
●
I got too busy / lazy / bored so it never
made it to ZF
●
Maybe you wanna finish it? ;-)
Amazon EC2 - EBS
/* NOTE: this class is NOT in ZF! */
$elb = new Zend_Service_Amazon_Ec2_ElasticLB(
AWS_ACCESS_KEY, AWS_SECRET_KEY
);
/* Create a listener on port 80, HTTP */
$listener = new Zend_Service_Amazon_Ec2_ElasticLB_Listener(
80, 80, 'HTTP'
);
/* Create a load balancer */
$lbInfo = $elb->create(
'my-http-lb', 'eu-west-1b', $listener
);
/* Register instances with load balancer */
$instanceIds = array();
foreach($myInstances as $instInfo) {
$instanceIds[] = $instInfo['instanceId'];
}
$elb->registerInstances('my-http-lb', $instanceIds);
More AWS + ZF Goodies
●
SimpleDB
●
Simple Queue Service
●
Elastic IP Addresses
●
EC2 Images
●
EC2 Windows Instances
●
CloudWatch Monitoring
●
Reserved Instances
Where Next?
●
Last Questions?
●
Email me: shahar.e@zend.com
●
IRC: #zftalk, #zendserver @ FreeNode
●
http://framework.zend.com/manual/
●
http://aws.amazon.com/documentation/
●
Pay-per-use Zend Server images:
http://zend.com/products/server/amazon/
Thank You!

More Related Content

PDF
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
KEY
Perl: Hate it for the Right Reasons
KEY
Keeping it small: Getting to know the Slim micro framework
KEY
Mojo as a_client
PDF
XQuery Rocks
PDF
Taking Objective-C to the next level. UA Mobile 2016.
PDF
Not your Grandma's XQuery
PPTX
Deep Dive into AWS CLI - the command line interface
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Perl: Hate it for the Right Reasons
Keeping it small: Getting to know the Slim micro framework
Mojo as a_client
XQuery Rocks
Taking Objective-C to the next level. UA Mobile 2016.
Not your Grandma's XQuery
Deep Dive into AWS CLI - the command line interface

What's hot (14)

PPT
Slim RedBeanPHP and Knockout
PDF
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
ODP
The promise of asynchronous php
PDF
Masterclass Advanced Usage of the AWS CLI
PDF
Lightweight wrapper for Hive on Amazon EMR
PDF
Forget about Index.php and build you applications around HTTP - PHPers Cracow
PDF
Play á la Rails
PDF
How Kris Writes Symfony Apps
PDF
Keeping it Small: Getting to know the Slim Micro Framework
PDF
Building Cloud Castles - LRUG
PDF
Great Developers Steal
PPTX
Configuration Management and Provisioning Are Different
PDF
PHP 5.3 and Lithium: the most rad php framework
KEY
Slim RedBeanPHP and Knockout
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
The promise of asynchronous php
Masterclass Advanced Usage of the AWS CLI
Lightweight wrapper for Hive on Amazon EMR
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Play á la Rails
How Kris Writes Symfony Apps
Keeping it Small: Getting to know the Slim Micro Framework
Building Cloud Castles - LRUG
Great Developers Steal
Configuration Management and Provisioning Are Different
PHP 5.3 and Lithium: the most rad php framework
Ad

Similar to Amazon Cloud Services and Zend Framework (20)

PDF
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
PDF
Symfony finally swiped right on envvars
PDF
Manage WordPress with Awesome using wp cli
PDF
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
PPTX
Stack kicker devopsdays-london-2013
PDF
Amazon Web Services for PHP Developers
PDF
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
PDF
infra-as-code
PDF
Practical Chef and Capistrano for Your Rails App
PDF
Symfony2 revealed
ODP
Symfony CMF - PHP Conference Brazil 2011
KEY
PDF
Alex Casalboni - Configuration management and service discovery - Codemotion ...
PDF
Mojolicious
PDF
Scaling in Mind (Case study of Drupal Core)
PDF
PHP SA 2014 - Releasing Your Open Source Project
PPT
eZ Publish Cluster Unleashed
KEY
PPTX
Running Splunk on AWS
PDF
Ansible inside
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Symfony finally swiped right on envvars
Manage WordPress with Awesome using wp cli
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Stack kicker devopsdays-london-2013
Amazon Web Services for PHP Developers
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
infra-as-code
Practical Chef and Capistrano for Your Rails App
Symfony2 revealed
Symfony CMF - PHP Conference Brazil 2011
Alex Casalboni - Configuration management and service discovery - Codemotion ...
Mojolicious
Scaling in Mind (Case study of Drupal Core)
PHP SA 2014 - Releasing Your Open Source Project
eZ Publish Cluster Unleashed
Running Splunk on AWS
Ansible inside
Ad

More from Shahar Evron (12)

PDF
Best Practices in PHP Application Deployment
PPTX
PHP and Zend Framework on Windows
PDF
Zend Server: A Guided Tour
PDF
Zend Server: Scalability & Performance
PDF
Intro To Couch Db
ODP
Scaling PHP Applications with Zend Platform
PDF
Zend Framework Components for non-framework Development
PDF
PHP ואבטחה - חלק שני
PDF
PHP ואבטחה - חלק ראשון
PDF
PHP - עבר הווה ועתיד
PDF
Content Indexing with Zend_Search_Lucene
ODP
Building Scalable Development Environments
Best Practices in PHP Application Deployment
PHP and Zend Framework on Windows
Zend Server: A Guided Tour
Zend Server: Scalability & Performance
Intro To Couch Db
Scaling PHP Applications with Zend Platform
Zend Framework Components for non-framework Development
PHP ואבטחה - חלק שני
PHP ואבטחה - חלק ראשון
PHP - עבר הווה ועתיד
Content Indexing with Zend_Search_Lucene
Building Scalable Development Environments

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
sap open course for s4hana steps from ECC to s4
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
sap open course for s4hana steps from ECC to s4
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
A comparative analysis of optical character recognition models for extracting...
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Advanced methodologies resolving dimensionality complications for autism neur...

Amazon Cloud Services and Zend Framework

  • 1. Shahar Evron | Zend Technologies Amazon Cloud Services and Zend Framework
  • 2. A few things about me... ● Shahar Evron (‫ֹן‬‫ו‬‫ְר‬‫ב‬ֶ‫ע‬ ‫ַר‬‫ח‬ָ‫ש‬) ● Working with PHP since 2002 ● In Zend since 2005 ● “Technical Product Manager” ● I'm not a programmer, I decide stuff ;) ● I get to play with cool technical sh!t ● My boss is in marketing (but I do not talk about it) ● I also try to contribute to Zend Framework
  • 3. Agenda ● This is a code talk! ● A quick introduction to the AWS platform ● Showcase some of the Amazon services through ZF-based examples ● Amazon Simple Storage Service ● Amazon Elastic Compute Cloud ● Elastic Block Storage ● Elastic Load Balancing
  • 4. Usual Zend Framework Mantras ● ZF is also a component library ...you all already know this right? ● Everything I'll show today can be used with any PHP 5.2+ code
  • 5. Hype Aside, Why Cloud? ● Lets take a deep breath for a minute.. ● We're not all moving to the cloud ...right? ● It's not the solution for everything! ● It's not only a hosting platform ● It can be used at will
  • 6. Amazon Cloud Services ● The biggest, most complete and best known public cloud platform today ● Amazon started externalizing (and selling) internal infrastructures ● EC2 public beta in 2006 ● Includes services for computing, file storage, data storage, queueing and more ● ...no free development offering
  • 7. Common Initialization Code All code samples in this tutorial assume: // Have ZF in your include_path set_include_path('/path/to/zf/library'); // Load and register the ZF autoloader require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); // Set AWS access keys define('AWS_ACCESS_KEY', 'YOURACCESSKEYID'); define('AWS_SECRET_KEY', '5om3R4Ndom53Cr3757uFf');
  • 8. Amazon S3 ● “Simple Storage Service” ● Object (file, blob) storage ● Allows access control on files ● Simple HTTP REST interface ● Public objects can be accessed directly using any regular web browser ● Fault-tolerant ● Not to be confused with: EBS, CloudFront
  • 9. Amazon S3 The Basics: /* Keys can also be set globally using the static Zend_Service_Amazon_S3::setKeys() method */ $s3 = new Zend_Service_Amazon_S3( AWS_ACCESS_KEY, AWS_SECRET_KEY ); // Create a bucket $bucket = 'shahar-talks'; $s3->createBucket($bucket); // Store the current file in our bucket $s3->putFile( __FILE__, $bucket . '/' . basename(__FILE__) );
  • 10. Amazon S3 ● The object we have just created is at http://s3.amazonaws.com/shahar-talks/filename ● ...but it's private (objects are private by default) so you can't access it without authenticating ● You can access it using API after authenticating, but not using a browser ● More about access control later on // Get the file we just uploadad $file = $s3->getObject( $bucket . '/' . basename(__FILE__) );
  • 11. but what's that about buckets!?!
  • 12. Amazon S3 - Buckets ● S3 stores files in “buckets” ● Think of them as storage namespaces ● Buckets are globally unique! /** DON'T TRY THIS AT HOME, KIDS **/ $buckets = $s3->getBuckets(); foreach ($buckets as $bucket) { $objects = $s3->getObjectsByBucket($bucket); echo "Deleting " . count($objects) . " from bucket $bucket...n"; $s3->cleanBucket($bucket); $s3->removeBucket($bucket); }
  • 13. Amazon S3 – Access Control ● Access Control can be set using the 3rd parameter of putObject(): $location = 'shahar-talks/picture.jpg'; $s3->putObject('picture.jpg', $location, array( // Make the picture publicly readable Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ, // Specify content type Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER => 'image/jpeg' ));
  • 14. Amazon S3 – Streaming ● By default, the getObject and putObject methods load entire files into memory ● Dealing with large files, you will very quickly hit PHP's memory limit ● (or you'll just crash your server) ● Solution: use the streaming methods!
  • 15. Amazon S3 - Streaming // Store a potentially large object $localFile = '/home/shahar/pirated-movie-dvd.iso'; $destination = 'my-stuff/' . basename($localFile); $s3->putFileStream($localFile, $destination, $meta); // Or: $fp = fopen($localFile); $s3->putObject($destination, $fp, $meta); // Get a potentially large object $s3->getObjectStream($destination, $localFile); // Or: $response = $s3->getObjectStream($destination); $fp = fopen($response->getStreamName(), 'r'); while ($data = fread($fp, 4096)) { file_put_contents('/dev/null', $data); } fclose($fp);
  • 16. The Amazon S3 Stream Wrapper ● Even Cooler: ZF provides a user-space stream wrapper for S3! // Register the stream wrapper $s3->registerStreamWrapper("s3"); // Now we can use S3 files more or less as regular files $bucket = "my-secret-stuff"; mkdir("s3://$bucket"); $localFp = fopen($localFile, 'r'); $remoteFp = fopen("s3://$bucket/secret-dvd.iso", 'w'); stream_filter_append($remoteFp, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $filterOpts); // Copy my local file to S3, encrypting it as we go stream_copy_to_stream($localFp, $remoteFp);
  • 17. Amazon EC2 ● Amazon Elastic Compute Cloud ● On-demand virtual servers in the cloud ● You are “guaranteed” CPU and memory ● You are not-so-guaranteed I/O and network throughput ● Different machine types are available, pricing varies ● Useful for hosting, and for other stuff!
  • 18. Amazon EC2 - Instances $ec2 = new Zend_Service_Amazon_Ec2_Instance( AWS_SECRET_KEY, AWS_ACCESS_KEY ); // Set EC2 region $ec2->setRegion('us-west-1'); // Start an EC2 machine instance $result = $ec2->run(array( 'instanceType' => 'm1.large', 'imageId' => 'ami-123456', 'securityGroup' => array('default', 'ssh'), 'keyName' => 'my-ssh-key', 'userData' => $myUserData, ));
  • 19. Amazon EC2 - Instances // ... continued // Wait for machine to be up and running $instance = $result['instances'][0]; $state = $instance['instanceState']['name']; while ($state != 'running') { sleep(5); $result = $ec2->describe($instance['instanceId']); $instance = $result['instances'][0]; $state = $instance['instanceState']['name']; } // Print out the machine's public hostname echo $instance['dnsName'];
  • 20. Amazon EC2 - EBS ● Allows you to create permanent storage for EC2 instances ● EBS volumes - block devices that can be attached to any EC2 instance ● Can be attached to a single EC2 machine at a time, and detached while not in use ● You can create EBS snapshots of volumes ● These are stored in S3 ● You can quickly create multiple volumes from a single snapshot
  • 21. Amazon EC2 - EBS $ebs = new Zend_Service_Amazon_Ec2_Ebs( AWS_ACCESS_KEY, AWS_SECRET_KEY ); /* Create and attach a 10gb volume */ $result = $ebs->createNewVolume(10, 'eu-west-1a'); while($result['status'] != 'available') { sleep(1); $result = array_shift( $ebs->describeVolume($result['volumeId']) ); } $ebs->attachVolume( $result['volumeId'], $instanceId, '/dev/sdf' );
  • 22. Amazon EC2 - EBS /* Create a snapshot of a volume */ $snapInfo = $ebs->createSnapshot($volumeId); while ($snapInfo['status'] != 'completed') { sleep(1); $snapInfo = array_shift( $ebs->describeSnapshot($snapInfo['snapshotId']) ); } /* Create volumes from snapshot and attach to machines */ foreach($myInstances as $instInfo) { $result = $ebs->createVolumeFromSnapshot( $snapInfo['snapshotId'],$instInfo['availabilityZone'] ); $ebs->attachVolume( $result['volumeId'], $instInfo['instanceId'], '/dev/sdf' ); }
  • 23. Amazon EC2 - ELB ● Elastic Load Balancing – load balancing service for EC2 machine clusters ● Can do TCP or HTTP load balancing ● Optionally provides session stickiness ● Either TCP or HTTP based stickiness ● You can set up health pings and add / remove machines based on health ● Can distribute load across availability zones
  • 24. Amazon EC2 - ELB ● Ok, not really in ZF... but still useful http://github.com/shevron/zf-amazonaws-elasticlb ● I needed access to Amazon ELB, so I wrote a ZF-compatible class for it ● I got too busy / lazy / bored so it never made it to ZF ● Maybe you wanna finish it? ;-)
  • 25. Amazon EC2 - EBS /* NOTE: this class is NOT in ZF! */ $elb = new Zend_Service_Amazon_Ec2_ElasticLB( AWS_ACCESS_KEY, AWS_SECRET_KEY ); /* Create a listener on port 80, HTTP */ $listener = new Zend_Service_Amazon_Ec2_ElasticLB_Listener( 80, 80, 'HTTP' ); /* Create a load balancer */ $lbInfo = $elb->create( 'my-http-lb', 'eu-west-1b', $listener ); /* Register instances with load balancer */ $instanceIds = array(); foreach($myInstances as $instInfo) { $instanceIds[] = $instInfo['instanceId']; } $elb->registerInstances('my-http-lb', $instanceIds);
  • 26. More AWS + ZF Goodies ● SimpleDB ● Simple Queue Service ● Elastic IP Addresses ● EC2 Images ● EC2 Windows Instances ● CloudWatch Monitoring ● Reserved Instances
  • 27. Where Next? ● Last Questions? ● Email me: shahar.e@zend.com ● IRC: #zftalk, #zendserver @ FreeNode ● http://framework.zend.com/manual/ ● http://aws.amazon.com/documentation/ ● Pay-per-use Zend Server images: http://zend.com/products/server/amazon/