Upload
Download free for 30 days
Login
Submit Search
[AWSマイスターシリーズ] AWS SDK for PHP / Ruby / boto(Python) / JavaScript in Node.js
15 likes
10,727 views
Amazon Web Services Japan
1 of 68
Download now
Downloaded 48 times
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
More Related Content
PPTX
今だから!Amazon CloudFront 徹底活用
Yasuhiro Araki, Ph.D
PPTX
分散トレーシングAWS:X-Rayとの上手い付き合い方
Recruit Lifestyle Co., Ltd.
PDF
AWSの課金体系
Amazon Web Services Japan
PDF
[AWSマイスターシリーズ] AWS Elastic Beanstalk
Amazon Web Services Japan
PDF
[JAWS DAYS 2019] Amazon DocumentDB(with MongoDB Compatibility)入門
Shuji Kikuchi
PDF
AWS Black Belt Online Seminar コストの観点から見るアカウント管理
Amazon Web Services Japan
PDF
AWS EC2 Eメール制限解除 - 逆引き(rDNS)設定 申請手順
Amazon Web Services Japan
PDF
AWS Black Belt Online Seminar 2017 Amazon Aurora
Amazon Web Services Japan
今だから!Amazon CloudFront 徹底活用
Yasuhiro Araki, Ph.D
分散トレーシングAWS:X-Rayとの上手い付き合い方
Recruit Lifestyle Co., Ltd.
AWSの課金体系
Amazon Web Services Japan
[AWSマイスターシリーズ] AWS Elastic Beanstalk
Amazon Web Services Japan
[JAWS DAYS 2019] Amazon DocumentDB(with MongoDB Compatibility)入門
Shuji Kikuchi
AWS Black Belt Online Seminar コストの観点から見るアカウント管理
Amazon Web Services Japan
AWS EC2 Eメール制限解除 - 逆引き(rDNS)設定 申請手順
Amazon Web Services Japan
AWS Black Belt Online Seminar 2017 Amazon Aurora
Amazon Web Services Japan
What's hot
(20)
PDF
20170725 black belt_monitoring_on_aws
Amazon Web Services Japan
PDF
DevOps with Database on AWS
Amazon Web Services Japan
PDF
20210309 AWS Black Belt Online Seminar AWS Audit Manager
Amazon Web Services Japan
PDF
Usage Report(利用レポート)のダウンロード・開き方
Amazon Web Services Japan
PDF
Jmespathをもっと広めたい
Tetsunori Nishizawa
PDF
Dockerクイックツアー
Etsuji Nakai
PPTX
backlogsでもCI/CDする夢を見る
Takeru Maehara
PDF
Amazon Redshift パフォーマンスチューニングテクニックと最新アップデート
Amazon Web Services Japan
PDF
AWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMail
Amazon Web Services Japan
PDF
AWS Black Belt Online Seminar 2017 Amazon DynamoDB
Amazon Web Services Japan
PDF
20190424 AWS Black Belt Online Seminar Amazon Aurora MySQL
Amazon Web Services Japan
PPTX
20220409 AWS BLEA 開発にあたって検討したこと
Amazon Web Services Japan
PDF
Infrastructure as Code (IaC) 談義 2022
Amazon Web Services Japan
PDF
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
Amazon Web Services Japan
PDF
20200826 AWS Black Belt Online Seminar AWS CloudFormation
Amazon Web Services Japan
PPTX
Awsをオンプレドメコンに連携させる
Syuichi Murashima
PDF
【JAWS DAYS 2016】ランサーズを支えるAurora
Yuki Kanazawa
PDF
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
Amazon Web Services Japan
PDF
AWS Black Belt Online Seminar 2016 AWS CloudFormation
Amazon Web Services Japan
PDF
AWSのログ管理ベストプラクティス
Akihiro Kuwano
20170725 black belt_monitoring_on_aws
Amazon Web Services Japan
DevOps with Database on AWS
Amazon Web Services Japan
20210309 AWS Black Belt Online Seminar AWS Audit Manager
Amazon Web Services Japan
Usage Report(利用レポート)のダウンロード・開き方
Amazon Web Services Japan
Jmespathをもっと広めたい
Tetsunori Nishizawa
Dockerクイックツアー
Etsuji Nakai
backlogsでもCI/CDする夢を見る
Takeru Maehara
Amazon Redshift パフォーマンスチューニングテクニックと最新アップデート
Amazon Web Services Japan
AWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMail
Amazon Web Services Japan
AWS Black Belt Online Seminar 2017 Amazon DynamoDB
Amazon Web Services Japan
20190424 AWS Black Belt Online Seminar Amazon Aurora MySQL
Amazon Web Services Japan
20220409 AWS BLEA 開発にあたって検討したこと
Amazon Web Services Japan
Infrastructure as Code (IaC) 談義 2022
Amazon Web Services Japan
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
Amazon Web Services Japan
20200826 AWS Black Belt Online Seminar AWS CloudFormation
Amazon Web Services Japan
Awsをオンプレドメコンに連携させる
Syuichi Murashima
【JAWS DAYS 2016】ランサーズを支えるAurora
Yuki Kanazawa
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
Amazon Web Services Japan
AWS Black Belt Online Seminar 2016 AWS CloudFormation
Amazon Web Services Japan
AWSのログ管理ベストプラクティス
Akihiro Kuwano
Ad
Similar to [AWSマイスターシリーズ] AWS SDK for PHP / Ruby / boto(Python) / JavaScript in Node.js
(20)
PDF
20120528 aws meister-reloaded-awssd-kforjava-public
Amazon Web Services Japan
PDF
[AWSマイスターシリーズ] AWS SDK for Java / .NET
Amazon Web Services Japan
PDF
[AWS Developers Meetup 2017] DeveloperのためのライブAWSウォークスルー 〜 AWS SDKの使い方 〜
Atsushi Fukui
PDF
AWS Black Belt Techシリーズ AWS SDK
Amazon Web Services Japan
PDF
AWS Black Belt Online Seminar AWSサービスを利用したアプリケーション開発を始めよう
Amazon Web Services Japan
PDF
[AWSマイスターシリーズ] AWS Client Side SDK -Android,iOS & JavaScript-
Amazon Web Services Japan
PDF
Programming AWS with Perl at YAPC::Asia 2013
Yasuhiro Horiuchi
PDF
AWS Black Belt Techシリーズ Amazon Elastic Compute Cloud (Amazon EC2)
Amazon Web Services Japan
PDF
Cloud Programing for beginner
Satoru Ishikawa
PDF
AWS SDK for Android and iOS
Amazon Web Services Japan
PDF
AWS SDK for Haskell開発
Nomura Yusuke
PDF
AWSマイスターシリーズReloaded -AWS SDK for .NET-
Amazon Web Services Japan
PDF
AWS初心者向けWebinar AWSクラウドでのWindowsの実行
Amazon Web Services Japan
PDF
Aws tools for power shellをつかいこなそう
Genta Watanabe
PPTX
Awsについて
Naoyuki Sano
PDF
Windows 開発者のための Dev&Ops on AWS
Amazon Web Services Japan
PDF
AWS Update 2011/10
Akio Katayama
PDF
AWS meets Android - "AWS SDK for Android"で開発を楽にしよう!
SORACOM, INC
PDF
Awsビギナー向け資料 ec2 20111124
satoshi
PDF
AWS初心者向けWebinar .NET開発者のためのAWS超入門
Amazon Web Services Japan
20120528 aws meister-reloaded-awssd-kforjava-public
Amazon Web Services Japan
[AWSマイスターシリーズ] AWS SDK for Java / .NET
Amazon Web Services Japan
[AWS Developers Meetup 2017] DeveloperのためのライブAWSウォークスルー 〜 AWS SDKの使い方 〜
Atsushi Fukui
AWS Black Belt Techシリーズ AWS SDK
Amazon Web Services Japan
AWS Black Belt Online Seminar AWSサービスを利用したアプリケーション開発を始めよう
Amazon Web Services Japan
[AWSマイスターシリーズ] AWS Client Side SDK -Android,iOS & JavaScript-
Amazon Web Services Japan
Programming AWS with Perl at YAPC::Asia 2013
Yasuhiro Horiuchi
AWS Black Belt Techシリーズ Amazon Elastic Compute Cloud (Amazon EC2)
Amazon Web Services Japan
Cloud Programing for beginner
Satoru Ishikawa
AWS SDK for Android and iOS
Amazon Web Services Japan
AWS SDK for Haskell開発
Nomura Yusuke
AWSマイスターシリーズReloaded -AWS SDK for .NET-
Amazon Web Services Japan
AWS初心者向けWebinar AWSクラウドでのWindowsの実行
Amazon Web Services Japan
Aws tools for power shellをつかいこなそう
Genta Watanabe
Awsについて
Naoyuki Sano
Windows 開発者のための Dev&Ops on AWS
Amazon Web Services Japan
AWS Update 2011/10
Akio Katayama
AWS meets Android - "AWS SDK for Android"で開発を楽にしよう!
SORACOM, INC
Awsビギナー向け資料 ec2 20111124
satoshi
AWS初心者向けWebinar .NET開発者のためのAWS超入門
Amazon Web Services Japan
Ad
More from Amazon Web Services Japan
(20)
PDF
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
Amazon Web Services Japan
PDF
202205 AWS Black Belt Online Seminar Amazon FSx for OpenZFS
Amazon Web Services Japan
PDF
202204 AWS Black Belt Online Seminar AWS IoT Device Defender
Amazon Web Services Japan
PDF
202204 AWS Black Belt Online Seminar Amazon Connect を活用したオンコール対応の実現
Amazon Web Services Japan
PDF
202204 AWS Black Belt Online Seminar Amazon Connect Salesforce連携(第1回 CTI Adap...
Amazon Web Services Japan
PDF
Amazon Game Tech Night #25 ゲーム業界向け機械学習最新状況アップデート
Amazon Web Services Japan
PDF
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
Amazon Web Services Japan
PDF
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
Amazon Web Services Japan
PDF
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
Amazon Web Services Japan
PDF
Amazon QuickSight の組み込み方法をちょっぴりDD
Amazon Web Services Japan
PDF
マルチテナント化で知っておきたいデータベースのこと
Amazon Web Services Japan
PDF
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
Amazon Web Services Japan
PDF
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
Amazon Web Services Japan
PDF
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
Amazon Web Services Japan
PDF
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
Amazon Web Services Japan
PPTX
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
Amazon Web Services Japan
PDF
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
Amazon Web Services Japan
PDF
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
Amazon Web Services Japan
PDF
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
Amazon Web Services Japan
PDF
20211209 Ops-JAWS Re invent2021re-cap-cloud operations
Amazon Web Services Japan
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
Amazon Web Services Japan
202205 AWS Black Belt Online Seminar Amazon FSx for OpenZFS
Amazon Web Services Japan
202204 AWS Black Belt Online Seminar AWS IoT Device Defender
Amazon Web Services Japan
202204 AWS Black Belt Online Seminar Amazon Connect を活用したオンコール対応の実現
Amazon Web Services Japan
202204 AWS Black Belt Online Seminar Amazon Connect Salesforce連携(第1回 CTI Adap...
Amazon Web Services Japan
Amazon Game Tech Night #25 ゲーム業界向け機械学習最新状況アップデート
Amazon Web Services Japan
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
Amazon Web Services Japan
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
Amazon Web Services Japan
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
Amazon Web Services Japan
Amazon QuickSight の組み込み方法をちょっぴりDD
Amazon Web Services Japan
マルチテナント化で知っておきたいデータベースのこと
Amazon Web Services Japan
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
Amazon Web Services Japan
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
Amazon Web Services Japan
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
Amazon Web Services Japan
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
Amazon Web Services Japan
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
Amazon Web Services Japan
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
Amazon Web Services Japan
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
Amazon Web Services Japan
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
Amazon Web Services Japan
20211209 Ops-JAWS Re invent2021re-cap-cloud operations
Amazon Web Services Japan
[AWSマイスターシリーズ] AWS SDK for PHP / Ruby / boto(Python) / JavaScript in Node.js
1.
re:G ene rate AWS マイスターシリーズ AWS
SDK for PHP & AWS SDK for Ruby & boto(Python) & JavaScript in Node.js 2013.12.20 アマゾン データ サービス ジャパン株式会社 ソリューションアーキテクト 今井 榎並 蒋 © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
2.
ウェビナー(Webセミナー)へようこそ! ! 参加者は、⾃自動的にミュートになっています !
質問を投げることができます! § GoToWebinarの仕組みを使って、書き込んでください § ただし環境によっては、⽇日本語の直接⼊入⼒力力ができないので、 お⼿手数ですが、テキストエディタ等に打ち込んでから、 コピペしてください § 最後のQ&Aの時間で、できるだけ回答させて頂きます § 書き込んだ質問は、主催者にしか⾒見見えません ! Twitterのハッシュタグは#jawsugでどうぞ 2 © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
3.
Webセミナー 週刊AWSマイスターシリーズ re:Generate! ! AWSマイスターシリーズ §
12⽉月4⽇日 AWS re:Invent アップデート振り返り § 12⽉月11⽇日 AWS SDK for Java/.Net § 申し込みサイト § http://aws.amazon.com/jp/event_̲schedule/ § 過去資料料集 § http://aws.amazon.com/jp/aws-‐‑‒meister/ 3 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
4.
Agenda ! AWS
SDK 概要 ! AWS SDK for PHP ! boto(Python) ! AWS SDK for Ruby ! AWS SDK for JavaScript in Node.js ! まとめ 4 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
5.
AWS SDK概要 © 2013
Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
6.
AWS SDKの重要性 !
AWSはプログラマブルなインフラ • プログラムから扱うためにはSDKが必要 • ほぼすべてのサービスはマネジメントコンソールから利利⽤用でき るが、⾃自動化しようと思ったらプログラムから扱うのが必須 • ⾃自動化するとAWSは何倍も便便利利になる ! 代表的な⽤用途 • インフラ構築/運⽤用の⾃自動化 • EC2やRDSを上げたり下げたり、CloudFormationでスタックをデ プロイしたり • アプリケーション的なサービスの利利⽤用 • S3にデータをアップしたり、DynamoDBやSQSにデータ⼊入れたり 出したり © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
7.
AWS SDK !
AWSのサービスはHTTP/HTTPSでREST/SOAP形式の APIをサポート。 例例えば • EC2 : Start/Stop/Terminate • S3 : GetObject/PutObject • DynamoDB : Get/Put ! SDKはこれらのAPIを抽象化し、各⾔言語からの利利⽤用を⾮非 常に簡単にしてくれる Your code AWS SDK API 7 EC2 S3 その他サービス © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
8.
AWS SDK !
下記の⾔言語/環境で提供中 Java Python JavaScript in nodeJS PHP JavaScript in the Browser .NET iOS Ruby Android © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
9.
AWS SDK !
今回は下記についてお話します。 Java Python JavaScript in Node.js PHP JavaScript in the Browser .NET iOS Ruby Android © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
10.
AWS SDKの使い⽅方 !
必要な⾔言語のSDKをインストール • ⾔言語ごとにインストール⽅方法が異異なります。このあとの章で⾔言語ご とに解説します。 ! Credential(AWS APIの認証情報)を⽤用意する ! ファクトリーメソッドを利利⽤用してサービス(例例えばS3)のクラ イアントオブジェクトを⽣生成 • このときにCredentialを渡す ! クライアントオブジェクトのメソッドを使ってオペレーショ ン(例例えばPutObject) ! ⾔言語によってはより⾼高度度に抽象化されているSDKもあります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
11.
Credentialの取り扱い ! Credentialの取り扱いについてはいくつかのやり⽅方があ りますが、IAM
Roleもしくは環境変数を使うのがオス スメです。PHPを例例にそれぞれの実装⽅方法をご案内しま す。 ! コード内に直接埋め込むパターン(コード内に Credentialが⼊入り込んでしまうのでやっちゃダメなパ ターン) <?php $s3client = S3Client::factory(array( 'key' => 'your-‐‑‒aws-‐‑‒access-‐‑‒key-‐‑‒id', 'secretʻ‘ => 'your-‐‑‒aws-‐‑‒secret-‐‑‒access-‐‑‒key', )); © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
12.
Credentialの取り扱い ! configファイルでCredentialを設定するパターン • PHPとbotoではこの⽅方法が提供されている •
これもCredentialがファイル化されるので良良くないパターン $ vim aws-‐‑‒config.php <?php return array( 'includes' => array('_̲aws'), 'services' => array( 'default_̲settings' => array( 'params' => array( 'key' => 'your-‐‑‒access-‐‑‒key-‐‑‒id', 'secret' => 'your-‐‑‒secret-‐‑‒access-‐‑‒key',) ) ) ); $ vim sample.php <?php $aws = Aws::factory(ʻ‘aws-‐‑‒config.php'); $s3client = $aws-‐‑‒>get('s3'); © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
13.
Credentialの取り扱い ! 環境変数でCredentialを設定するパターン •
AWS_̲ACCESS_̲KEY_̲ID, AWS_̲SECRET_̲KEYという環境変数 を実⾏行行ユーザーで設定しておくことによってコードから Credentialを追い出せる $ export AWS_̲ACCESS_̲KEY_̲ID="your-‐‑‒aws-‐‑‒access-‐‑‒key-‐‑‒id" $ export AWS_̲SECRET_̲KEY="your-‐‑‒aws-‐‑‒secret-‐‑‒access-‐‑‒key” $vim sample.php <?php $s3client = S3Client::factory(); © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
14.
Credentialの取り扱い ! IAM
RoleでCredentialを設定するパターン • コードが動くのがEC2上であれば、IAM Roleを使うことによっ て、EC2⾃自体にAWS APIへのアクセス権限を付与できる。よっ てコードや環境変数にCredentialを持たせずに済む。 例例えばS3フルアクセスの権限を持った IAM Roleを作成して・・・ EC2にそのRoleを 割り当てると・・・ © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
15.
Credentialの取り扱い ! IAM
RoleでCredentialを設定するパターン • 前のページのようにS3アクセス権限を持ったRoleをEC2に割り 当てると、下記を書くだけで利利⽤用可能。 $vim sample.php <?php $s3client = S3Client::factory(); • これは、SDKが内部でSTS(Security Token Service)を利利⽤用し ており、AccessKey,SecretAccessKey,Tokenを⾃自動的に © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
16.
AWS SDK for
PHP © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
17.
AWS SDK for
PHP ! ! ! ! ! ! Amazon提供のAWS開発⽤用のPHP向けSDK 現在は、Version2 http://aws.amazon.com/jp/sdkforphp/ 環境:PHP5.3.3以降降 Guzzle HTTP Client framework上で構築されている 依存Extension • cURL © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
18.
操作可能サービス Direct Connect Elasticache IAM EC2 SimpleDB OpsWorks ELB S3 Elastic Transcoder Auto
Scaling Glacier SQS EMR CloudFront SNS Route53 Storage Gateway SES VPC Import/Export SWF DynamoDB Elastic Beanstalk CloudSearch RDS Cloud Formation Redshift Cloud Watch © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
19.
利利⽤用⽅方法 ! Composerによるインストール(推奨) •
http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/guide/latest/ installation.html#installing-‐‑‒via-‐‑‒composer ! Pharよるインストール • http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/guide/latest/ installation.html#installing-‐‑‒via-‐‑‒phar ! Zipファイルからインストール • http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/guide/latest/ installation.html#installing-‐‑‒via-‐‑‒zip ! PEARによるインストール • http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/guide/latest/ installation.html#installing-‐‑‒via-‐‑‒pear © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
20.
初期設定 ! インストール⽅方法により以下のとおり異異なります インストール方法 インクルード Composer require
'/path/to/vendor/autoload.php'; Phar require '/path/to/aws.phar'; Zip require '/path/to/aws-autoloader.php'; PEAR 'AWSSDKforPHP/aws.phar'; ! コンフィグレーションファイルの設定 • クレデンシャル情報などを設定可能 • factory()の引数として指定することも可能 • ʻ‘src/Aws/Common/Resources/aws-‐‑‒config.phpʼ’ を参考に追加 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
21.
サンプル:S3 -‐‑‒ putObject API仕様:
http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/latest/class-‐‑‒ Aws.S3.S3Client.html#_̲putObject <?php require '/path/to/vendor/autoload.php'; use AwsCommonAws; use AwsS3ExceptionS3Exception; try { $client = S3Client::factory; ① $bucket = ʼ’your_̲bucket'; $file = 'test.txt'; $result = $client-‐‑‒>putObject(array( 'Bucket' => $bucket, 'Key' => $file, 'Body' => fopen($file, 'r'), )); // 結果表⽰示 var_̲dump($result); } catch (S3Exception $e) { echo '*** Error ***' . "n"; echo $e-‐‑‒>getMessage(); } ① S3クライアント作成 ② putObject実⾏行行 ② Bucketを指定、Keyは、ファ イル名、Bodyにアップロードす るファイルストリームを指定 (*) 事前にBucketが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
22.
サンプル:S3 -‐‑‒ getObject API仕様:
http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/latest/class-‐‑‒ Aws.S3.S3Client.html#_̲getObject <?php require '/path/to/vendor/autoload.php'; use AwsCommonAws; use AwsS3ExceptionS3Exception; try { $client = S3Client::factory; ① $bucket = ʼ’your_̲bucket'; $file = 'test.txt'; $result = $client-‐‑‒>getObject(array( 'Bucket' => $bucket, 'Key' => $file, )); // 結果表⽰示 echo $result['Body']; ③ } catch (S3Exception $e) { echo '*** Error ***' . "n"; echo $e-‐‑‒>getMessage(); } ① S3クライアント作成 ② getObject実⾏行行 ② Bucketを指定、Keyは、ファイル 名 ③ 取得したコンテンツを表⽰示 (*) 事前にBucketが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
23.
サンプル:SQS -‐‑‒ sendMessage API仕様:
http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/latest/class-‐‑‒ Aws.Sqs.SqsClient.html#_̲sendMessage <?php require '/path/to/vendor/autoload.php'; use AwsCommonAws; use AwsSqsExceptionSqsException; try { $client = SqsClient::factory; ① $queueUrl = 'https://YourQueue'; $result = $client-‐‑‒>sendMessage(array( ② 'QueueUrl' => $queueUrl, 'MessageBody' => 'Send Message!', )); // 結果表⽰示 var_̲dump($result); } catch (SqsException $e) { echo '*** Error ***' . "n"; echo $e-‐‑‒>getMessage(); } ① SQSクライアント作成 ② sendMessage実⾏行行 QueueURLを指定、送りたい メッセージを指定 (*) 事前にQueueが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
24.
サンプル:SQS -‐‑‒ receiveMessage API仕様:
http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/latest/class-‐‑‒ Aws.Sqs.SqsClient.html#_̲receiveMessage <?php require '/path/to/vendor/autoload.php'; use AwsCommonAws; use AwsSqsExceptionSqsException; ① コンフィグを指定してインスタン ス作成 ② SQSクライアント作成 try { $client = SqsClient::factory; ① ③ receiveMessage実⾏行行 $queueUrl = 'https://YourQueue'; $result = $client-‐‑‒>receiveMessage(array( ② QueueURLを指定 'QueueUrl' => $queueUrl, )); // 結果表⽰示 var_̲dump($result); } catch (SqsException $e) { echo '*** Error ***' . "n"; echo $e-‐‑‒>getMessage(); } (*) 事前にQueueが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
25.
サンプル:DynamoDB -‐‑‒ putItem API仕様:
http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/latest/class-‐‑‒ Aws.DynamoDb.DynamoDbClient.html#_̲putItem <?php require '/path/to/vendor/autoload.php'; use AwsCommonAws; use AwsDynamoDbExceptionDynamoDbException; try { $client = DynamoDbClient::factory; ① $result = $client-‐‑‒>putItem(array( 'TableName' => ʼ’table_̲name', 'Item' => $client-‐‑‒>formatAttributes(array( ʼ’id' => 100, 'timestamp' => 130699342, 'message' => 'Good Morning.', )), )); // 結果表⽰示 var_̲dump($result); } catch (DynamoDbException $e) { echo '*** Error ***' . "n"; echo $e-‐‑‒>getMessage(); } ① DynamoDBクライアント作 成 ② ② putItem実⾏行行 -‐‑‒ TableName: テーブル名 -‐‑‒ Item: Putするアイテムを 指定 (例例) id : Hash Key timestamp : Range Key message : Attribute (*) 事前にTableが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
26.
サンプル:DynamoDB -‐‑‒ getItem API仕様:
http://docs.aws.amazon.com/aws-‐‑‒sdk-‐‑‒php/latest/class-‐‑‒Aws.DynamoDb.DynamoDbClient.html#_̲getItem <?php require '/path/to/vendor/autoload.php'; use AwsCommonAws; use AwsDynamoDbExceptionDynamoDbException; try { $client = DynamoDbClient::factory; ① $result = $client-‐‑‒>getItem(array( ② 'ConsistentRead' => true, 'TableName' => 'table_̲name', 'Key' => array( ʼ’id' => array('N' => '100'), 'timestamp' => array('N' => '130699342') ) )); // 結果表⽰示 var_̲dump($result); } catch (DynamoDbException $e) { echo '*** Error ***' . "n"; echo $e-‐‑‒>getMessage(); } ① DynamoDBクライアント作 成 ② getItem実⾏行行 -‐‑‒ TableName: テーブル名 -‐‑‒ Key:GetするアイテムのKey を指定 (例例) id : Hash Key timestamp : Range Key (*) 事前にTableが作成されてい る必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
27.
活⽤用法 ! PHPアプリのバックエンドストレージ呼び出し •
DynamoDB,SQS,S3を簡単に呼び出し可能 ! PHPベースのアプリケーションの拡張 • WordpressやEC-‐‑‒CubeなどのPHPベースのアプリケーションと AWSの連携 ! 独⾃自の管理理⽤用Webインターフェースの作成 • 定型作業を簡略略化したり、管理理を容易易にするための独⾃自Webイ ンターフェースの作成 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
28.
PHP版SDKの便便利利なクラス ! DynamoDBSessionHandler ! DynamoDBを使った、HTTPのセッション共有が可能 EC2 ELB EC2 EC2 DynamoDB 速い 消えない 管理不要 ©
2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
29.
DynamoDBSessionHandlerの利利⽤用 <?php require '/home/ec2-‐‑‒user/vendor/autoload.php'; use AwsCommonAws; use
AwsDynamoDbExceptionDynamoDbException; use AwsDynamoDbDynamoDbClient; use AwsDynamoDbSessionSessionHandler; $aws = Aws::factory(ʼ’aws-‐‑‒config.php'); $client = $aws-‐‑‒>get('dynamodb'); try { $sessionHandler = SessionHandler::factory(array( 'dynamodb_̲client' => $client, 'table_̲name' => 'sessions', )); $sessionHandler-‐‑‒>register(); } catch (DynamoDbException $e) { echo '*** Error ***' . "n"; echo $e-‐‑‒>getMessage(); } session_̲start(); //セッションにデータ登録 $_̲SESSION['username'] = 'jeremy'; $_̲SESSION['role'] = 'admin'; session_̲commit(); © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
30.
boto(Python) © 2013 Amazon.com,
Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
31.
botoとは ! Python⽤用のAWS
SDKのデファクトスタンダード ! 最新版は2.19.0 (2013年年12⽉月現在) ! Python 2.6.6, 2.7.3 on Mac OSX and Ubuntu Maverick で動作確認している。 ! Python 2.5での互換性もなるべく考慮しているが保証外 ! Python 3.x版はDeveloper Preview中 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
32.
操作可能サービス Direct Connect Elasticache IAM EC2 SimpleDB OpsWorks ELB S3 Elastic Transcoder Auto
Scaling Glacier SQS EMR CloudFront SNS Route53 Storage Gateway SES VPC Import/Export SWF DynamoDB Elastic Beanstalk CloudSearch RDS Cloud Formation Data Pipeline Redshift Cloud Watch CloudTrail FPS EBS © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
33.
botoに関するリソース ! ソースコードリポジトリ •
https://github.com/boto/boto ! PyPI • http://pypi.python.org/pypi/boto ! オンラインドキュメント • http://docs.pythonboto.org/ ! IRC • http://webchat.freenode.net/?channels=boto © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. Amazon.com, Inc.
34.
インストール $ pip
install boto © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. Amazon.com, Inc.
35.
初期設定 ! 設定ファイルの作成 !
/etc/boto.cfg -‐‑‒ グローバルな設定を記述 ! ~∼/.boto ユーザー毎の設定を記述 [Boto] debug = 0 num_̲retries = 10 [DynamoDB] region = ap-‐‑‒northeast-‐‑‒1 © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. Amazon.com, Inc.
36.
サンプル:S3 – set_̲contents_̲from_̲string >>>
from boto.s3.connection import S3Connection >>> conn = S3Connection() >>> bucket_̲name = ”yourBucket" >>> bucket = conn.get_̲bucket(bucket_̲name) >>> from boto.s3.key import Key >>> k = Key(bucket) >>> k.key = "test.txt" >>> k.set_̲contents_̲from_̲string("Hello World!") (*) 事前にBucketが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
37.
サンプル:S3 – get_̲contents_̲as_̲string >>>
from boto.s3.connection import S3Connection >>> conn = S3Connection() >>> bucket_̲name = "yourBucket" >>> bucket = conn.get_̲bucket(bucket_̲name) >>> from boto.s3.key import Key >>> k = Key(bucket) >>> k.key = "test.txt" >>> k.get_̲contents_̲as_̲string() (*) 事前にBucketが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
38.
サンプル:SQS – write >>>
import boto.sqs >>> conn = boto.sqs.connect_̲to_̲region("ap-‐‑‒northeast-‐‑‒1") >>> q = conn.get_̲queue('YourQueue') >>> from boto.sqs.message import Message >>> m = Message() >>> m.set_̲body('Hello World!!') >>> q.write(m) (*) 事前にQueueが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
39.
サンプル:SQS – get_̲messages >>>
import boto.sqs >>> conn = boto.sqs.connect_̲to_̲region("ap-‐‑‒northeast-‐‑‒1") >>> q = conn.get_̲queue('YourQueue') >>> rs = q.get_̲messages() >>> m = rs[0] >>> m.get_̲body() 'Hello World!!' (*) 事前にQueueが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
40.
サンプル:DynamoDB – putItem >>>
from boto.dynamodb2.items import Item >>> from boto.dynamodb2.table import Table >>> table = Table('table_̲name') >>> item = Item(table , data={ ... ʼ’id': 100, ... 'timestamp': 130699342, ... 'message' : 'Good Morning.', ... }) >>> item.save() True (*) 事前にTableが作成されてい る必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
41.
サンプル:DynamoDB – getItem >>>
from boto.dynamodb2.table import Table >>> table= Table('table_̲name') >>> item = table.get_̲item(id=100,timestamp=130699342) >>> print item['message'] Good Morning. (*) 事前にTableが作成されてい る必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
42.
その他Tips ! AWSコマンドラインインタフェース(CLI)もbotoを⼀一部 利利⽤用している ©
2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
43.
AWS SDK for
Ruby © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
44.
AWS SDK for
Rubyとは ! Amazon提供のAWS開発⽤用のRuby向けSDK ! 現在のバージョン • Version 1 (stable) • Version 2 (developer preview) ! http://aws.amazon.com/sdkforruby/ ! 環境:Ruby 1.8.7 以降降 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
45.
操作可能サービス Direct Connect Elasticache IAM EC2 SimpleDB OpsWorks ELB S3 Elastic Transcoder Auto
Scaling Glacier SQS EMR CloudFront SNS Route53 Storage Gateway SES VPC Import/Export SWF DynamoDB Elastic Beanstalk CloudSearch RDS Cloud Formation Data Pipeline Redshift Cloud Watch © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
46.
利利⽤用⽅方法 ! Ruby環境のセットアップ •
Rbenvを利利⽤用する • https://github.com/sstephenson/rbenv • RVMを利利⽤用する • https://rvm.io/ ! aws-‐‑‒sdk gemをインストール $ gem install aws-‐‑‒sdk © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
47.
設定の初期化 ! デフォルトのリージョンをセッティング require
'awsʼ’ AWS.config({ :region => ʻ‘YOUR_̲DEFAULT_̲REGIONʼ’ }) © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
48.
サンプル:S3 -‐‑‒ write API仕様:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html#write-‐‑‒ instance_̲method #!/usr/bin/env ruby require 'aws' AWS.config({ :access_̲key_̲id => ENV['AWS_̲ACCESS_̲KEY_̲ID'], :secret_̲access_̲key => ENV['AWS_̲SECRET_̲ACCESS_̲KEY'], :region => ENV['AWS_̲REGION'] }) ① コンフィグを指定 ① ② S3クライアント作成し、 bucketやkeyを指定 ③ putするfile名を指定し、s3に put ② s3 = AWS::S3.new bucket = s3.buckets['your-‐‑‒bucket'] obj = bucket.objects['key'] obj.write(Pathname.new('/path/to/file.txt')) ③ (*) 事前にBucketが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
49.
サンプル:S3 -‐‑‒ read API仕様:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html#read-‐‑‒ instance_̲method #!/usr/bin/env ruby require 'aws' ① コンフィグを指定 AWS.config({ :access_̲key_̲id => ENV['AWS_̲ACCESS_̲KEY_̲ID'], :secret_̲access_̲key => ENV['AWS_̲SECRET_̲ACCESS_̲KEY'], :region => ENV['AWS_̲REGION'] }) ① s3 = AWS::S3.new bucket = s3.buckets['your-‐‑‒bucket'] obj = bucket.objects['key'] ② obj.read do |chunk| puts chunk #=> data of s3://your-‐‑‒bucket/key end ③ ② S3クライアント作成し、 bucketやkeyを指定 ③ s3にあるobjectのデータを取 得 (*) 事前にBucketが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
50.
サンプル:SQS – send_̲message API仕様:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SQS/ Client.html#send_̲message-‐‑‒instance_̲method #!/usr/bin/env ruby require 'aws' require 'pp' ① コンフィグを指定 AWS.config({ :access_̲key_̲id => ENV['AWS_̲ACCESS_̲KEY_̲ID'], :secret_̲access_̲key => ENV['AWS_̲SECRET_̲ACCESS_̲KEY'], :region => ENV['AWS_̲REGION'] }) ① sqs = AWS::SQS.new ② queue_̲url = 'https://your_̲queue' result = sqs.client.send_̲message({ :queue_̲url => queue_̲url, :message_̲body => 'Send Message!' }) pp result ② SQSクライアント作成 ③ ③ send_̲message実⾏行行 queue_̲urlを指定、送りたい メッセージを指定 (*) 事前にQueueが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
51.
サンプル:SQS – receive_̲message API仕様:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SQS/ Client.html#receive_̲message-‐‑‒instance_̲method #!/usr/bin/env ruby require 'aws' require 'pp' ① コンフィグを指定 AWS.config({ :access_̲key_̲id => ENV['AWS_̲ACCESS_̲KEY_̲ID'], :secret_̲access_̲key => ENV['AWS_̲SECRET_̲ACCESS_̲KEY'], :region => ENV['AWS_̲REGION'] }) ① sqs = AWS::SQS.new ② queue_̲url = 'https://your_̲queue' result = sqs.client.receive_̲message({ :queue_̲url => queue_̲url }) pp result ② SQSクライアント作成 ③ ③ receive_̲message実⾏行行 queue_̲urlを指定 (*) 事前にQueueが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
52.
サンプル:DynamoDB – put_̲item API仕様:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/DynamoDB/Client.html#put_̲item-‐‑‒ instance_̲method #!/usr/bin/env ruby require 'aws' require 'pp' ① コンフィグを指定 AWS.config({ ① :access_̲key_̲id => ENV['AWS_̲ACCESS_̲KEY_̲ID'], :secret_̲access_̲key => ENV['AWS_̲SECRET_̲ACCESS_̲KEY'], :region => ENV['AWS_̲REGION'] }) client = AWS::DynamoDB::Client.new result = client.put_̲item({ :table_̲name => 'table_̲nameʼ’, :item => { 'id' => {:n => '100'}, 'timestamp' => {:n => '130699342'}, 'message' => {:s => 'Good Morning'} } }) pp result #=> {"ConsumedCapacityUnits"=>1.0} ② ③ ② DynamoDBクライアント作成 ③ put_̲item実⾏行行 -‐‑‒ :table_̲name: テーブル名 -‐‑‒ :item: Putするアイテムを指 定 (例例) id : Hash Key timestamp : Range Key message : Attribute (*) 事前にTableが作成されてい る必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
53.
サンプル:DynamoDB – get_̲item API仕様:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/DynamoDB/Client.html#get_̲item-‐‑‒ instance_̲method #!/usr/bin/env ruby require 'aws' require 'pp' ① コンフィグを指定 AWS.config({ ① :access_̲key_̲id => ENV['AWS_̲ACCESS_̲KEY_̲ID'], :secret_̲access_̲key => ENV['AWS_̲SECRET_̲ACCESS_̲KEY'], :region => ENV['AWS_̲REGION'] }) client = AWS::DynamoDB::Client.new result = client.get_̲item({ :consistent_̲read => true, :table_̲name => 'table_̲name', :key => { :hash_̲key_̲element => {:n => '100'}, :range_̲key_̲element => {:n => '130699342'} } }) pp result #=> {"Item"=>{"id"=>{"N"=>"100"}, "message"=>{"S"=>"Good Morning"}, "timestamp"=>{"N"=>"130699342"}}, "ConsumedCapacityUnits"=>1.0} ② ③ ② DynamoDBクライアント 作成 ③ get_̲item実⾏行行 -‐‑‒ :table_̲name テーブル名 -‐‑‒ :consistent_̲read ⼀一貫性 -‐‑‒ :key GutするKeyを指定 (例例) id : Hash Key timestamp : Range Key (*) 事前にTableが作成され ている必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
54.
その他Tips ! 新しいRuby
SDK (version 2) • • • • Developer Preview バリデーション、ドキュメント、拡張性など改善 プラグイン⽅方式をとっている Ruby 1.9以降降が必須 ! 以下のように利利⽤用可能 $ gem install aws-‐‑‒sdk-‐‑‒core AWS::DynamoDB.new(api_̲version: ʻ‘2012-‐‑‒08-‐‑‒10ʼ’) Re:Inventで発表された新Ruby SDKのスライドはおすすめ © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
55.
その他Tips ! RailsのセッションをDynamoDBに保存 •
スケーラブルかつ耐障害に優れたセッションストア • Rails 3.x か 4.x から利利⽤用可能 • Rackベースのアプリも利利⽤用可能 ! 以下の⼿手順で利利⽤用可能 gem ʻ‘aws-‐‑‒sessionstore-‐‑‒dynamodbʼ’ $ bundle install 参考:https://github.com/aws/aws-‐‑‒sessionstore-‐‑‒dynamodb-‐‑‒ruby © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
56.
AWS SDK for
JavaScript in Node.js © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
57.
AWS SDK for
JavaScript in Node.jsとは ! Amazon提供のAWS開発⽤用のnode.js環境で動くJavaScript 向けSDK • http://aws.amazon.com/sdkfornodejs/ © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
58.
操作可能サービス Direct Connect Elasticache IAM EC2 SimpleDB OpsWorks ELB S3 Elastic Transcoder Auto
Scaling Glacier SQS EMR CloudFront SNS Route53 Storage Gateway SES VPC Import/Export SWF DynamoDB Elastic Beanstalk CloudSearch RDS Cloud Formation Data Pipeline Redshift Cloud Watch © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
59.
利利⽤用⽅方法 ! Node.js環境のセットアップ • OSのパッケージマネージャーでnpmをインストール •
Mac の場合: $ brew install npm ! aws-‐‑‒sdk packageをインストール $ npm install aws-‐‑‒sdk © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
60.
サンプル:S3 -‐‑‒ putObject var
AWS = require('aws-‐‑‒sdk'); var fs = require('fs'); var s3 = new AWS.S3(); ① var bodyStream = fs.createReadStream( '/path/ ② to/file.txt' ); var params = { Bucket: 'your-‐‑‒bucket', Key: 'key', Body: bodyStream }; s3.putObject(params, function(err, data) { if (err) console.log(err); else console.log("Successfully uploaded."); }); ① S3クライアント作成 ② put時の引数 • Bucket: s3 bucket • Key: s3 key • Body: 実際のデータ ③ ③ S3へPUT (*) 事前にBucketが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
61.
サンプル:S3 -‐‑‒ getObject var
AWS = require('aws-‐‑‒sdk'); var fs = require('fs'); var s3 = new AWS.S3(); ① var params = { Bucket: ʼ’your-‐‑‒bucket', Key: ʼ’key' }; ② s3.getObject(params, function(err, data) { if (err) console.log(err); else console.log(data.Body.toString()); }); ③ ① S3クライアント作成 ② gut時の引数 • Bucket: s3 bucket • Key: s3 key ③ S3からデータ取得 (*) 事前にBucketが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
62.
サンプル:SQS -‐‑‒ sendMessage var
AWS = require('aws-‐‑‒sdk'); var fs = require('fs'); var s3 = new AWS.SQS(); ① var params = { ② QueueUrl: 'https://your_̲queue', MessageBody: 'Send Message!' } sqs.sendMessage(params, function(err, data) { if (err) console.log(err); else console.log("Successfully sent."); }) ① SQSクライアント作成 ② queue_̲urlを指定、送りたい メッセージを指定 ③ sendMessage実⾏行行 (*) 事前にQueueが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
63.
サンプル:SQS -‐‑‒ receiveMessage var
AWS = require('aws-‐‑‒sdk'); var fs = require('fs'); var s3 = new AWS.SQS(); ① ① SQSクライアント作成 var params = { ② ② queue_̲urlを指定 QueueUrl: 'https://your_̲queueʼ’ } sqs.receiveMessage(params, function(err, data) ③ receiveMessage実⾏行行 { ③ if (err) console.log(err); else console.log(data); }) (*) 事前にQueueが作成されて いる必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
64.
サンプル:DynamoDB – putItem var
AWS = require('aws-‐‑‒sdk'); var fs = require('fs'); var ddb = new AWS.DynamoDB(); ① var params = { TableName: 'my_̲table', Item: { 'id': {N: ʻ‘100'}, 'timestamp': {N: '130699342'}, 'message': {S: 'Good Morning'} } }; ② ddb.putItem(params, function(err, data) { if (err) console.log(err); else console.log(data); }); ③ ① DynamoDBクライアント 作成 ② パラメータ指定 -‐‑‒ :TableName: テーブル名 -‐‑‒ :Item: Putするアイテムを指 定 (例例) id : Hash Key timestamp : Range Key message : Attribute ③ Put実⾏行行 (*) 事前にTableが作成され ている必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
65.
サンプル:DynamoDB – getItem var
AWS = require('aws-‐‑‒sdk'); var fs = require('fs'); var ddb = new AWS.DynamoDB(); ① var params = { TableName: 'my_̲table', Key: { 'id': {N: ʻ‘100'}, 'timestamp': {N: '130699342'} } }; ② ddb.getItem(params, function(err, data) { if (err) console.log(err); else console.log(data); }); ③ ① DynamoDBクライアント作 成 ② パラメータ指定 -‐‑‒ :TableName: テーブル名 -‐‑‒ :Item: Putするアイテムを 指定 (例例) id : Hash Key timestamp : Range Key message : Attribute ③ Get実⾏行行 (*) 事前にTableが作成されてい る必要があります。 © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
66.
まとめ © 2013 Amazon.com,
Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
67.
今回のまとめ ! AWSはプログラマブルなインフラ •
ほぼすべてのサービスはマネジメントコンソールから利利⽤用でき るが、⾃自動化しようと思ったらプログラムから扱うのが必須 • ⾃自動化するとAWSは何倍も便便利利になる ! AWSのサービスはHTTP/HTTPSでREST/SOAP形式の APIをサポート。 例例えば • EC2 : Start/Stop/Terminate • S3 : GetObject/PutObject • DynamoDB : Get/Put ! SDKはこれらのAPIを抽象化し、各⾔言語からの利利⽤用を⾮非 常に簡単にしてくれる © 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
68.
Q&A 68 © 2012 Amazon.com,
Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
Download