Slide 1

Slide 1 text

By Jeremy Lindblom (@jeremeamia)

Slide 2

Slide 2 text

Jeremy Lindblom (@jeremeamia)

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

The Clooouuud

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

"Cloud Computing" on-demand IT resources

Slide 14

Slide 14 text

AWS services each have an API, so you can control your resources through programs and scripts.

Slide 15

Slide 15 text

So let's provision a web server from PHP by using the AWS SDK for PHP to talk to the Amazon EC2 API Amazon  EC2  

Slide 16

Slide 16 text

$ec2 = 'region' => 'us-east-1' 'version' => '2015-10-01' $ec2->runInstances 'ImageId' => 'ami-6a6dcc02' 'MinCount' => 'MaxCount' => 'InstanceType' => 't2.micro'

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Amazon S3 Amazon SES Amazon SimpleDB Amazon SNS Amazon SQS Amazon SWF Amazon VPC Auto Scaling AWS CloudHSM AWS Data Pipeline AWS Elastic Beanstalk AWS Import/Export AWS OpsWorks AWS Marketplace AWS Storage Gateway AWS Support Elastic Load Balancing 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

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

$ec2 = ::factory 'region' => 'us-east-1' $ec2->runInstances 'ImageId' => 'ami-6a6dcc02' 'MinCount' => 'MaxCount' => 'InstanceType' => 't2.micro'

Slide 26

Slide 26 text

$ec2 = ::factory 'region' => 'us-east-1' $ec2->runInstances 'ImageId' => 'ami-6a6dcc02' 'MinCount' => 'MaxCount' => 'InstanceType' => 't2.micro' 'version' => '2015-10-01’

Slide 27

Slide 27 text

$ec2 = ::factory 'region' => 'us-east-1' $ec2->runInstances 'ImageId' => 'ami-6a6dcc02' 'MinCount' => 'MaxCount' => 'InstanceType' => 't2.micro'

Slide 28

Slide 28 text

$ec2 = ::factory 'region' => 'us-east-1' $ec2->runInstances 'ImageId' => 'ami-6a6dcc02' 'MinCount' => 'MaxCount' => 'InstanceType' => 't2.micro' 'version' => '2015-10-01'

Slide 29

Slide 29 text

$ec2 = ::factory 'region' => 'us-east-1' $ec2->runInstances 'ImageId' => 'ami-6a6dcc02' 'MinCount' => 'MaxCount' => 'InstanceType' => 't2.micro' 'version' => '2015-10-01'

Slide 30

Slide 30 text

•  Async requests with a Promise API •  Support for custom HTTP adapters –  cURL no longer required (still the default) –  Possible to implement with non-blocking event loops •  Result "Paginators" for iterating paginated data •  JMESPath querying of result data •  "debug" client option for easy debugging

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

PHP PHP #nofilter #selphpie #instagood

Slide 33

Slide 33 text

PHP PHP

Slide 34

Slide 34 text

(Storage of selPHPies) (Storage of URLs/captions) PHP PHP

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

"require": { "aws/aws-sdk-php": "~3.0", "silex/silex": "~1.2", "twig/twig": "~1.16", } getcomposer.org

Slide 37

Slide 37 text

•  Instance profile credentials •  Credentials file •  Environment variables •  Hard coding

Slide 38

Slide 38 text

•  Instance profile credentials •  Credentials file •  Environment variables •  Client configuration

Slide 39

Slide 39 text

•  Instance profile credentials •  Credentials file •  Environment variables •  Client configuration FYI: Also supported by the AWS CLI and other SDKs.

Slide 40

Slide 40 text

•  Instance profile credentials •  Credentials file •  Environment variables •  Client configuration

Slide 41

Slide 41 text

•  Instance profile credentials •  Credentials file •  Environment variables •  Client Configuration (BEWARE) 'credentials' => 'key' => $yourAccessKeyId 'secret' => $yourSecretAccessKey

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

php bin/setup.php S3 bucket DynamoDB table Amazon S3 Amazon DynamoDB

Slide 44

Slide 44 text

$s3->createBucket 'Bucket' => $bucket $s3->waitUntil 'BucketExists' 'Bucket' => $bucket $dynamoDb->createTable(['TableName' => $table ... $dynamoDb->waitUntil 'TableExists' 'TableName' => $table echo "Done.\n"

Slide 45

Slide 45 text

$s3->createBucket 'Bucket' => $bucket $s3->waitUntil 'BucketExists' 'Bucket' => $bucket $dynamoDb->createTable(['TableName' => $table ... $dynamoDb->waitUntil 'TableExists' 'TableName' => $table echo "Done.\n"

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

$s3->createBucket 'Bucket' => $bucket $s3->waitUntil 'BucketExists' 'Bucket' => $bucket $dynamoDb->createTable(['TableName' => $table ... $dynamoDb->waitUntil 'TableExists' 'TableName' => $table echo "Done.\n"

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

$app = new $app 'aws' = function return new 'region' => 'us-east-1' 'version' => 'latest' // ROUTES AND OTHER APPLICATION LOGIC $app->run

Slide 52

Slide 52 text

$app = new $app 'aws' = function return new 'region' => 'us-east-1' 'version' => 'latest' // ROUTES AND OTHER APPLICATION LOGIC $app->run

Slide 53

Slide 53 text

$app = new $app 'aws' = function return new 'region' => 'us-east-1' 'S3' => 'version' => '2006-03-01' 'DynamoDb' => 'version' => '2012-08-10'

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

$app->get '/' function ...

Slide 56

Slide 56 text

$dynamoDb = $app 'aws' ->createDynamoDb $result = $dynamoDb->query 'TableName' => 'selphpies' 'Limit' => // ... $items = $result 'Items'

Slide 57

Slide 57 text

$results = $dynamoDb->getPaginator 'Query' 'TableName' => 'selphpies' // ... $items = $results->search 'Items[]'

Slide 58

Slide 58 text

$results = $s3->getPaginator 'ListObjects' ... $files = $results->search 'Contents[].Key'

Slide 59

Slide 59 text

# With Paginators $results = $s3->getPaginator 'ListObjects' 'Bucket' => 'my-bucket' $keys = $results->search 'Contents[].Key' foreach $keys as $key echo $key . "\n" # Without Paginators $marker = do $args = 'Bucket' => 'my-bucket' if $marker $args 'Marker' = $marker $result = $s3->listObjects $args $objects = array $result 'Contents' foreach $objects as $object echo $object 'Key' . "\n" $marker $result->search 'NextMarker || Contents[-1].Key' while $result 'IsTruncated'

Slide 60

Slide 60 text

http://jmespath.org/ $result->search '' > 'Contents[].Key' > '[CommonPrefixes[].Prefix, Contents[].Key][]' > 'NextMarker || Contents[-1].Key'

Slide 61

Slide 61 text

$app->post '/upload' function ...

Slide 62

Slide 62 text

try { $caption = $request->request->get('selphpieCaption', '...'); $file = $request->files->get('selphpieImage'); if (!$file instanceof UploadedFile || $file->getError()) { throw new \RuntimeException('...'); } #1. UPLOAD THE IMAGE TO S3 #2. SAVE THE IMAGE DATA TO DYNAMODB $app['session']->getFlashBag()->add('alerts', 'success'); return $app->redirect('/'); } catch (\Exception $e) { $app['session']->getFlashBag()->add('alerts', 'danger'); return $app->redirect('/upload'); }

Slide 63

Slide 63 text

$s3 = $app['aws']->createS3(); $result = $s3->putObject([ 'Bucket' => 'selphpies', 'Key' => $file->getClientOriginalName(), 'Body' => fopen($file->getFileName(), 'r'), 'ACL' => 'public-read', ]);

Slide 64

Slide 64 text

// Automatically switches to multipart uploads // if the file is larger than default threshold. $result = $s3->upload( 'selphpies', $file->getClientOriginalName(), fopen($file->getPathname(), 'r'), 'public-read' );

Slide 65

Slide 65 text

$dynamoDb->putItem([ 'TableName' => 'selphpies', 'Item' => [ // ... 'src' => ['S' => $result['ObjectURL']], 'caption' => ['S' => $caption], ], ]);

Slide 66

Slide 66 text

$m = new (); $dynamoDb->putItem([ 'TableName' => 'selphpies', 'Item' => $m->marshalItem([ // ... 'src' => $result['ObjectURL’], 'caption' => $caption, ]), ]);

Slide 67

Slide 67 text

PHP such php so cloud wow very selfie much app #phpdoge

Slide 68

Slide 68 text

github.com/aws/aws-sdk-php/releases @awsforphp blogs.aws.amazon.com/php

Slide 69

Slide 69 text

github.com/aws/aws-sdk-php forums.aws.amazon.com

Slide 70

Slide 70 text

By Jeremy Lindblom (@jeremeamia)