Amazon Web Services for PHP Developers

  • 1,020 views
Uploaded on

Amazon Web Services and the AWS SDK for PHP continue to put more power into the hands of PHP developers to build robust and scalable web applications. With version 2 of the SDK, developers now have an …

Amazon Web Services and the AWS SDK for PHP continue to put more power into the hands of PHP developers to build robust and scalable web applications. With version 2 of the SDK, developers now have an even more powerful library for interacting with AWS built on top of existing open source software like the Guzzle HTTP framework and the Symfony 2 Event Dispatcher. In this session you will learn about Amazon Web Services, how to use the AWS SDK for PHP, and how you can easily deploy and scale your applications to the cloud with AWS services, including AWS Elastic Beanstalk.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,020
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
26
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Amazon Web Servicesfor PHP Developers
  • 2. Oh Hai! Im 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
  • 3. What is "The Cloud"?
  • 4. Cloud computingis the acquisition and useof computing resources thatare delivered as a service on anas-needed basis.
  • 5. "The Cloud"•  Evolution of distributed computing andService-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/ )
  • 6. Bringing you the “The Cloud” since 2006.
  • 7. Amazon Web Services offers acomplete set of infrastructure andapplication services that enableyou to run virtually everything inthe cloud: from enterpriseapplications and big data projectsto social games and mobile apps.( http://aws.amazon.com )
  • 8. Amazon CloudFormationAmazon CloudFrontAmazon CloudSearchAmazon CloudWatchAmazon Direct ConnectAmazon DynamoDBAmazon EBSAmazon EC2Amazon ElastiCacheAmazon Elastic TranscoderAmazon EMRAmazon GlacierAmazon IAMAmazon Mechanical TurkAmazon RDSAmazon RedshiftAmazon Route53Amazon S3Amazon SESAmazon SimpleDBAmazon SNSAmazon SQSAmazon SWFAmazon VPCAWS CloudHSMAWS Data PipelineAWS Elastic BeanstalkAWS Import/ExportAWS MarketplaceAWS OpsWorksAWS Storage GatewayAWS SupportAuto ScalingElastic Load Balancing
  • 9. Amazon CloudFormationAmazon CloudFrontAmazon CloudSearchAmazon CloudWatchAmazon Direct ConnectAmazon DynamoDBAmazon EBSAmazon EC2Amazon ElastiCacheAmazon Elastic TranscoderAmazon EMRAmazon GlacierAmazon IAMAmazon Mechanical TurkAmazon RDSAmazon RedshiftAmazon Route53Amazon S3Amazon SESAmazon SimpleDBAmazon SNSAmazon SQSAmazon SWFAmazon VPCAWS CloudHSMAWS Data PipelineAWS Elastic BeanstalkAWS Import/ExportAWS MarketplaceAWS OpsWorksAWS Storage GatewayAWS SupportAuto ScalingElastic Load Balancing
  • 10. Amazon CloudFormationAmazon CloudFrontAmazon CloudSearchAmazon CloudWatchAmazon Direct ConnectAmazon DynamoDBAmazon EBSAmazon EC2Amazon ElastiCacheAmazon Elastic TranscoderAmazon EMRAmazon GlacierAmazon IAMAmazon Mechanical TurkAmazon RDSAmazon RedshiftAmazon Route53Amazon S3Amazon SESAmazon SimpleDBAmazon SNSAmazon SQSAmazon SWFAmazon VPCAWS CloudHSMAWS Data PipelineAWS Elastic BeanstalkAWS Import/ExportAWS MarketplaceAWS OpsWorksAWS Storage GatewayAWS SupportAuto ScalingElastic Load BalancingNEW!
  • 11. Amazon CloudFormationAmazon CloudFrontAmazon CloudSearchAmazon CloudWatchAmazon Direct ConnectAmazon DynamoDBAmazon EBSAmazon EC2Amazon ElastiCacheAmazon Elastic TranscoderAmazon EMRAmazon GlacierAmazon IAMAmazon Mechanical TurkAmazon RDSAmazon RedshiftAmazon Route53Amazon S3Amazon SESAmazon SimpleDBAmazon SNSAmazon SQSAmazon SWFAmazon VPCAWS CloudHSMAWS Data PipelineAWS Elastic BeanstalkAWS Import/ExportAWS MarketplaceAWS OpsWorksAWS Storage GatewayAWS SupportAuto ScalingElastic Load BalancingCompute & NetworkingStorage & Content DeliveryDatabasesApplication ServicesDeployment & Management
  • 12. Customers in 190 Countries
  • 13. Customers in 190 Countries37 SignalsAirbnbEngine YardEtsyFlipboardFoursquareHoot SuiteIMDbOutback SteakhousePBSPinterestRedditSamsungSegaShazamSpotifyTicketmasterYelp
  • 14. How do I use AWS?
  • 15. AWS Console
  • 16. AWS SDKs and ToolsPHP • Java • Python • .NETRuby • Node.js • iOS • AndroidSDKsUnified CLI • Visual Studio PluginEclipse Plugin • PowerShell ToolsTools
  • 17. General SDK Features•  Suite of HTTP clients•  Input and output serialization•  Protocol normalization•  Authentication•  Error handling•  Language-specific conveniences•  Open source
  • 18. The AWS SDK for PHPhttp://github.com/aws/aws-sdk-php
  • 19. Quick History•  Tarzan (Started by @skyzyx)•  CloudFusion•  AWS SDK for PHP [2010]•  AWS SDK for PHP 2 [Late 2012]
  • 20. 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
  • 21. require  vendor/autoload.php;  use  AwsS3S3Client;    $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)  ));  
  • 22. Built on Guzzle•  Popular HTTP Library– Goutte– AWS SDK for PHP J– Drupal 8•  Foundation of the SDK•  Symfony2 Events•  http://guzzlephp.org
  • 23. Installing the PHP SDK•  Composer•  PEAR•  Downloadable Phar•  RPM/yum (on Amazon Linux)
  • 24. Composer•  Dependency management•  Autoloader for project•  http://getcomposer.org
  • 25. Installing via ComposerIn your composer.json file:  {      "require":  {          "aws/aws-­‐sdk-­‐php":  "2.*"      }  }  On the command line.php  composer.phar  install  
  • 26. Concepts in the SDK•  Commands•  Modeled Results•  Iterators•  Waiters•  Events & Plugins•  High-level Abstractions
  • 27. Commands•  Encapsulates an operation to AWS•  Contains Request and Response objects•  Allows you set and get parameters•  Returns modeled results
  • 28. Commands - Shorthand$result  =  $s3-­‐>listObjects(array(      Bucket  =>  my-­‐bucket-­‐name  ));    echo  $result[Objects][0][Key];  
  • 29. $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
  • 30. $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
  • 31. 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());  
  • 32. Waiters•  Poll resources until available•  Handle asynchronous and eventuallyconsistent operations more easily$s3-­‐>createBucket(array(      Bucket  =>  my-­‐bucket  ));  $s3-­‐>waitUntilBucketExists(array(      Bucket  =>  my-­‐bucket  ));  
  • 33. 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;  }  
  • 34. 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);
  • 35. 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);
  • 36. $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
  • 37. Events & Event Listeners•  Event slots in various parts of SDK•  Inject logic without extending classes•  Symfony2 Event Dispatcher$s3-­‐>getEventDispatcher()        -­‐>addListener(<event>,  <fn>);  
  • 38. Plugins•  Implemented as event listeners•  Many built-in plugins from Guzzleincluding easy wire logginguse  GuzzlePluginLogLogPlugin;  $s3-­‐>addSubscriber(          LogPlugin::getDebugPlugin()  );  
  • 39. Higher-level Abstractions•  S3 Multipart Uploader•  S3 Stream Wrapper•  DynamoDB Session Handler•  DynamoDB WriteRequestBatch•  SNS Message Validator•  Third-party Modules: ZF2, Silex, Laravel
  • 40. $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
  • 41. http://aws.amazon.com/sdkforphp/https://github.com/aws/aws-sdk-php
  • 42. PHP Apps on AWS
  • 43. •  http://aws.amazon.com/architecture/ – Reference architectures•  http://awsofa.info/ – Obama for America architecture
  • 44. Hosting•  AWS Elastic Beanstalk•  AWS OpsWorks•  AWS CloudFormation•  Amazon EC2+ Auto Scaling+ Elastic Load Balancer+ Amazon CloudWatchEasiest tosetupEasiest tocustomize
  • 45. Databases•  Amazon RDS – Relational Databases•  Amazon DynamoDB – NoSQL Database•  Amazon Redshift – Data Warehousing•  Amazon ElastiCache – Memcache
  • 46. File Storage & Delivery•  Amazon S3 – General Storage•  Amazon EBS – Detachable Storage Volumes•  Amazon Glacier – Archiving•  Amazon CloudFront – Global CDN
  • 47. 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
  • 48. 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 CloudSearchTheres an app a service for that!
  • 49. Simple Funny FaceSharing App onAWS Elastic Beanstalk
  • 50. Funny Face Sharing App•  AWS Elastic Beanstalk– Amazon EC2– Auto Scaling– Elastic Load Balancer– Amazon CloudWatch•  Amazon S3•  Amazon DynamoDB
  • 51. Questions?@jeremeamiaTry out "The Cloud",AWS, and theAWS SDK for PHP