60
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 1 アマゾンウェブサービスジャパン株式会社 ソリューションアーキテクト 福井 厚 2017.12.12 【AWS Black Belt Online Seminar】 AWSサービスを利用した アプリケーション開発を始めよう

AWS Black Belt Online Seminar · • AWS Command Line Interface(AWS CLI)、Tools for Windows PowerShell、AWS SDK、または直接HTTP呼び出しな どAWSをプログラムで呼び出すには、ユーザー独自のアクセス

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

1

アマゾンウェブサービスジャパン株式会社

ソリューションアーキテクト 福井 厚

2017.12.12

【AWS Black Belt Online Seminar】AWSサービスを利用したアプリケーション開発を始めよう

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

2

自己紹介

名前 福井 厚(ふくい あつし)fatsushi@

所属 アマゾン ウェブ サービス ジャパン株式会社

技術統括本部レディネス ソリューション部

DevOps スペシャリスト ソリューション アーキテクト

前職 エンタープライズ アプリケーション開発コンサルタント

好きなAWSサービス AWS Code シリーズ、AWS Cloud9、AWS Fargate、AWS Lambda

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

3

内容についての注意点

本資料では2017年12月12日時点のサービス内容および価格についてご説明しています。最新の情報はAWS公式ウェブサイト(http://aws.amazon.com)にてご確認ください。

• 資料作成には十分注意しておりますが、資料内の価格とAWS公式ウェブサイト記載の価格に相違があった場合、AWS公式ウェブサイトの価格を優先とさせていただきます。

• 価格は税抜表記となっています。日本居住者のお客様が東京リージョンを使用する場合、別途消費税をご請求させていただきます。

AWS does not offer binding price quotes. AWS pricing is publicly available and is subject to change in accordance with the AWS Customer Agreement available at http://aws.amazon.com/agreement/. Any pricing information included in this document is provided only as an estimate of usage charges for AWS services based on certain information that you have provided. Monthly charges will be based on your actual use of AWS services, and may vary from the estimates provided.

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4

Agenda

• AWS上でのアプリケーション開発

• 開発を始める前の準備

• やってみよう

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

5

AWSのサービス操作といえば

マネジメントコンソール

AWS CLI

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

6

AWSの各サービスはAPIを提供

• 各サービスの操作にAPIが定義されている

• マネジメントコンソールまたはAWS CLIから、これらのAPIをコール

• プログラミングからAPIをコールすることも可能

• 各種開発言語用にSDKを提供

• SIG V4ヘッダの組み立てを行なってくれるので楽

• 高レベルなプログラミング インターフェイスを提供

• HTTP REST APIを直接リクエストすることも可能

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

7

アプリケーションからAWSのサービスを利用

Amazon

S3

Lambda

functionAmazon

DynamoDBclient

user

オブジェクトをS3にアップロード

S3イベントでLambdaを実行

DynamoDBにメタデータを保存

S3へオブジェクトをPutするコードを実装

DynamoDBへItemをPut

するコードを実装

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

8

AWS SDK

Ruby AWS CLI

Python (boto)Mobile SDK Node.js

AWS Toolkit for Visual

Studio

.NET

AWS Toolkit for Eclipse

PHP

AWS Tools for Windows PowerShell

C++

JavaScriptJava

Go

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

9

AWS Mobile SDK• 高品質なモバイルアプリケーションを

素早く簡単に構築可能に

• AWS Lambda、Amazon S3、Amazon DynamoDB、Amazon Mobile Analytics、Amazon Machine Learning、Elastic Load balancing、Auto ScalingなどのAWSサービスへの容易なアクセス

• iOS、Android/Fire OS、Xamarin、Unityのライブラリ、コードサンプル、ドキュメントを提供

• ドキュメントhttps://aws.amazon.com/documentation/mobile-sdk/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

10

AWS Mobile SDK

• オープンソースのソフトウェア開発キット

• AWS Mobile SDK for iOS• 開発環境:Xcode 7 以降、iOS 8 以降

• AWS Mobile SDK for Android• 開発環境:Android 2.3.3(API Level 10) 以降、Android Studio または Android

Development Tools for Eclipse

• AWS Mobile SDK for .NET and Xamarin• 対象アプリ:Xamarin iOS、Xamarin Android、Window Phone Silverlight、Windows RT

8.1、Windows Phone 8.1• 開発環境

• Windows環境:Visual Studio 2013 Update 2、Visual Studio 2015 及び 2017• Mac環境:MacOS Sierra 10.12 以降、Xcode 8.3

• AWS Mobile SDK for Unity• 開発環境

• Unity version 4.x または 5.x

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

11

AWS SDK for Python(Boto3)

• Boto3は2つの異なるレベルのAPIを提供• Client API(低レベル):HTTP APIと1対1でマッピング• Resource API (高レベル):リソース属性とオブジェクトのコレクショ

ンを提供

• Python 2 及び Python 3 をサポート• Python version 2.6.5+、2.7、3.3+

• AWSリソースが事前定義された状態に遷移するまでポーリングして待機するWaitersを提供

• ドキュメントhttps://boto3.readthedocs.io/en/latest/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

12

AWS SDK for Java

• AWS SDK for Java 2.0開発者プレビュー• Amazon S3、Amazon EC2、DynamoDBなどへの容易なアク

セスを提供

• 2.0.0-preview-6 (2017/11/6)

• メジャーバージョンアップとして1.xをリライト

• Java 8をベースに要求の多かった機能を追加• ノンブロッキングI/O、ブラグイン可能なHTTレイヤー、Clientビ

ルダー、Immutable POJOなど

• https://github.com/aws/aws-sdk-java-v2/

• プレビューなので本番環境への適用は推奨しません

• 1.xは今後もサポート

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

13

AWS SDK for .NET

• サーバーレス アプリケーション開発を含む.NET Core サポート

• Amazon S3 TransferUtility:マルチスレッド化されたAmazon S3マルチパートアップロードを利用することでスループット、パフォーマンス、及び信頼性を向上

• Amazon S3 クライアントサイド暗号化

• Amazon DynamoDBオブジェクト永続化フレームワークを提供

• Amazon Glacier ArchiveTransferManager:高レベルAPIによって、大きなファイルを自動的にパーツ分割

• Portal Class LibraryとXamarin Projectのサポート:.NET 3.5、.NET 4.5 Frameworkに加え、Portable Class Libraryも用意

• Amazon DynamoDB Session State Provider:ASP.NETのセッション状態をDynamoDBに簡単に格納可能

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

14

AWS SDK for Ruby

• Version 3

• gem install aws-sdk

• サービス特化なgem(aws-sdk-s3など)により、各サービスのセマンティックなバージョニングを使用

• aws-sdk-rails:AWS SDK for RubyのRuby on Railsとの統合を提供https://github.com/aws/aws-sdk-rails

• aws-record:AWS SDK for Ruby上に構築されたAmazon DynamoDBの抽象データマッピングを提供https://github.com/aws/aws-sdk-ruby-record

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

15

その他のSDK

• PHP• PHP 5.5.0以上• OpenSSL PHP extension(オプション)• cURL 7.16.2(推奨)• Xdebug(パフォーマンスに問題がある場合は、アンインストールを推奨)• Composer classmap autoloaderの利用

• C++• Amazon S3のクライアントサイド データ暗号化• Amazon S3 Transfer Manager• 幅広いプラットフォームに対応• CMakeのサポート• カスタマイズ可能なメモリ管理

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

16

その他のSDK

• Go• go get –u github.com/aws/aws-sdk-go• Amazon S3 Transfer Manager:大きなファイルを複数のパートに分

割してS3転送• Response Paginator:ページ分割された大量のAPI結果を容易に反復

処理可能• 拡張性:ハンドラーにより、すべてのAPIライフライクルをカスタマイ

ズ可能、モックテスト、エラーシミュレーションを実現

• Node.js• Npm install aws-sdk• Var AWS = require(‘aws-sdk’);

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

17

AWS Amplify

• クラウド対応アプリケーションを構築するフロントエンドとモバイル開発者用のJavaScriptライブラリ

• 宣言的インターフェイスでAWS以外のクラウドサービスもブラグ可能なオープンな設計

• Aws-amplifyライブラリに追加で、Reactアプリケーション用、React Nativeアプリケーション用ライブラリを提供

• 認証、分析、APIインタラクション、ストレージ、キャッシュ、i18n及びロギングのカテゴリをサポート

• https://github.com/aws/aws-amplify

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

18

AWS Mobile CLI

• JavaScriptフロントエンド開発者のためにアプリ内でAWSサービスと設定を有効化するためのコマンドラインインターフェイスを提供

• ターミナルから最小の設定で、AWS Mobile Hubが提供するすべての機能を利用可能

• AWS Mobile CLIは他の業界標準のコマンドラインインターフェイスに準拠するように設計

• $ awsmobile のパラメータでMobile Hubの設定取得、更新、S3とCloudFrontへのパブリッシュなどを実行http://docs.aws.amazon.com/aws-mobile/latest/developerguide/web-getting-started.html

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

19

Agenda

• AWS上でのアプリケーション開発

• 開発を始める前の準備

• やってみよう

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

20

開発を始める前の準備

• AWSへのサインアップ

• ユーザーとグループの作成

• AWS CLIのインストールとプロファイルの設定

• AWS SDKのインストール

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

21

開発を始める前の準備

• AWSへのサインアップ

• AWSアカウント作成の流れhttps://aws.amazon.com/jp/register-flow/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

22

開発を始める前の準備

• ユーザーとグループの作成• IAMユーザーの作成

• IAMグループの作成

• グループへのポリシーの適用

• ユーザーのグループへの追加

• アクセスキーIDとシークレットアクセスキーの生成• AWS Command Line Interface(AWS CLI)、Tools for

Windows PowerShell、AWS SDK、または直接HTTP呼び出しなどAWSをプログラムで呼び出すには、ユーザー独自のアクセスキーが必要

• IAMはアクセスキーIDとシークレットアクセスキーを返す

• これらを安全な場所に保存

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

23

IAMユーザーとグループ作成

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

24

IAMユーザーとグループ作成

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

25

IAMユーザーとグループ作成

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

26

IAMユーザーとグループ作成

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

27

IAMユーザーとグループ作成

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

28

AWS CLIのインストールとプロファイルの作成

• AWS CLIのインストール要件

• Python 2 バージョン 2.6.5+またはPython 3 バージョン 3.3+

• Windows、Linux、MacOS またはUnix

aws configure でクレデンシャル情報、リージョンを保存

$ pip install awcscli --upgrade –user

$ aws configure

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

29

AWS SDKのインストール

• お好みの開発環境を利用可能

• 個々のAWS SDKのインストールについては以下のサイトから各ドキュメントを参照くださいhttps://aws.amazon.com/jp/tools/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

30

AWS Toolkit

• IDEと統合して、より便利な開発を支援

• AWS Toolkit for Visual Studiohttps://aws.amazon.com/jp/visualstudio/

• AWS Toolkit for Eclipse https://aws.amazon.com/jp/eclipse/?nc1=h_ls

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

31

開発環境(Java)

• AWS Toolkit for Eclipse のインストールhttp://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/setup-install.html

[Help] – [Install New Software]を選択し下記のURLを指定

https://aws.amazon.com/eclips

e

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

32

AWS Toolkit for Eclipse

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

33

開発環境(.NET)

• AWS Toolkit for Visual Studioのインストールhttps://aws.amazon.com/jp/visualstudio/

Visual Studioのバージョンによってダウンロードするイン

ストーラーを選択

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

34

AWS Toolkit for Visual Studio

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

35

でも、なんか準備が大変そう。。。

• そんなあなたにオススメなのが、

AWS Cloud9!

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

36

クラウドベースの統合開発環境AWS Cloud9を発表

• AWSクラウド上で開発・テスト・デバッグを完結できる統合開発環境のサービスを発表。環境構築に時間を掛けず、即座に開発を始められる

• 初の”クラウドネイティブ”なIDE。Lambdaと統合され、ファンクションのテストをシームレスに実行できる。CodeStarとの統合も

• 自分の開発環境にアクセスできるユーザをIAMユーザの単位で設定し、共同作業が可能に

• オレゴン、オハイオ、バージニア、アイルランド、シンガポールのリージョンで利用可能に

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

37

AWS Cloud9 は

• JavaScript、Python、Goなど人気のある開発言語とツールを同梱

• AWS CLIもインストール済み

• Amazon EC2 インスタンスまたはSSH経由で独自のLinuxサーバー環境に開発環境を構築可能

• AWS Cloud9 ダッシュボードを利用して、多数のAWS Cloud9 環境を切り替え可能

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

38

AWS Cloud9環境のセットアップ

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

39

リージョンの選択

”Select a Region”をクリック

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

40

リージョンの選択環境を作成したいリージョンを選択現在は、・オレゴン、・オハイオ・北バージニア・アイルランド・シンガポールで、利用可能

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

41

環境の作成

”Create Environment”をクリック

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

42

名前と説明の入力

環境名と説明を入力したら“Next Step”をクリック

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

43

設定画面

“Next Step”をクリック

“Create a new instance for envrionment(EC2)” か“Connect and run in remote

Server (SSH)” を選択

インスタンスタイプを選択し、コストセービング オプションを選択

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

44

環境名と設定を確認し、作成

設定を確認して、“Create

environment”をクリック

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

45

数分で、AWS Cloud9環境が!

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

46

Agenda

• AWS上でのアプリケーション開発

• 開発を始める前の準備

• 開発環境

• やってみよう

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

47

Demo!

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

48

指定した名前で始まるS3のバケット名の取得(例)

import boto3

def listBuckets(bucketName):

s3client = boto3.client('s3')

resource = s3client.list_buckets()

for bucket in resource['Buckets']:

if bucket['Name'].startswith(bucketName):

print("Bucket: %s" % bucket['Name'])

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

49

S3のバケットの作成(例)

import boto3

def createBucket(bucketName) :s3client = boto3.client('s3')

s3client.create_bucket(Bucket=bucketName)

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

50

S3のバケットの削除(例)

import boto3

def deleteBucket(bucketName) :s3client = boto3.client('s3')

s3client.delete_bucket(Bucket=bucketName)

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

51

SQSのキューの作成(例)

import boto3

def createQueue(name):

sqs = boto3.resource('sqs')

queue = sqs.create_queue(

QueueName=name, Attributes={'DelaySeconds':'5'})

return queue.url

url = createQueue("myqueue")

print("url : %s" % url)

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

52

SQSのキューの取得(例)

import boto3

def getQueue(name):

sqs = boto3.resource("sqs")

queue = sqs.get_queue_by_name(QueueName=name)

return queue

queue = getQueue("myqueue")

print("queue url: %s" % queue.url)

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

53

SQSのキューへメッセージを送信(例)

import boto3

def sendMessage(name, message):

sqs = boto3.resource("sqs")

queue = getQueue(name)

response = queue.send_message(MessageBody=message)

return response

response = sendMessage("myqueue", "Hello, World!")

print("message id: %s" % response.get("MessageId"))

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

54

まとめ

• AWS SDKを利用することでAWSの各サービスをアプリケーションのサービスブロックとして活用することができる

• 様々な開発言語を利用可能、用途に応じた使い分けを

• AWS Cloud9は最初から様々な開発言語やツールが同梱されており、始めるのが超簡単でオススメ

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

55

オンラインセミナー資料の配置場所

AWS クラウドサービス活用資料集• http://aws.amazon.com/jp/aws-jp-introduction/

AWS Solutions Architect ブログ• 最新の情報、セミナー中のQ&A等が掲載されています

• http://aws.typepad.com/sajp/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

56

公式Twitter/FacebookAWSの最新情報をお届けします

@awscloud_jp

検索

最新技術情報、イベント情報、お役立ち情報、お得なキャンペーン情報などを日々更新しています!

もしくはhttp://on.fb.me/1vR8yWm

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

57

AWSの導入、お問い合わせのご相談

AWSクラウド導入に関するご質問、お見積り、資料請求をご希望のお客様は以下のリンクよりお気軽にご相談くださいhttps://aws.amazon.com/jp/contact-us/aws-sales/

※「AWS 問い合わせ」で検索してください

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

58

AWS Well Architected 個別技術相談会のお知らせ

Well Architectedフレームワークに基づく数十個の質問項目を元に、お客様がAWS上で構築するシステムに潜むリスクやその回避方法をお伝えする個別相談会https://pages.awscloud.com/well-architected-consulting-2017Q4-jp.html

参加無料

毎週火曜・木曜開催

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

59

ご参加ありがとうございました

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

60