Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012

9,364 views

Published on

Learn how to work with Amazon DynamoDB using the AWS SDK for PHP. Attendees learn about the AWS SDK for PHP including how to install and configure the SDK and how to perform operations with DynamoDB. Advanced discussion topics include tips for effective DynamoDB usage, request batching, performance tuning, configuring event listeners, and setting up the included DynamoDB session handler for session storage.

  • Be the first to comment

TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012

  1. 1. #reinvent
  2. 2. AWS SDK for PHP 2
  3. 3. re:• Faster and more flexible• More open source
  4. 4. • Foundation of the AWS SDK• Symfony2 EventDispatcher http://guzzlephp.org
  5. 5. Getting Started with the AWS SDK for PHPrequire vendor/autoload.php;$aws = AwsCommonAws::factory(array( key => your-aws-access-key-id, secret => your-aws-secret-access-key, region => us-west-2));$db = $aws->get(dynamodb);$s3 = $aws->get(s3);
  6. 6. Amazon DynamoDB
  7. 7. Website hosted onAWS Elastic BeanstalkPet profiles and appointmentsstored in Amazon DynamoDB
  8. 8. Part 1: Outbreak Time to scale up!
  9. 9. Session Handler – Basic Usage// Register the handler$db = $aws->get(dynamodb);$db->registerSessionHandler(array( table_name => sessions));// Use PHP sessions like normalsession_start();$_SESSION[‘abc] = bar;session_write_close();
  10. 10. <1KB
  11. 11. Part 2: Triage Lets query!
  12. 12. Puppies Kittens Old dogs Old cats Hefty cats
  13. 13. • S: Id array( Id => array(S => 000012), Species => array(S => Cat), Name => array(S => Fluffy), Owner => array(S => Yifei), Age => array(N => 11), Weight => array(N => 20) )
  14. 14. Faster, butonly operates on keysQuery Scan
  15. 15. Puppies Kittens Old dogs Old cats Hefty cats Age LT 1 Age GT 10 Species EQ CatAND Species IN [Cat, Dog] AND Species IN [Cat, Dog] Weight GT 20
  16. 16. No, endforeach Yes, send moreScanIterator Yield results
  17. 17. Simple Iterator$tables = $db->getIterator(ListTables, array( Limit => 25));foreach ($tables as $table) { echo $table . PHP_EOL;}
  18. 18. Scan Iterators – Example$youngPets = $db->getIterator(Scan, array( TableName => Pets, ScanFilter => array( species => array( AttributeValueList => array(array(S => Dog), array(S => Cat)), ComparisonOperator => IN ), age => array( AttributeValueList => array(array(N => 1), ComparisonOperator => LT ) )));
  19. 19. Scan Iterators – Combining and Iterating$atRiskPets = new AppendIterator();$atRiskPets->append($youngPets);$atRiskPets->append($oldPets);$atRiskPets->append($heftyCats);foreach ($atRiskPets as $pet) { echo "Vaccinate {$pet[Name][S]}.n"; // @TODO Create an appointment}
  20. 20. Demo: Iterators
  21. 21. $client->addSubscriber(new CommandAnnouncerListener());
  22. 22. Events – Example Pluginclass CommandAnnouncerListener implements EventSubscriberInterface{ public static function getSubscribedEvents() { return array(command.before_send => array( onCommandBeforeSend) ); } public function onCommandBeforeSend(Event $event) { $commandName = $event[command]->getName(); echo "Executing the {$commandName} operation.n"; }}
  23. 23. Demo: Iterators
  24. 24. Part 3: Vaccinate Push the bits!
  25. 25. Batch System
  26. 26. (Strategy Pattern)
  27. 27. (Decorator Pattern)
  28. 28. (Builder Pattern)
  29. 29. DynamoDB WriteRequestBatch – Usage$batch = WriteRequestBatch::factory($db);foreach ($atRiskPets as $pet) { $pet[date] = array(S => date(Ymd)); $batch->add($db->getCommand(PutItem, array( TableName => Appointments, Item => $pet )));}$batch->flush();
  30. 30. Demo: Batching
  31. 31. $iterator = $db->getIterator(Scan, array([…]));$batch = WriteRequestBatch::factory($db);foreach ($iterator as $pet) { $batch->add($db->getCommand(PutItem, array( TableName => Appointments, Item => $pet )));}$batch->flush();
  32. 32. We are sincerely eager to #reinvent hear your feedback on thispresentation and on re:Invent. Please fill out an evaluation form when you have a chance.

×