SlideShare a Scribd company logo
1 of 28
Download to read offline
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

What's hot

Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
Deep Dive into AWS CLI - the command line interface
Deep Dive into AWS CLI - the command line interfaceDeep Dive into AWS CLI - the command line interface
Deep Dive into AWS CLI - the command line interfaceJohn Varghese
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutVic Metcalfe
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupKacper Gunia
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous phpWim Godden
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceAmazon Web Services
 
Masterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLIMasterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLIDanilo Poccia
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRShinji Tanaka
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014Amazon Web Services
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowKacper Gunia
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Deep Dive - Advanced Usage of the AWS CLI
Deep Dive - Advanced Usage of the AWS CLIDeep Dive - Advanced Usage of the AWS CLI
Deep Dive - Advanced Usage of the AWS CLIAmazon Web Services
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkJeremy Kendall
 
Building Cloud Castles - LRUG
Building Cloud Castles - LRUGBuilding Cloud Castles - LRUG
Building Cloud Castles - LRUGBen Scofield
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers StealBen Scofield
 
Configuration Management and Provisioning Are Different
Configuration Management and Provisioning Are DifferentConfiguration Management and Provisioning Are Different
Configuration Management and Provisioning Are DifferentCarlos Nunez
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkG Woo
 

What's hot (20)

Not your Grandma's XQuery
Not your Grandma's XQueryNot your Grandma's XQuery
Not your Grandma's XQuery
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
Deep Dive into AWS CLI - the command line interface
Deep Dive into AWS CLI - the command line interfaceDeep Dive into AWS CLI - the command line interface
Deep Dive into AWS CLI - the command line interface
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
Deep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line InterfaceDeep Dive: AWS Command Line Interface
Deep Dive: AWS Command Line Interface
 
Masterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLIMasterclass Advanced Usage of the AWS CLI
Masterclass Advanced Usage of the AWS CLI
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMR
 
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
(DEV301) Advanced Usage of the AWS CLI | AWS re:Invent 2014
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Deep Dive - Advanced Usage of the AWS CLI
Deep Dive - Advanced Usage of the AWS CLIDeep Dive - Advanced Usage of the AWS CLI
Deep Dive - Advanced Usage of the AWS CLI
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Building Cloud Castles - LRUG
Building Cloud Castles - LRUGBuilding Cloud Castles - LRUG
Building Cloud Castles - LRUG
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Configuration Management and Provisioning Are Different
Configuration Management and Provisioning Are DifferentConfiguration Management and Provisioning Are Different
Configuration Management and Provisioning Are Different
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php framework
 

Similar to Amazon Cloud Services and Zend Framework

Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013Amazon Web Services
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Enrico Zimuel
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvarsSam Marley-Jarrett
 
Manage WordPress with Awesome using wp cli
Manage WordPress with Awesome using wp cliManage WordPress with Awesome using wp cli
Manage WordPress with Awesome using wp cliGetSource
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Enrico Zimuel
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Simon McCartney
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersJeremy Lindblom
 
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliWordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliGetSource
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppSmartLogic
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Jacopo Romei
 
Alex Casalboni - Configuration management and service discovery - Codemotion ...
Alex Casalboni - Configuration management and service discovery - Codemotion ...Alex Casalboni - Configuration management and service discovery - Codemotion ...
Alex Casalboni - Configuration management and service discovery - Codemotion ...Codemotion
 
Scaling in Mind (Case study of Drupal Core)
Scaling in Mind (Case study of Drupal Core)Scaling in Mind (Case study of Drupal Core)
Scaling in Mind (Case study of Drupal Core)jimyhuang
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
eZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedeZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedBertrand Dunogier
 
solving little problems
solving little problemssolving little problems
solving little problemsAustin Ziegler
 
Running Splunk on AWS
Running Splunk on AWSRunning Splunk on AWS
Running Splunk on AWSAlan Williams
 

Similar to Amazon Cloud Services and Zend Framework (20)

Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
 
Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvars
 
Manage WordPress with Awesome using wp cli
Manage WordPress with Awesome using wp cliManage WordPress with Awesome using wp cli
Manage WordPress with Awesome using wp cli
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
 
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliWordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011
 
Fatc
FatcFatc
Fatc
 
Alex Casalboni - Configuration management and service discovery - Codemotion ...
Alex Casalboni - Configuration management and service discovery - Codemotion ...Alex Casalboni - Configuration management and service discovery - Codemotion ...
Alex Casalboni - Configuration management and service discovery - Codemotion ...
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Scaling in Mind (Case study of Drupal Core)
Scaling in Mind (Case study of Drupal Core)Scaling in Mind (Case study of Drupal Core)
Scaling in Mind (Case study of Drupal Core)
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
eZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedeZ Publish Cluster Unleashed
eZ Publish Cluster Unleashed
 
solving little problems
solving little problemssolving little problems
solving little problems
 
Running Splunk on AWS
Running Splunk on AWSRunning Splunk on AWS
Running Splunk on AWS
 

More from Shahar Evron

Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentShahar Evron
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on WindowsShahar Evron
 
Zend Server: A Guided Tour
Zend Server: A Guided TourZend Server: A Guided Tour
Zend Server: A Guided TourShahar Evron
 
Zend Server: Scalability & Performance
Zend Server: Scalability & PerformanceZend Server: Scalability & Performance
Zend Server: Scalability & PerformanceShahar Evron
 
Scaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformScaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformShahar Evron
 
Zend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentZend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentShahar Evron
 
PHP ואבטחה - חלק שני
PHP ואבטחה - חלק שניPHP ואבטחה - חלק שני
PHP ואבטחה - חלק שניShahar Evron
 
PHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשוןPHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשוןShahar Evron
 
PHP - עבר הווה ועתיד
PHP - עבר הווה ועתידPHP - עבר הווה ועתיד
PHP - עבר הווה ועתידShahar Evron
 
Content Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_LuceneContent Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_LuceneShahar Evron
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development EnvironmentsShahar Evron
 

More from Shahar Evron (12)

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

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

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/