56
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Akihiro Tsukada Startup Senior Solutions Architect, Amazon Web Services Japan K.K. 2-H1-3-11 AWS 上の Blockchain アプリケーション実装

AWS 上の Blockchain アプリケーション実装 · AWS 上のBlockchain アプリケーション ... 新規ノードをネットワーク上にデプロイするとき、クライアントは最初に全

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Akihiro Tsukada

Startup Senior Solutions Architect, Amazon Web Services Japan K.K.

2-H1-3-11

AWS 上の Blockchain アプリケーション実装

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

• 塚田 朗弘(つかだ あきひろ)

• スタートアップ

シニアソリューションアーキテクト

• #blockchain #fintechsecurity

#serverless #mobile #startup

#developer

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

このセッションについて

• 対象者

• ローカルや別の環境では Blockchain アプリケーションの

経験があるが、AWS 上でどのように開発すればよいか、

どんなサービスを活用できるか知りたい方

• ゴール

• AWS を活用した Dapps – Decenterized Applications の

構築、開発方法を理解すること

• 後半部分では、主に Ethereum / Solidity による開発を想定

※ コードの書き方の話は含まれません

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

アジェンダ

• AWS と Blockchain

• AWS のスタンス

• 事例

• AWS が提供する Blockchain 関連のリソース

• Dapps 開発に AWS を活かす

• セキュリティを意識した開発シナリオ

• AWS で作る Smart Contract 開発パイプライン

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Blockchain

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS のスタンス

• " 分散台帳技術はイノベーションの最先端だ。

AWS は、イノベーションの加速とよりよい体験の実現の

ために、様々な金融機関および多くの分野 * の

Blockchain プロバイダ とともに活動している "

- Head of AWS Financial Services Business Development

*) AWS 上で運用される Blockchain の適用分野医療、機微情報の共有、マーケティングと消費者情報管理、仮想通貨とスマートコントラクト、コーポレート・ガバナンス、金融取引 etc

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

ユースケースやワークロードを限定しない

• アマゾンは選択肢を揃え、お客様の購買判断を促進し体験を向上させる

AWS

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

ユースケースやワークロードを限定しない

ENTERPRISE APPSDEVELOPMENT & OPERATIONSMOBILE SERVICESAPP SERVICESANALYTICS

Data

Warehousing

Hadoop/Spark

Streaming

Data

Collection

Machine

Learning

Elastic

Search

Virtual

Desktop

s

Sharing &

Collaborati

on

Corporat

e Email

Backup

Queuing &

Notifications

Workflow

Search

Email

Transcodi

ng

One-click

App

Deploymen

t

Identity

Sync

Single

Integrated

Console

Push

Notificatio

ns

DevOps

Resource

Management

Application

Lifecycle

Management

Containe

rs

Triggers

Resource

Templates

TECHNICAL &

BUSINESS

SUPPORT

Account

Management

Support

Profession

al Services

Training &

Certification

Security &

Pricing

Reports

Partner

Ecosystem

Solutions

Architects

MARKETPLACE

Business

Apps

Business

Intelligence

Database

s

DevOp

s Tools

Networki

ngSecurity

Storag

e

RegionsAvailability

Zones

Points of

Presence

INFRASTRUCTURE

CORE SERVICES

ComputeVMs, Auto-

scaling, & Load

Balancing

StorageObject, Blocks,

Archival,

Import/Export

DatabasesRelational, NoSQL,

Caching, Migration

Networki

ngVPC, DX,

DNS

CDN

Access

Control

Identity

Management

Key

Managemen

t & Storage

Monitoring

& Logs

Assessment

and

reporting

Resource &

Usage

Auditing

SECURITY & COMPLIANCE

Configuratio

n Compliance

Web

application

firewall

HYBRID

ARCHITECTURE

Data

Backups

Integrated

App

Deployment

s

Direct

Connect

Identity

Federation

Integrated

Resource

Manageme

nt

Integrate

d

Networki

ng

API

Gateway

IoT

Rules

Engine

Device

Shadows

Device

SDKs

Registry

Device

Gateway

Streaming Data

Analysis

Business

Intelligence

Mobile

Analyti

cs

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

パートナー事例: Intel, T-Mobile, PwC, pokitdok

https://www.youtube.com/watch?v=z29SCJQfBmM

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

事例: Bank of England

https://www.youtube.com/watch?v=8o7OtIyWUek

https://www.slideshare.net/AmazonWebServices/aws-reinvent-2016-blockchain-on-aws-disrupting-the-norm-gpst301

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

事例: coinbase

https://www.youtube.com/watch?v=bhW6ORU8MpI

https://engineering.coinbase.com/how-coinbase-builds-secure-infrastructure-to-store-bitcoin-in-the-cloud-30a6504e40ba

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

事例: ConsenSys - INFURA

https://www.youtube.com/watch?v=YHSSzV8DOII= =

"Boomerang"

Amazon

RDS

Amazon

ElastiCache

EBS

S3

EC2ALB

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

事例: ConsenSys - INFURA

https://www.youtube.com/watch?v=YHSSzV8DOII

Scalability Challenge: Initial Blockchain Sync● Ethereum は継続的に成長する、トランザクションハッシュのマークル木を

含むブロックのチェーン

● 新規ノードをネットワーク上にデプロイするとき、クライアントは最初に全

チェーンデータを同期しなければならない

● チェーンを非常に重いブロックにする攻撃も常にあり、同期が難しい

● 2017年5月現在、Ethereum ネットワークは誕生から 2 年、360万ブロック、

合計 100 GBのデータに達する

● データは Ethereum がより普及するにつれ非線形に成長していく

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

事例: ConsenSys - INFURA

https://www.youtube.com/watch?v=YHSSzV8DOII= =

Scalability Challenge: Initial Blockchain SyncDynamic IOPS

● cloud-init の userdata を利用して依存関係(ライブラリ、S3 のターゲットロケーション等)のインストールを自動化(AMI に作り込むことができる)

● Amazon CloudWatch メトリクスを利用し、どの地域のブロックチェーンの同期が攻撃により遅れているかを判断

● ブロックチェーン内の "Tough Spots" を解決し、同期時間を最適化するためボリュームの IOPS を動的にサイジング

● コスト最適化のため、一度同期が済んだら動的に IOPS を減らす

● 今後 Ethereum ネットワークが攻撃されても、攻撃の検知と高ディスク I/O に対応するために Amazon CloudWatch メトリクスを利用する

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

事例: ConsenSys - Kaleido

https://kaleido.io/get-started/

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS

Blockchain

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS が提供する Blockchain 関連のリソース

AWS Blockchain

テンプレート

https://aws.amazon.com/blockchain/

Blockchain

パートナーズポータル

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Blockchain パートナーズポータル

• Blockchain 関連のAPNパートナーソリューションポータル

(2017年12月に発表)

https://aws.amazon.com/jp/partners/blockchain/

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

• AWS上のリソース(EC2, S3 等の各種コンポーネント)を

JSONまたはYAMLで記述・管理する構成管理サービス

• 環境の構築、構成変更時の反映を自動化

• 追加料金はなし

https://aws.amazon.com/jp/cloudformation/

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Blockchain テンプレート

• 一般的な Blockchain フレームワークをすばやく構築するための

AWS CloudFormation テンプレート(2018年4月に発表)

• 2018年 5月現在は Ethereum と Hyperledger Fabric に対応

• 他のフレームワークにも対応予定 → フィードバックをください!

• Blockchain の管理、モニタリング、参照を行うための

追加コンポーネントも含まれる

• スターターキットとして最適

https://aws.amazon.com/jp/blockchain/templates/

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Blockchain テンプレート

• 起動時のパラメータ(networkId)

指定によって接続先ネットワーク

を選択

• 1: mainnet, 3: Ropsten etc

• Geth client, Geth miner, Eth Stats,

Eth Explorer の Docker コンテナを

自動で起動

Ethereum on Amazon ECS

Eth Stats

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Blockchain テンプレート

• 起動時のパラメータで Fabric のチャネル名、

ドメインなどを指定

• Peer ノード、Orderer、Explorer、が起動

Hyperledger on Amazon EC2

Explorer

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

アジェンダ

• AWS と Blockchain

• AWS のスタンス

• 事例

• AWS が提供する Blockchain 関連のリソース

• Dapps 開発に AWS を活かす

• セキュリティを意識した開発シナリオ

• Smart Contract 開発をAWSでパイプライン化する

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

※この資料内で使うツール・フレームワーク

• go-ethereum – geth

• Official golang implementation of the Ethereum protocol

• Truffle

• ConsenSys 社製の Smart Contract フレームワーク

• JavaScript / Solidity でのテストに対応

• testrpc を内包しており、すぐにテストが始められる

• 作業環境

• macOS Sierra

• Node.js v8.10.0, geth 1.8.8-stable, truffle v4.1.8, Solidity v0.4.23

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

※この資料内で使う AWS のサービス

• AWS CodePipeline

• CI/CD パイプラインの全体を制御し、リリースプロセスを自動化する

• AWS CodeCommit

• 安定性が高くスケーラブル、従量課金なプライベート Git リポジトリ

• IAM でアクセス権限を制御できる

• AWS CodeBuild

• Docker 上で任意のコマンドやテスト、ビルドを実行する

• CodeCommit への push や CodePipeline をトリガーに起動

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Ethereum / Solidity

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

なぜセキュリティを強く意識するのか

• Smart Contract は原則的にロールバックが難しい

• Upgradable Contracts なども出てきてはいるものの…

• Smart Contract 上のバグはしばしば大規模な事故、損害に

https://paritytech.io/security-alert-2/

Parity Multisig Wallet

- 300 ETH

https://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/

The DAO - 360 ETH

→, CI

( )

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

参考: システムアーキテクチャのセキュリティについてはAWS FinTech リファレンス・アーキテクチャもご参照下さい

https://amzn.to/awsj-fintech

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. 動作確認

5. testnet にデプロイ

6. 動作確認

7. Mainnet にデプロイ

8. 動作確認

セキュリティを意識した開発シナリオ

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Smart Contract

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

C9

: IDE AWS Syntax

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

AWS

CodeBuild

privatenet

(on AWS)testnet mainnet

AWS

CodePipeline

2

3 5 7

QA

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

実装・構築手順

Developer

AWS

CodeCommit

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1.1 CodeCommit にリポジトリ作成 & Clone

https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/how-to-create-commit.html

$ git config --global credential.helper ¥

'!aws codecommit credential-helper $@'

$ git config --global credential.UseHttpPath true

$ git clone https://git-codecommit.xxx.amazonaws.com/v1/repos/MyRepo

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1.2 ローカルで開発、テスト、コミット

$ brew tap Ethereum/Ethereum && brew install Ethereum

$ npm install –g truffle

$ vim contracts/MyContract.sol

$ vim test/TestMyContract.js

$ truffle test

Using network 'test'.

(...snip...)

Contract: MyContract

✓ should put 10000 MetaCoin in the first account

1 passing (1s)

$ git add -A && git commit -m 'add MyContract and Test'

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

AWS

CodeBuild

AWS

CodePipeline

2

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

2.1 CodePipeline のパイプライン作成

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

2.2 buildspec.yaml$ vim buildspec.yaml1 version: 0.223 phases:4 install:5 commands:6 - echo Entered the install phase on `date`7 - echo npm version `npm -v`8 - npm install9 - export PATH=./node_modules/.bin:$PATH10 - echo truffle version .. `truffle version`11 build:12 commands:13 - echo Entered the commands phase on `date`14 - truffle test15 artifacts:16 files:17 - '**/*'

https://docs.aws.amazon.com/ja_jp/codebuild/latest/userguide/build-spec-ref.html

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

2.3 push して自動で build$ git push -u origin master

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

2.3 push して自動で build$ git push -u origin master

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

AWS

CodeBuild

privatenet

(on AWS)

AWS

CodePipeline

2

3

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

3.1 privatenet へのデプロイステージを追加

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

AWS

CodeBuild

privatenet

(on AWS)

AWS

CodePipeline

2

3

QA

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

4.1 承認プロセスを追加

https://docs.aws.amazon.com/ja_jp/codepipeline/latest/userguide/approvals.html

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

4.2 承認ステージまで来ると待ち状態に

https://docs.aws.amazon.com/ja_jp/codepipeline/latest/userguide/approvals.html

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

AWS

CodeBuild

privatenet

(on AWS)testnet

AWS

CodePipeline

2

3 5

QA

※ 5 7

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

AWS

CodeBuild

privatenet

(on AWS)testnet

AWS

CodePipeline

2

3 5

QA

※ 5 7

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

AWS

CodeBuild

privatenet

(on AWS)testnet mainnet

AWS

CodePipeline

2

3 5 7

QA

※ 5 7

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

1. ローカルで開発、テスト

2. CI などを利用してテスト

3. privatenet にデプロイ

4. ≪承認プロセス≫

5. testnet にデプロイ

6. ≪承認プロセス≫

7. mainnet にデプロイ

AWSでパイプラインを作るなら

Developer

AWS

CodeCommit

AWS

CodeBuild

privatenet

(on AWS)testnet mainnet

AWS

CodePipeline

2

3 5 7

QA

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

完成したパイプライン

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS で Smart Contract 実装フローをパイプライン化

• 自動テストの徹底

• デプロイフローの徹底

• 手動による動作確認には承認プロセスで対応

• 当然ながら自動化による種々の恩恵も

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

まとめ

• AWS は幅広い Blockchain のワークロードをサポート、

事例も豊富

• 開発時にすぐ利用できるリソースを多く提供

• Blockchain Templates、パートナーズポータル

• AWS のサービスを活用することで Smart Contract の

開発も自動化が可能、効率とセキュリティ向上へ

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.