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()
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
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