SlideShare a Scribd company logo
1 of 33
Download to read offline
© 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 d
aep 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
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';
<?php
require '/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 w
w 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 h
h 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()
• 
// Result
$result = $s3Client->putObject([
    'Bucket' => 'your-bucket',
    'Key'    => 'docs/file.pdf',
    'Body'   => fopen('/path/to/file.pdf', 'r'),
]);
 
// Result
echo $result['ObjectURL'];
n t Promise fe
1
2
3
4
5
6
7
8
9
// Promise
$promise = $s3Client->putObjectAsync([
    'Bucket' => 'your-bucket',
    'Key'    => 'docs/file.pdf',
    'Body'   => fopen('/path/to/file.pdf', 'r'),
]);
 
// Result
$result = $promise->wait();
 
// Result
echo $result['ObjectURL'];
1
2
3
4
5
6
7
8
9
10
11
12
• 
Promise
Promise
Promise W
•  Promise h
Promise
h
Resolve
Reject
Promise
Promise
then
then
catch
Method Chain
$s3Client = new AwsS3S3Client([
    ‘region’ => ‘us-west-2’,
    ‘version’ => ‘2006-03-01’,
]);
 
// response
$buckets = $s3Client->listBuckets();
 
//
$promise = $s3Client->listBucketsAsync();
 
// request callback
$promise->then(
    //
    function (AwsResultInterface $buckets) {
        echo ‘My buckets are: ‘
             . implode(‘, ‘, $buckets->search(‘Buckets[].Name’));
    },
    //
    function ($reason) {
        echo "The promise was rejected with {$reason}";
    }
);
Promises
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
•  h A V Q M t b h v
h – c
•  r h b h h
t v c
$filesToUpload = [
    ‘/path/to/file/1.ext’,
    ‘/path/to/file/2.ext’,
    …
    ‘/path/to/file/10.ext’,
];
$promises = [];
// putObjectAsync
foreach ($filesToUpload as $path) {
    $promises []= $s3Client->putObjectAsync([
        ‘Bucket’ => $bucketName,
        ‘Key’ => basename($path),
        ‘SourceFile’ => $path,
    ]);
}
// promise fulfilled fulfilled allPomise
$allPromise = GuzzleHttpPromiseall($promises);
$allPromise->wait();
Promises
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
•  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 AwsSdk([‘region’ => ‘us-west-2’, ‘version’ => ‘latest’]);
$elasticacheClient = $sdk->get(‘elasticache’);
$s3Client = $sdk->get(‘s3’);
$promises = [];
// S3 bucket
for ($i = 0; $i < 3; $i++) {
    $promises []= $s3Client->createBucket([
        ‘Bucket’ => “my-bucket-$i”,
    ]);
}
// ElastiCache cluster
$cacheClusterId = uniqid(‘cache’);
$promises []= $elasticacheClient->createCacheCluster([
    ‘CacheClusterId’ => $cacheClusterId,
]);
// promise fulfilled fulfilled metaPomise
$metaPromise = GuzzleHttpPromiseall($promises);
$metaPromise->wait();
Waiters
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
•  S3 buckets ElastiCache cluster b v r b y u
AWS h u p c
•  $metaPromise createBucket createCacheCluster h
v w c
$waiterPromises = [];
// S3 Waiter
for ($i = 0; $i < 3; $i++) {
    $waiter = $s3Client->getWaiter(‘BucketExists’, [
        ‘Bucket’ => “my-bucket-$i”,
    ]);
    // Waiter promise
    $waiterPromises []= $waiter->promise();
}
// ElastiCache cluster Waiter
$waiterPromises []= $elasticacheClient
    ->getWaiter(‘CacheClusterAvailable’, [
        ‘CacheClusterId’ => $cacheClusterId,
    ])
    ->promise();
// waiterPromise fulfilled fulfilled metaWaiterPomise
$metaWaiterPromise = GuzzleHttpPromiseall($waiterPromises);
$metaWaiterPromise->wait();
Waiters
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
•  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
$s3Client = new AwsS3S3Client([
    ‘region’ => ‘us-west-2’,
    ‘version’ => ‘latest’,
]);
 
// Commands
$commands = [
    $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket1’]),
    $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket2’]),
    $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket3’]),
];
 
// Command pool
$pool = new AwsCommandPool($s3Client, $commands);
 
// Commands
$promise = $pool->promise();
 
// pool
$promise->wait();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Command Pool z H
•  g h u Promise b $s3Client-
>listObjectsAsync(…) h z v c b
6V I L AVVS – $pool->promise( h
b h hv v w c
•  Command Pool h 25 c
h 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 h4
h h5
h h6f 95(
h 2
11 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 5
Amazon SQS
Amazon SQS – o r
C7D
5
C7D
V RMDBD66 66
. .
4G 4G
. .
. .
4 I_V D D
V QSM A P
Apple APNS
Google GCM
Amazon ADM
Amazon SNS Mobile Push – zt
•  h w
•  p v w
k
z m k i
h
h
, h
- h
6 MIZM ASIZNV
LWVQ Z
. LWVQ Z4
/ LWVQ Z4
9 . A
k
3B3 3A
. .
Amazon SNS Mobile Push – zt
k
z 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 !

More Related Content

What's hot

Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 

What's hot (20)

Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOPHOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
 
Kubernetes API - deep dive into the kube-apiserver
Kubernetes API - deep dive into the kube-apiserverKubernetes API - deep dive into the kube-apiserver
Kubernetes API - deep dive into the kube-apiserver
 
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
[Community Open Camp] 給 PHP 開發者的 VS Code 指南[Community Open Camp] 給 PHP 開發者的 VS Code 指南
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
 
Seven perilous pitfalls to avoid with Java | DevNation Tech Talk
Seven perilous pitfalls to avoid with Java | DevNation Tech TalkSeven perilous pitfalls to avoid with Java | DevNation Tech Talk
Seven perilous pitfalls to avoid with Java | DevNation Tech Talk
 
Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?
 
BUILDING APPS WITH ASYNCIO
BUILDING APPS WITH ASYNCIOBUILDING APPS WITH ASYNCIO
BUILDING APPS WITH ASYNCIO
 
Concourse updates
Concourse updatesConcourse updates
Concourse updates
 
The journey of asyncio adoption in instagram
The journey of asyncio adoption in instagramThe journey of asyncio adoption in instagram
The journey of asyncio adoption in instagram
 
Ansible Best Practices - July 30
Ansible Best Practices - July 30Ansible Best Practices - July 30
Ansible Best Practices - July 30
 
Cutting the Kubernetes Monorepo in pieces – never learnt more about git
Cutting the Kubernetes Monorepo in pieces – never learnt more about gitCutting the Kubernetes Monorepo in pieces – never learnt more about git
Cutting the Kubernetes Monorepo in pieces – never learnt more about git
 
State in stateless serverless functions
State in stateless serverless functionsState in stateless serverless functions
State in stateless serverless functions
 
Working with Xcode and Swift Package Manager
Working with Xcode and Swift Package ManagerWorking with Xcode and Swift Package Manager
Working with Xcode and Swift Package Manager
 
Code reviews vs Pull requests
Code reviews vs Pull requestsCode reviews vs Pull requests
Code reviews vs Pull requests
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansible
 
Riot Games Scalable Data Warehouse Lecture at UCSB / UCLA
Riot Games Scalable Data Warehouse Lecture at UCSB / UCLARiot Games Scalable Data Warehouse Lecture at UCSB / UCLA
Riot Games Scalable Data Warehouse Lecture at UCSB / UCLA
 
Extending the Kube API
Extending the Kube APIExtending the Kube API
Extending the Kube API
 
Monitoring and Alerting with InfluxDB 2.0 | Nate Isley & Deniz Kusefoglu | In...
Monitoring and Alerting with InfluxDB 2.0 | Nate Isley & Deniz Kusefoglu | In...Monitoring and Alerting with InfluxDB 2.0 | Nate Isley & Deniz Kusefoglu | In...
Monitoring and Alerting with InfluxDB 2.0 | Nate Isley & Deniz Kusefoglu | In...
 
Be a microservices hero
Be a microservices heroBe a microservices hero
Be a microservices hero
 
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
 

Similar to AWS SDK for PHP のインストールから 始めるクラウドマスターへの道 〜 Promise による非同期オペレーション 〜

Similar to AWS SDK for PHP のインストールから 始めるクラウドマスターへの道 〜 Promise による非同期オペレーション 〜 (20)

AWS における サーバーレスの基礎からチューニングまで
AWS における サーバーレスの基礎からチューニングまでAWS における サーバーレスの基礎からチューニングまで
AWS における サーバーレスの基礎からチューニングまで
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
 
Presentation kyushu-2018
Presentation kyushu-2018Presentation kyushu-2018
Presentation kyushu-2018
 
AWS Serverless Workshop
AWS Serverless WorkshopAWS Serverless Workshop
AWS Serverless Workshop
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
 
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
 
AWS September Webinar Series - Running Microservices with Amazon EC2 Contain...
AWS September Webinar Series -  Running Microservices with Amazon EC2 Contain...AWS September Webinar Series -  Running Microservices with Amazon EC2 Contain...
AWS September Webinar Series - Running Microservices with Amazon EC2 Contain...
 
Sprockets
SprocketsSprockets
Sprockets
 
Parse, scale to millions
Parse, scale to millionsParse, scale to millions
Parse, scale to millions
 
Containerizing a REST API and Deploying to Kubernetes
Containerizing a REST API and Deploying to KubernetesContainerizing a REST API and Deploying to Kubernetes
Containerizing a REST API and Deploying to Kubernetes
 
Developing and deploying serverless applications (February 2017)
Developing and deploying serverless applications (February 2017)Developing and deploying serverless applications (February 2017)
Developing and deploying serverless applications (February 2017)
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)
 
AWS for Startups, London - Programming AWS
AWS for Startups, London - Programming AWSAWS for Startups, London - Programming AWS
AWS for Startups, London - Programming AWS
 
自己修復的なインフラ -Self-Healing Infrastructure-
自己修復的なインフラ -Self-Healing Infrastructure-自己修復的なインフラ -Self-Healing Infrastructure-
自己修復的なインフラ -Self-Healing Infrastructure-
 
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
 
DevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office HoursDevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office Hours
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Building Serverless APIs on AWS
Building Serverless APIs on AWSBuilding Serverless APIs on AWS
Building Serverless APIs on AWS
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 

More from 崇之 清水

RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
崇之 清水
 
クラウドを活用したセンシング/モニタリングなどデータ分析の実現
クラウドを活用したセンシング/モニタリングなどデータ分析の実現クラウドを活用したセンシング/モニタリングなどデータ分析の実現
クラウドを活用したセンシング/モニタリングなどデータ分析の実現
崇之 清水
 
日本語でおk AI スピーカーを作ってみた
日本語でおk AI スピーカーを作ってみた日本語でおk AI スピーカーを作ってみた
日本語でおk AI スピーカーを作ってみた
崇之 清水
 
WordPress RESTful API & Amazon API Gateway - WordCamp Kansai 2016
WordPress RESTful API & Amazon API Gateway - WordCamp Kansai 2016WordPress RESTful API & Amazon API Gateway - WordCamp Kansai 2016
WordPress RESTful API & Amazon API Gateway - WordCamp Kansai 2016
崇之 清水
 

More from 崇之 清水 (20)

WordPress RESTful API & Amazon API Gateway (English version)
WordPress RESTful API & Amazon API Gateway (English version)WordPress RESTful API & Amazon API Gateway (English version)
WordPress RESTful API & Amazon API Gateway (English version)
 
知らなきゃ損なアップデートを振り返り(2020年分)- いにしえのサービスから勝手にチョイス
知らなきゃ損なアップデートを振り返り(2020年分)- いにしえのサービスから勝手にチョイス知らなきゃ損なアップデートを振り返り(2020年分)- いにしえのサービスから勝手にチョイス
知らなきゃ損なアップデートを振り返り(2020年分)- いにしえのサービスから勝手にチョイス
 
マイクロサービスを AWS サーバレス&コンテナで実装する方法
マイクロサービスを AWS サーバレス&コンテナで実装する方法マイクロサービスを AWS サーバレス&コンテナで実装する方法
マイクロサービスを AWS サーバレス&コンテナで実装する方法
 
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
 
クラウドを活用したセンシング/モニタリングなどデータ分析の実現
クラウドを活用したセンシング/モニタリングなどデータ分析の実現クラウドを活用したセンシング/モニタリングなどデータ分析の実現
クラウドを活用したセンシング/モニタリングなどデータ分析の実現
 
AWS 主要なサービスアップデート 6/3-11/28
AWS 主要なサービスアップデート 6/3-11/28AWS 主要なサービスアップデート 6/3-11/28
AWS 主要なサービスアップデート 6/3-11/28
 
5分でサーバーレスの環境構築から本番デプロイまでやったろやないか! - Serverless Meetup Osaka #4 LT
5分でサーバーレスの環境構築から本番デプロイまでやったろやないか! - Serverless Meetup Osaka #4 LT5分でサーバーレスの環境構築から本番デプロイまでやったろやないか! - Serverless Meetup Osaka #4 LT
5分でサーバーレスの環境構築から本番デプロイまでやったろやないか! - Serverless Meetup Osaka #4 LT
 
サーバレスアプリケーションの入門と実践 - AWS Cloud Roadshow 2017 Osaka
サーバレスアプリケーションの入門と実践 - AWS Cloud Roadshow 2017 Osakaサーバレスアプリケーションの入門と実践 - AWS Cloud Roadshow 2017 Osaka
サーバレスアプリケーションの入門と実践 - AWS Cloud Roadshow 2017 Osaka
 
データ分析 on AWS
データ分析 on AWSデータ分析 on AWS
データ分析 on AWS
 
日本語でおk AI スピーカーを作ってみた
日本語でおk AI スピーカーを作ってみた日本語でおk AI スピーカーを作ってみた
日本語でおk AI スピーカーを作ってみた
 
Amazon Web Services (AWS) のご紹介
Amazon Web Services (AWS) のご紹介Amazon Web Services (AWS) のご紹介
Amazon Web Services (AWS) のご紹介
 
Amazon AI のスゴいデモ(仮) - Serverless Meetup Osaka
Amazon AI のスゴいデモ(仮) - Serverless Meetup OsakaAmazon AI のスゴいデモ(仮) - Serverless Meetup Osaka
Amazon AI のスゴいデモ(仮) - Serverless Meetup Osaka
 
Amazon Pinpoint - re:Invent Serverless Follow Up - 20161207
Amazon Pinpoint - re:Invent Serverless Follow Up - 20161207Amazon Pinpoint - re:Invent Serverless Follow Up - 20161207
Amazon Pinpoint - re:Invent Serverless Follow Up - 20161207
 
WordPress RESTful API & Amazon API Gateway - WordCamp Kansai 2016
WordPress RESTful API & Amazon API Gateway - WordCamp Kansai 2016WordPress RESTful API & Amazon API Gateway - WordCamp Kansai 2016
WordPress RESTful API & Amazon API Gateway - WordCamp Kansai 2016
 
Amazon API Gateway を活用したゲームサーバー構築
Amazon API Gateway を活用したゲームサーバー構築Amazon API Gateway を活用したゲームサーバー構築
Amazon API Gateway を活用したゲームサーバー構築
 
関西スタートアップAWS勉強会 スタートアップ最新事例
関西スタートアップAWS勉強会 スタートアップ最新事例関西スタートアップAWS勉強会 スタートアップ最新事例
関西スタートアップAWS勉強会 スタートアップ最新事例
 
スタートアップ向け構成例とAWS活用事例(福岡市スタートアップカフェ)
スタートアップ向け構成例とAWS活用事例(福岡市スタートアップカフェ)スタートアップ向け構成例とAWS活用事例(福岡市スタートアップカフェ)
スタートアップ向け構成例とAWS活用事例(福岡市スタートアップカフェ)
 
Amazon Aurora の活用 - Developers.IO in OSAKA
Amazon Aurora の活用 - Developers.IO in OSAKAAmazon Aurora の活用 - Developers.IO in OSAKA
Amazon Aurora の活用 - Developers.IO in OSAKA
 
SA プライムなう! - AWS IoT とロボットアームでお絵かき
SA プライムなう! - AWS IoT とロボットアームでお絵かきSA プライムなう! - AWS IoT とロボットアームでお絵かき
SA プライムなう! - AWS IoT とロボットアームでお絵かき
 
Amazon Aurora の活用
Amazon Aurora の活用Amazon Aurora の活用
Amazon Aurora の活用
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

AWS SDK for PHP のインストールから 始めるクラウドマスターへの道 〜 Promise による非同期オペレーション 〜

  • 1. © 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 d aep l w . 9A e n t
  • 2. 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
  • 3. z i M P AWS IoT ls z i MQTT h h h
  • 4. 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 etc.
  • 5. 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/
  • 6. •  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
  • 7. 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';
  • 8. •  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'; <?php require '/path/to/aws-autoloader.php';
  • 10. 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
  • 11. •  i •  h , b h u w rb API h v b g •  i h h •  API yb h h h b w w r h w c AWS SDK for PHP “Version 3”
  • 12. •  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' ]);
  • 13. •  AWS SDK for PHP Version 3 Guzzle Promises t b Promises w c •  SDK h API h h 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()
  • 14. •  // Result $result = $s3Client->putObject([     'Bucket' => 'your-bucket',     'Key'    => 'docs/file.pdf',     'Body'   => fopen('/path/to/file.pdf', 'r'), ]);   // Result echo $result['ObjectURL']; n t Promise fe 1 2 3 4 5 6 7 8 9 // Promise $promise = $s3Client->putObjectAsync([     'Bucket' => 'your-bucket',     'Key'    => 'docs/file.pdf',     'Body'   => fopen('/path/to/file.pdf', 'r'), ]);   // Result $result = $promise->wait();   // Result echo $result['ObjectURL']; 1 2 3 4 5 6 7 8 9 10 11 12 • 
  • 15. Promise Promise Promise W •  Promise h Promise h Resolve Reject Promise Promise then then catch Method Chain
  • 16. $s3Client = new AwsS3S3Client([     ‘region’ => ‘us-west-2’,     ‘version’ => ‘2006-03-01’, ]);   // response $buckets = $s3Client->listBuckets();   // $promise = $s3Client->listBucketsAsync();   // request callback $promise->then(     //     function (AwsResultInterface $buckets) {         echo ‘My buckets are: ‘              . implode(‘, ‘, $buckets->search(‘Buckets[].Name’));     },     //     function ($reason) {         echo "The promise was rejected with {$reason}";     } ); Promises 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 •  h A V Q M t b h v h – c •  r h b h h t v c
  • 17. $filesToUpload = [     ‘/path/to/file/1.ext’,     ‘/path/to/file/2.ext’,     …     ‘/path/to/file/10.ext’, ]; $promises = []; // putObjectAsync foreach ($filesToUpload as $path) {     $promises []= $s3Client->putObjectAsync([         ‘Bucket’ => $bucketName,         ‘Key’ => basename($path),         ‘SourceFile’ => $path,     ]); } // promise fulfilled fulfilled allPomise $allPromise = GuzzleHttpPromiseall($promises); $allPromise->wait(); Promises 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 •  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
  • 18. $sdk = new AwsSdk([‘region’ => ‘us-west-2’, ‘version’ => ‘latest’]); $elasticacheClient = $sdk->get(‘elasticache’); $s3Client = $sdk->get(‘s3’); $promises = []; // S3 bucket for ($i = 0; $i < 3; $i++) {     $promises []= $s3Client->createBucket([         ‘Bucket’ => “my-bucket-$i”,     ]); } // ElastiCache cluster $cacheClusterId = uniqid(‘cache’); $promises []= $elasticacheClient->createCacheCluster([     ‘CacheClusterId’ => $cacheClusterId, ]); // promise fulfilled fulfilled metaPomise $metaPromise = GuzzleHttpPromiseall($promises); $metaPromise->wait(); Waiters 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 •  S3 buckets ElastiCache cluster b v r b y u AWS h u p c •  $metaPromise createBucket createCacheCluster h v w c
  • 19. $waiterPromises = []; // S3 Waiter for ($i = 0; $i < 3; $i++) {     $waiter = $s3Client->getWaiter(‘BucketExists’, [         ‘Bucket’ => “my-bucket-$i”,     ]);     // Waiter promise     $waiterPromises []= $waiter->promise(); } // ElastiCache cluster Waiter $waiterPromises []= $elasticacheClient     ->getWaiter(‘CacheClusterAvailable’, [         ‘CacheClusterId’ => $cacheClusterId,     ])     ->promise(); // waiterPromise fulfilled fulfilled metaWaiterPomise $metaWaiterPromise = GuzzleHttpPromiseall($waiterPromises); $metaWaiterPromise->wait(); Waiters 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 •  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
  • 20. Command Pool •  h h Command Pool w c •  Command Pool Client Command c b6V I L b h getCommand w c // S3Client $s3Client = new AwsS3S3Client([     ‘region’ => ‘us-west-2’,     ‘version’ => ‘latest’, ]);   // Commands $commands = [     $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket1’]),     $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket2’]),     $s3Client->getCommand(‘ListObjects’, [‘Bucket’ => ‘bucket3’]), ];   // Command pool $pool = new AwsCommandPool($s3Client, $commands);   // Commands $promise = $pool->promise();   // pool $promise->wait(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
  • 21. Command Pool z H •  g h u Promise b $s3Client- >listObjectsAsync(…) h z v c b 6V I L AVVS – $pool->promise( h b h hv v w c •  Command Pool h 25 c h h w c AWS SDK for PHP D, Command Pool http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/commands.html#commandpool
  • 22. fe AWS r Wi o py
  • 23. Amazon S3 – n k u •  h h •  h h h h h4 h h5 h h6f 95( h 2 11 111111111 h u
  • 24. Amazon S3 – n k u C7D 5 4G 4G C7D 66 66 D, . . . . b
  • 25. Amazon DynamoDB – NoSQL w •  e h •  h , 4G v •  h CMIL QZM b h v w h
  • 26. 6 6 Amazon DynamoDB – NoSQL w 5 6 6 7 I V75 . .. .
  • 27. Amazon SQS – o r •  @ ZW Z 4 b W Z 5 •  4 @ ZW Z y •  5 v u •  DBD b v 4 5 4 5 Amazon SQS
  • 28. Amazon SQS – o r C7D 5 C7D V RMDBD66 66 . . 4G 4G . . . .
  • 29. 4 I_V D D V QSM A P Apple APNS Google GCM Amazon ADM Amazon SNS Mobile Push – zt •  h w •  p v w
  • 30. k z m k i h h , h - h 6 MIZM ASIZNV LWVQ Z . LWVQ Z4 / LWVQ Z4 9 . A k 3B3 3A . . Amazon SNS Mobile Push – zt
  • 31. k z m k i . h LWVQ Z4 9 . A 3B3 3A : , A SQ P- h h . . Amazon SNS Mobile Push – zt
  • 32. •  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