Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

80
Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless Keisuke Nishitani (@Keisuke69) Amazon Web Services Japan K.K. Nov 25, 2016

Transcript of Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Page 1: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Keisuke Nishitani (@Keisuke69)Amazon Web Services Japan K.K.

Nov 25, 2016

Page 2: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

ProfileKeisuke NishitaniSpecialist Solutions Architect, Amazon Web Service Japan K.K

@Keisuke69 Keisuke69

✤ Specialist SA- Serverless- Mobile- DevOps- Application Service

✤ ソーシャルで⾚ドクロの⼈です✤ RESTおじさん✤ 餃⼦の王将エヴァンジェリスト(⾃称)✤ ⾳楽が好きです、フジロッカーです、今年も⾏きました✤ ブログ: http://keisuke69.hatenablog.jp/

Keisuke69 Keisuke69Keisuke69x

Page 3: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless
Page 4: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Amazonの代表的なサービス

Page 5: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Amazonの代表的なサービス

amazon.co.jpおなじみの通販サイト

Page 6: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless
Page 7: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Amazonの代表的なサービス

amazon services出品/出店サービス

Page 8: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless
Page 9: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Amazonの代表的なサービス

amazon web servicesITインフラサービス

Page 10: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

はサーバやストレージといったITリソースを電気・ガス・⽔道と同じように

必要なときに、必要なだけ使えるようにしたサービスです

Page 11: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

190カ国に及ぶ100万以上のお客様

Page 12: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

⽇本でAWSクラウドを利⽤するお客様:20,000以上

Page 13: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Startupも!

Page 14: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWSクラウドの現在✤ 世界に先駆けて2006年よりクラウドサービスを提供

✤ 世界に14箇所のリージョン(データセンタ群)

✤ 2015年で合計722回のイノベーション新機能・機能改善を実施

✤ 累計57回の値下げをして利益をお客様へ還元

Page 15: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Gartner Magic Quadrant for Cloud Infrastructure as a Service, Worldwide *でリーダーポジションに

GartnerはAWS をリーダーエリアの中でも、ビジョンの完全性と実⾏能⼒が最も優れていると評価

*Gartner, Magic Quadrant for Cloud Infrastructure as a Service, Worldwide, Leong, Lydia, Petri, Gregor, Gill, Bob, Dorosh, Mike, August 32016This graphic was published by Gartner, Inc. as part of a larger research document and should be evaluated in the context of the entire document. The Gartner document is available upon request from AWS : http://www.gartner.com/doc/reprints?id=1-2G2O5FC&ct=150519&st=sbGartner does not endorse any vendor, product or service depicted in its research publications, and does not advise technology users to select only those vendors with the highest ratings or other designation. Gartner research publications consist of the opinions of Gartner's research organization and should not be construed as statements of fact. Gartner disclaims all warranties, expressed or implied, with respect to this research, including any warranties of merchantability or fitness for a particular purpose.

Page 16: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Networking AnalyticsCompute

Storage & Content Delivery

Developer Tools Management Tools Security & Identity

Application Services

Mobile Services Database Enterprise Applications

S3 CloudFront EFS Glacier StorageGateway API Gateway AppStream CloudSearch Elastic Transcoder SES SQS SWF

Mobile AnalyticsCognito Device Farm SNS RDS DynamoDB ElastiCache RedShift WorkSpaces WorkDocs WorkMail

Lambda EC2 Container ServiiceEC2 VPC Direct Connect Route 53 EMR Data Pipeline Kinesis MachineLearning

Elastic Load Balancing QuickSight Elasticsearch Service

CodeCommit CloudWatch Cloud Formation

CloudTrail Config OpsWorks Service Catalog

Identity & Access Managem

ent

Directory Service

TrustedAdvisor

WAF

Snowball

DMS

IOT

IoT

Game Development

Mobile Hub

Elastic Beanstalk

ACM Inspector

GameLift

CodePipelineCodeDeploy

70以上のAWSサービス群を提供

Page 17: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWSの各サービスはアーキテクチャにおけるブロックの役割

Page 18: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

本⽇のお題

Page 19: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Javaとクラウド

Page 20: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Javaとクラウド…?

Page 21: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

⼤きく2つ

✤ Javaでクラウドをコントロール

✤ Javaアプリをクラウドで実⾏

Page 22: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Javaでクラウドをコントロール

Page 23: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Networking AnalyticsCompute

Storage & Content Delivery

Developer Tools Management Tools Security & Identity

Application Services

Mobile Services Database Enterprise Applications

S3 CloudFront EFS Glacier StorageGateway API Gateway AppStream CloudSearch Elastic Transcoder SES SQS SWF

Mobile AnalyticsCognito Device Farm SNS RDS DynamoDB ElastiCache RedShift WorkSpaces WorkDocs WorkMail

Lambda EC2 Container ServiiceEC2 VPC Direct Connect Route 53 EMR Data Pipeline Kinesis MachineLearning

Elastic Load Balancing QuickSight Elasticsearch Service

CodeCommit CloudWatch Cloud Formation

CloudTrail Config OpsWorks Service Catalog

Identity & Access Managem

ent

Directory Service

TrustedAdvisor

WAF

Snowball

DMS

IOT

IoT

Game Development

Mobile Hub

Elastic Beanstalk

ACM Inspector

GameLift

CodePipelineCodeDeploy

ほとんどのサービスに⽤意されたAPI

Page 24: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

SDK

Ruby

iOS

Python (boto)

Android Node.js

AWS Toolkit for Visual

Studio

.NET

AWS Toolkit for Eclipse

PHP

AWS Tools for Windows PowerShell

AWS CLI

JavaScriptJava

Xamarin

Page 25: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

SDK

Java

Page 26: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless
Page 27: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

プログラマブル✤ クラウドはAPIでコントロールできるのが当たり前

✤ AWSの場合、ほぼ全てのサービスにAPIがある

✤ ネットワークからプラットフォーム⾃体まで、どのレイヤもプログラマのコンテキストでコントロールできる

✤ 各サービスの利⽤を抽象化たフレームワークを⽤意して透過的に利⽤することも可能

Page 28: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

つまり全てを意のままに

Page 29: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

EC2インスタンスを起動する例

RunInstancesRequest runInstancesRequest = new RunInstancesRequest();

runInstancesRequest.withImageId("ami-4b814f22").withInstanceType("m1.small").withMinCount(1).withMaxCount(1).withKeyName("my-key-pair").withSecurityGroups("my-security-group");

Page 30: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

DynamoDBにデータを⼊れる例

AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());

DynamoDBMapper mapper = new DynamoDBMapper(client);CatalogItem item = new CatalogItem();item.setId(102);item.setTitle("Book 102 Title");item.setISBN("222-2222222222");item.setBookAuthors(new HashSet<String>(Arrays.asList("Author 1", "Author 2")));item.setSomeProp("Test");

mapper.save(item);

Page 31: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Javaアプリをクラウドで実⾏

Page 32: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

実⾏パターン✤ Amazon Elastic Compute Cloud (EC2)

✤ Docker + Amazon EC2 Container Service (ECS)

✤ AWS Lambda

Page 33: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWSのComputeサービス

Amazon EC2 Amazon ECS AWS Lambda

スケールの単位 インスタンス アプリケーション ファンクション

抽象化 ハードウェア OS ランタイム

Page 34: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWSのComputeサービス

Amazon EC2 Amazon ECS AWS Lambda

スケールの単位 インスタンス アプリケーション ファンクション

抽象化 ハードウェア OS ランタイム

Page 35: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Amazon EC2✤ 台数やスペックを柔軟に変更可能な仮想サーバ

⎻ 各種Linux/Windows⎻ 多様なインスタンスタイプ、状況に応じて最適なスペックを選択可能

✤ AMI(Amazon Machine Image)を利⽤した環境のコピーによる構築やAutoScalingによる⾃動スケールアウト/スケールイン

✤ 慣れ親しんだ通常のサーバと同じように扱える⎻ 好きなランタイム、アプリケーションサーバの導⼊⎻ これまでの知識をそのまま活かすことが可能※ただし、クラウド固有の機能や特性を活かすほうがオススメ

Page 36: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

EC2と合わせてよく使われるサービス✤ ELB(Elastic Load Balancing)

⎻ マネージドロードバランサーサービス⎻ L4ベースのCLBとコンテンツベース(L7)のルーティングを提供するALB⎻ ALBはコンテナベースのアプリケーションもサポート

✤ Amazon RDS⎻ マネージドデータベースサービス⎻ MySQL/PostgreSQL/Oracle/SQL Serverといって⼀般的なエンジンに加え、

クラウドネイティブに設計されたAuroraも利⽤可能⎻ 冗⻑構成、マスタ/スレーブ構成や⾃動バックアップなどを数クリックで利⽤可能

✤ Amazon S3⎻ 容量無制限のオンラインストレージ⎻ ⾃動的に複数DCに保存し、⾼い耐久性を実現⎻ 保存した分だけの安価な従量課⾦

Page 37: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

⼀般的な3-tier Webアプリの場合プレゼンテーション層 ロジック層 データストア層

Webサーバ/アプリサーバブラウザ/モバイル データベース

Page 38: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWSで作るとこうなる

AP(EC2)

DB(RDS)

LB(ELB)

Web(EC2)

Static Contents(S3)

ブラウザ/モバイル CDN(CloudFront)

Page 39: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless
Page 40: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

イイのあります

Page 41: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless
Page 42: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWS Elastic Beanstalk定番構成の構築/デプロイを

⾃動化するサービス

Page 43: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWS Elastic Beanstalk✤ELB + Web+(DB)の定番構成で利⽤

✤Auto Scaling利⽤可能

✤ログやアプリはS3に

Page 44: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWS Elastic Beanstalk✤アプリケーションを簡単にデプロイ

✤複数環境を切り替え可能

Page 45: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

対応している構成と⾔語環境

Elastic LoadBalancing

Web Tier

deploy!

Java Python PHP .NET Ruby nodeJS Docker

Amazon RDS

Auto scaling Group

Auto scaling GroupQueueAsyncTasks

Worker Tier

Page 46: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWSのComputeサービス

Amazon EC2 Amazon ECS AWS Lambda

スケールの単位 インスタンス アプリケーション ファンクション

抽象化 ハードウェア OS ランタイム

Page 47: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

コンテナのメリット

PortableFlexibleFastEfficient

Server

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 48: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

コンテナのメリット

⼀貫性のある環境 ⾼い⽣産性 バージョン管理 効率的なオペレーション

Page 49: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Dockerの特徴

PackageShipRun

Page 50: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Dockerfile例# GlassFish on DockerFROM glassfish/openjdk

# MaintainerMAINTAINER Bruno Borges <[email protected]>

# Set environment variables and default password for user 'admin'ENV GLASSFISH_PKG=glassfish-4.1.1.zip \

GLASSFISH_URL=http://download.oracle.com/glassfish/4.1.1/release/glassfish-4.1.1.zip \GLASSFISH_HOME=/glassfish4 \PATH=$PATH:/glassfish4/bin \PASSWORD=glassfish

# Install packages, download and extract GlassFish# Setup password file# Enable DASRUN apk add --update wget unzip && \

wget --no-check-certificate $GLASSFISH_URL && \unzip -o $GLASSFISH_PKG && \rm -f $GLASSFISH_PKG && \apk del wget unzip && \echo "--- Setup the password file ---" && \echo "AS_ADMIN_PASSWORD=" > /tmp/glassfishpwd && \echo "AS_ADMIN_NEWPASSWORD=${PASSWORD}" >> /tmp/glassfishpwd && \echo "--- Enable DAS, change admin password, and secure admin access ---" && \asadmin --user=admin --passwordfile=/tmp/glassfishpwd change-admin-password --domain_name domain1 && \asadmin start-domain && \echo "AS_ADMIN_PASSWORD=${PASSWORD}" > /tmp/glassfishpwd && \asadmin --user=admin --passwordfile=/tmp/glassfishpwd enable-secure-admin && \asadmin --user=admin stop-domain && \rm /tmp/glassfishpwd

# Ports being exposedEXPOSE 4848 8080 8181

# Start asadmin console and the domainCMD ["asadmin", "start-domain", "-v"]

Page 51: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Cluster Management

Page 52: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

$ docker run myimage

Server

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 53: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless
Page 54: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Amazon EC2 Container Service (ECS)✤ 管理ノード不要の、安定かつ⾼パフォーマンスなクラスタ管理サービス

✤ Dockerコンテナを複数のEC2インスタンスに分散配置

✤ ⼀時的な計算処理にも、ロングランニングな処理にも対応

✤ ELB連携など各種AWSサービスとの親和性

✤ Amazon ECS⾃体の利⽤は無料

複数のコンテナをEC2のクラスタ上で⼀元管理できるサービス

Page 55: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Cluster Management Engine

Agent Communication Service API

Key/Value Store

Amazon ECS

AZ

ECS Agent

Container Instance

Task

Container

Task

Container

Docker

AZ

ECS Agent

Container Instance

Task

Container

Task

Container

Docker

ECS Agent

Container Instance

Task

Container

Task

Container

Docker

ELB ELB

User/Scheduler

Page 56: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWSのComputeサービス

Amazon EC2 Amazon ECS AWS Lambda

スケールの単位 インスタンス アプリケーション ファンクション

抽象化 ハードウェア OS ランタイム

Page 57: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

すべてのデベロッパーをハッピーに

AWS Lambda

⾼いコスト効率インフラ管理不要

使った分だけ100ms単位で課⾦

⾃分のコードを実⾏

標準的な⾔語のコードを実⾏ビジネスロジックにフォーカス

Page 58: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

サーバレスなアプリケーションモデルイベントソース ファンクション サービスなど

JavaNode.jsPython

λイベント

S3にオブジェクトが作られるKinesisにストリームデータが保存されるHTTPSによるリクエストetc...

Page 59: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Amazon S3 Amazon DynamoDB

Amazon Kinesis

AWS CloudFormation

AWS CloudTrail

Amazon CloudWatch

Amazon SNSAmazonSES

AmazonAPI Gateway

Amazon Cognito

AWSIoT

AmazonAlexa

Cron events

DATASTORES ENDPOINTS

REPOSITORIES EVENT/MESSAGESERVICES

AWS Lambdaと連携するイベントソース

Amazon Config

Amazon Aurora

New!

Page 60: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

プログラミングモデル(Javaの場合)

✤ inputType / outputType⎻ inputTypa: イベントソースから発⾏されたイベントデータもしくは任意のデータオブジェクト⎻ outputType: 同期呼び出し時のレスポンスとなり、サポートされているあらゆる型を利⽤可能

✤ Context(省略可能)⎻ Lambdaファンクションの実⾏環境に関する情報が格納されている

✤ 利⽤可能な型⎻ プリミティブ型(intなど)およびString、Integer、Boolean、Map、List、Stream⎻ aws-lambda-java-eventsで提供されるイベントデータ型(S3Eventなど)⎻ 独⾃のPOJOオブジェクト

⎻ ⾃動的にJSON形式にシリアライズ/デシリアライズされるが、⾃前でやりたい場合はStream型を指定する

✤ Contextオブジェクトや事前定義済みのインターフェースを提供するaws-lambda-java-coreと各イベントの事前定義された型を提供するaws-lambda-java-eventsを利⽤して実装すると楽

publicoutputType handler-name(inputType input,Contextcontext){...

}

Page 61: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

コード例package com.sample.lambda;

import com.amazonaws.services.lambda.runtime.Context;import com.amazonaws.services.lambda.runtime.LambdaLogger;import com.amazonaws.services.lambda.runtime.events.S3Event;import com.amazonaws.services.s3.AmazonS3;import com.amazonaws.services.s3.AmazonS3Client;import com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord;import com.amazonaws.services.s3.model.GetObjectRequest;import com.amazonaws.services.s3.model.S3Object;

public class S3EventHandler {public String handler(S3Event event, Context context) {

LambdaLogger lambdaLogger = context.getLogger();

S3EventNotificationRecord record = event.getRecords().get(0);String bucket = record.getS3().getBucket().getName();String key = record.getS3().getObject().getKey();

AmazonS3 s3 = new AmazonS3Client();S3Object object = s3.getObject(new GetObjectRequest(bucket, key));String content_type = object.getObjectMetadata().getContentType();

lambdaLogger.log("Content-Type: " + content_type);

return content_type;}

}

Page 62: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWS Lambdaを利⽤する場合のユースケース

Data Processing Control SystemsBackends

Page 63: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWS Lambdaを利⽤する場合のユースケース

データの変更、システム状態の遷移もしくはユーザによるアクションといったものに対応したコードの実⾏

レスポンスのカスタマイズとAWS内の状態やデータ変更に対するワークフローのレスポンス

Web、モバイル、IoTや外部APIへのリクエストを扱うバックエンドロジックの実⾏

Data Processing

Backends

Control Systems

Page 64: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Real-time File Processing✤ イメージのサムネイル⽣成やビデオの変換✤ ドキュメントのメタデータをインデックス化✤ ログの処理✤ メディアコンテンツのバリデーション

元画像 サムネイル画像

1

2

31.ファイルストレージを

提供するAmazon S32.処理ロジックを提供す

るAWS Lambda

Page 65: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWS 導⼊事例:株式会社スクウェア・エニックス✤ ドラゴンクエストⅩ✤ ゲーム内で写真撮影し、Lambdaでサムネイル画像作成や

コピーライトの追加加⼯✤ 処理時間が数時間→10 数秒で完了✤ 同じ処理をオンプレミスと⽐べ 20 分の 1 程度まで削減

“AWS Lambda の効果は劇的でした。今まで数時間かかっていた画像処理がわずか 10 数秒で完了しました。コストに関しても、同じ処理をオンプレミスで⾏う場合と⽐べ 20 分の 1 程度にまで削減することができました。 AWS Lambda にはそもそもリソースが⾜りなくなるという発想がありません。これはオンプレミスでは真似のできないものです。” 縣 ⼤輔⽒

第 6 ビジネス・ディビジョン テクニカルディレクター

Page 66: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Webバックエンドの場合

AP(EC2)

DB(RDS)

LB(ELB)

Web(EC2)

Static Contents(S3)

ブラウザ/モバイル CDN(CloudFront)

Page 67: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

サーバレススタックで置き換えると

ブラウザ/モバイル API Gateway AWS Lambda DynamoDB etc

S3CloudFront

AWSによるマネージ(フルマネージド)

Page 68: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Amazon API Gateway

統⼀化されたAPIの作成と管理

APIの定義とホスティング

クラウド上のリソースへのアクセス認証

AWSのAuthを活⽤

バックエンド保護のためのDDoS対策やスロットリング

ネットワークトラフィックの管理

Page 69: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Serverless = No servers to manage and scale

Page 70: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

サーバレスのメリット✤ サーバレスはバックエンドのアウトソース

⎻ サーバサイドやインフラがわからないフロントエンジニアだけでシステムを実現することも可能

⎻ バックエンド側のコードとサーバが減るため開発運⽤コストが最⼩化⎻ ⾃分の書いたコードをすぐ試せる、トライ&エラーが容易⎻ サービスプロバイダによってマネージされ、スケーラビリティやキャパシティ、

セキュリティの⼼配が不要⎻ ⾮常にコスト効率化が⾼く、多くの場合コスト減が⾒込める

✤ 開発者がビジネスにフォーカスできる

Page 71: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

You donʼt do that, we do that.

Page 72: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

(注)API Gateway+Lambdaが向くもの/向かないもの

✤ 向くもの⎻ シンプル(単機能に近い)WebアプリのAPI⎻ マイクロサービス

✤ 向かないもの⎻ 複雑なモノリシックアプリケーション※モノリシックが悪いと⾔っているのではないので誤解しないように

Page 73: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

サーバレスのエコシステム

Serverless FrameworkClaudia.jsAPEXPythonServerless Microframework

Build, CI/CD

ロギングとモニタリング 開発とデプロイ

sumologic

Page 74: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

DEMO: Serverlessを使ったJava APIの作成と公開

Page 75: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

クラウド上でのアプリケーションの基本✤ 障害を前提としたデザイン(Design for failure)✤ 疎結合✤ 弾⼒性の実装✤ 全てのレイヤでセキュリティを担保✤ 並列処理✤ ワークロードにあわせてデータベースを使い分ける

Page 76: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

The Twelve-Factor App✤ モダンなWebアプリケーション開発のための⽅法論

✤ 直接的にクラウドと関連する話しではないが⼀読しておくべき

✤ URLhttp://12factor.net/http://12factor.net/ja/(⽇本語訳)

Page 77: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

まとめ✤ Javaとクラウド

⎻ Java SDKとAPIを使ってプログラマブルに⎻ Javaアプリケーションを実⾏する⽅法は複数ある

✤ Javaアプリの実⾏⎻ ベーシックなEC2からLambdaを使ったサーバレスまで⎻ 適材適所・ワークロードや状況によってサービスを使い分ける

✤ クラウドを最⼤限に活かすには、クラウド上でのアプリ開発の基本に従うこと

Page 78: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

AWS re:Invent 2016 Serverless Follow Up✤ AWS re:InventのServerlessにフォーカスしたフォローアップイベント

⎻ 12/7(⽔)19時〜⎻ アマゾンジャパン(とサテライト会場)

✤ 登録は以下のURLからhttp://aws-serverless.connpass.com/event/42950/

✤ 当⽇現地に来れない⽅のためにストリーミング配信も⽤意しました登録はこちら⇒ http://aws-serverless.connpass.com/event/45295/

Page 79: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless

Part1http://qiita.com/advent-calendar/2016/serverlessPart2http://qiita.com/advent-calendar/2016/serverless2

Page 80: Running Java Apps with Amazon EC2, AWS Elastic Beanstalk or Serverless