Upload
-
View
3.196
Download
2
Embed Size (px)
Citation preview
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Takayuki Shimizu @shimy_net Solutions Architect, Amazon Web Services Japan K.K. July 16, 2016 – PHP Conference Kansai 2016
/ / . . k daep l w. 9A e n t
B• 3:3E :9 / 9 9 3 PQ H MZ
/• w• BB DDD A 9 A 3 B A 9 E B
QKR ZI Z 6 a a a 4& &:4& &:4 Q M Q a 5QRM QZP 7 I V75a A ZPIOV I D QZKP 4 ZV IZQV
z i M P
AWS IoT
ls z i MQTT
h h h
Amazon Web Services W
• , h b,. h• 0) h
Amazon EC2 AWS
Lambda
Amazon Kinesis
Amazon S3 Amazon API
Gateway
Amazon SNS
Amazon RDS
AWS IoT
SSS"etc.
T h Pe • 4 D h b h hv w 4A
Ruby iOS Python Android Node.js .NET PHP JavaScript Java Xamarin
AWS Management Console k AWS CLI k
AWS SDKs k
https://aws.amazon.com/jp/tools/
• A:A u 4 D h w• 4 D h v 4A IW
AWS SDK for PHP W H
b
Put, Get
DB
AWS SDK for PHP
h h
h
h h
D, h
1. Composer k
2. u AWS SDK hk
3. Require Composer n
• Composer • PHP h
h h
Composer k
curl -sS https://getcomposer.org/installer | php
php composer.phar require aws/aws-sdk-php
<?php require 'vendor/autoload.php';
• Phar h
• PZZW2((LVK I I I_V KV (I & LR&WPW( ,(LV SVIL(I WPI
• G A h
• PZZW2((LVK I I I_V KV (I & LR&WPW( ,(LV SVIL(I _QW
b
<?php require '/path/to/aws.phar';
<?phprequire '/path/to/aws-autoloader.php';
Phar
: http://yomikata.org/word/phar
AWS Service Provider for Laravel Version 3.1.0 – For Version 3 of the AWS SDK for PHP and Laravel 5.1 Older Versions:
2.0 branch – For Version 2 of the AWS SDK for PHP and Laravel 5.0 1.0 branch – For Version 2 of the AWS SDK for PHP and Laravel 4.x
AWS SDK ZF2 Module (Zend Framework 2) Version 2.1.0 – For Version 3 of the AWS SDK for PHP and ZF2 Older Versions:
1.2 branch – For Version 2 of the AWS SDK for PHP and ZF2
AWS Service Provider for Silex Version 3.0.0 – For Version 3 of the AWS SDK for PHP and Silex 2 Older Versions:
2.0 branch – For Version 3 of the AWS SDK for PHP and Silex 1.x 1.1. branch – For Version 2 of the AWS SDK for PHP and Silex 1.x
Framework-specific modules support Version 3 of AWS SDK
• i• h , b h u w rb
API h v b g
• i h h • API yb
h h h b ww r h w c
AWS SDK for PHP “Version 3”
• composer.json
• Factory -> New
Version 2 -> Version 3 iz
"require": { - "aws/aws-sdk-php": "2.*" + "aws/aws-sdk-php": "3.*"
},
$ composer.phar update
$ec2client = Ec2Client::factory([ 'region' => 'ap-northeast-1'
]);
$ec2client = new Ec2Client(['region' => 'ap-northeast-1','version' => 'latest'
]);
• AWS SDK for PHP Version 3 Guzzle Promises t b Promises w c
• SDK h API hh h t b h Async
w c
• h Promise bPromise h fulfill ub h reject c
n t W Promise
// Sync$client->get()
// Async$client->getAsync()
• // ��>��,<2 Result AJE@BI'��)=<$result = $s3Client->putObject([ 'Bucket' => 'your-bucket', 'Key' => 'docs/file.pdf', 'Body' => fopen('/path/to/file.pdf', 'r'),]); // Result AJE@BI>�*0��4?BGF1(<echo $result['ObjectURL'];
n t Promise fe
123456789
// ��>��,<2 Promise AJE@BI'!�4��)=<$promise = $s3Client->putObjectAsync([ 'Bucket' => 'your-bucket', 'Key' => 'docs/file.pdf', 'Body' => fopen('/path/to/file.pdf', 'r'),]); // ��' �*0 Result AJE@BI>�1(<5>�/$result = $promise->wait(); // -5�$�CTO2+:&4 Result AJE@BI>�*0��4?BGF1(<echo $result['ObjectURL'];
123456789
101112
•
Promise
Promise
Promise W
• Promise h
Promise h
#Resolve
#Reject
Promise
Promise then
then
catch
Method Chain
$s3Client = new \Aws\S3\S3Client([ ‘region’ => ‘us-west-2’, ‘version’ => ‘2006-03-01’,]); // �ALPTDMR6 response '�;=<91JQHB)=<$buckets = $s3Client->listBuckets(); // !�ALPTDMR6JQHB)=3%$promise = $s3Client->listBucketsAsync(); // request ' �*.2(4��,< callback >��1(<$promise->then( // �� function (\Aws\ResultInterface $buckets) { echo ‘My buckets are: ‘ . implode(‘, ‘, $buckets->search(‘Buckets[].Name’)); }, // �� function ($reason) { echo "The promise was rejected with {$reason}"; });
Promises
123456789
1011121314151617181920212223
• h A V Q M ���� t b h vh – c
• ��������������� ������� r h b h ht v ���� c
$filesToUpload = [ ‘/path/to/file/1.ext’, ‘/path/to/file/2.ext’, … ‘/path/to/file/10.ext’,];$promises = [];
// OTK��40"putObjectAsync !�ALPTDMR>CTOforeach ($filesToUpload as $path) { $promises []= $s3Client->putObjectAsync([ ‘Bucket’ => $bucketName, ‘Key’ => basename($path), ‘SourceFile’ => $path, ]);}
// promise ',80 fulfilled *.2(4 fulfilled ,<:&372/5 allPomise >��$allPromise = \GuzzleHttp\Promise\all($promises);$allPromise->wait();
Promises
123456789
1011121314151617181920
• A V Q M v h t p c• D, 5 KRMZ ) h b h
h yb ) ������� b ) v ���� – c
PZZW2((LVK I I I_V KV (I & LR&WPW( ,(O QLM(O QLM(W V Q M PZ S
$sdk = new \Aws\Sdk([‘region’ => ‘us-west-2’, ‘version’ => ‘latest’]);$elasticacheClient = $sdk->get(‘elasticache’);$s3Client = $sdk->get(‘s3’);$promises = [];
// S3 bucket 5��for ($i = 0; $i < 3; $i++) { $promises []= $s3Client->createBucket([ ‘Bucket’ => “my-bucket-$i”, ]);}
// ElastiCache cluster 5��$cacheClusterId = uniqid(‘cache’);$promises []= $elasticacheClient->createCacheCluster([ ‘CacheClusterId’ => $cacheClusterId,]);
// promise ',80 fulfilled *.2(4 fulfilled ,<:&372/5 metaPomise >��$metaPromise = \GuzzleHttp\Promise\all($promises);$metaPromise->wait();
Waiters
123456789
101112131415161718192021
• S3 buckets ElastiCache cluster b v r b y u AWS h u p c
• �$metaPromise� ���� createBucket createCacheCluster hv w c
$waiterPromises = [];
// S3 �5"Waiter >��for ($i = 0; $i < 3; $i++) { $waiter = $s3Client->getWaiter(‘BucketExists’, [ ‘Bucket’ => “my-bucket-$i”, ]); // Waiter >���*0 promise >� $waiterPromises []= $waiter->promise();}
// ElastiCache cluster �5 Waiter >��$waiterPromises []= $elasticacheClient ->getWaiter(‘CacheClusterAvailable’, [ ‘CacheClusterId’ => $cacheClusterId, ]) ->promise();
// waiterPromise ',80 fulfilled *.2(4 fulfilled ,<:&372/5 metaWaiterPomise >��$metaWaiterPromise = \GuzzleHttp\Promise\all($waiterPromises);$metaWaiterPromise->wait();
Waiters
123456789
101112131415161718192021
• h v w r ������ r vp c• s–bS3Client wailUntil s–b Bucket v v veeea
$s3Client->waitUntil(‘BucketExists’, [‘Bucket’ => $bucketName]);�
http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/waiters.html
Command Pool • h h Command Pool w c• Command Pool Client Command c b6V I L
b h getCommand w c
// S3Client 5��$s3Client = new \Aws\S3\S3Client([ ‘region’ => ‘us-west-2’, ‘version’ => ‘latest’,]); // Commands NFI5��$commands = [ $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket1’]), $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket2’]), $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket3’]),]; // Command pool 5��$pool = new \Aws\CommandPool($s3Client, $commands); // Commands NFI5!�5��> �$promise = $pool->promise(); // ��4 pool 5 �>�/$promise->wait();
123456789
101112131415161718192021
Command Pool z H
• g h u Promise b $s3Client->listObjectsAsync(…) h z v c b6V I L AVVS – $pool->promise(�� h
b h hv v w c
• Command Pool h 25 ch h w c
AWS SDK for PHP D,
Command Pool
http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/commands.html#commandpool
fe AWS r Wi o py
Amazon S3 – n k u
• h h• h h
h
h h4h h5
h h6f 95( h 211 111111111
h u
Amazon S3 – n k u
C7D
5
4G 4G
C7D
66 66 D,
. . . .
b
Amazon DynamoDB – NoSQL w
• e h• h , 4G v• h CMIL QZM b h
v w
h
6 6
Amazon DynamoDB – NoSQL w
5
6 6
7 I V75
. .. .
Amazon SQS – o r
• @ ZW Z 4 b W Z 5 • 4 @ ZW Z y• 5 v u
• DBD b v
4 5
4 5Amazon SQS
Amazon SQS – o r
C7D
5
C7D
V RMDBD66 66. .
4G 4G
. .
. .
4 I_V D DV QSM A P
Apple APNS
Google GCM
Amazon ADM
Amazon SNS Mobile Push – zt
• h w• p v w
kz m k i
h
h, h
- h6 MIZM ASIZNV
LWVQ Z
. LWVQ Z4
/ LWVQ Z4
9 . A
k
3B3 3A. .
Amazon SNS Mobile Push – zt
kz m k i
. h
LWVQ Z4
9 . A
3B3 3A
:
, A SQ P- h
h. .
Amazon SNS Mobile Push – zt
• 4 D D7 NV A:A EM QV , • % h
• h• A V Q M % IQZM 6V I L AVVS
• y r 4 D h h• 4 I_V D,% 7 I V75% DBD D D
_Wa
Thank you !