無伺服器架構和containers on aws入門

40
AWS Cloud Kata for Start-Ups and Developers Hong Kong Getting Started with Serverless and Container Architectures Dickson Yue Solutions Architect, AWS

Upload: amazon-web-services

Post on 16-Apr-2017

745 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Hong Kong

Getting Started with Serverless and Container Architectures

Dickson Yue Solutions Architect, AWS

Page 2: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Key take way

Deploy your Containers with ECS Develop services with Lambda Build your micro services architecture with Serverless (Lambda) and Container (ECS)

Page 3: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Operational complexity - “I want to run some code in the cloud” •  …but ops are complicated, and I don’t have an ops guy

Undifferentiated instances - “I want flexibility to use the code I like” •  …but OS and runtime configuration? Don’t really care.

Capacity management concerns - “My business scales with users and requests” •  …but I don’t want a planning exercise to reserve and provision capacity

Low utilization but high scale - “I want infinite scale” •  …but I only want to pay for calls I actually make

Run some code in the cloud

Page 4: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

How do I choose? •  VMs

•  “I want to configure machines, storage, networking, and my OS”

•  Containers •  “I want to run servers, configure

applications, and control scaling”

•  Serverless •  “Run my code when it’s needed”

ECS

EC2

AWS Lambda

Page 5: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Amazon Route 53 User

Amazon CloudFront

Web

RDS Master (Multi-AZ)

Elastic Load

Balancer

RDS Slave (Multi-AZ)

Web

Availability Zone Availability Zone

Page 6: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Micro services Amazon Route 53 User

Amazon CloudFront

Static website *.html, *.js *.css *.jpg *.mp4

S3 Web

RDS Master (Multi-AZ)

RDS Slave (Multi-AZ)

Zone A Zone B

DynamoDB

Fn1()

API Gateway

Fn2() Fn3()

Redis MySQL

Web

RDS Master (Multi-AZ)

RDS Slave (Multi-AZ)

Zone A Zone B

EC2 Containter Serverless

Service Alpha Service Delta, Gamma Service Beta

Page 7: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Conatiner

Page 8: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

  Self managed EC2

  Elastic Beanstalk

  Elastic container service (ECS)

Deployment options

Page 9: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Server

Guest OS

Bins/Libs Bins/Libs

App2 App1

Managing One Host is Straightforward

Page 10: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Managing a Fleet is Hard

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

Server

Guest OS

AZ 1 AZ 2

AZ 3

Page 11: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

What is EC2 Container Service?

Page 12: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Cluster Management Made Easy

  No cluster software to install and manage

  Manages cluster state

  Manages containers

  Control and monitoring

  Scale from one to tens of thousands of containers

Page 13: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Designed for use with other AWS services

Elastic Load Balancing Amazon Elastic Block Store

Amazon Virtual Private Cloud AWS Identity and Access Management

AWS CloudTrail

Page 14: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Key Components

  Clusters

  Containers

  Task Definitions

  Service

Page 15: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Typical User Workflow

I have a Docker image, and I want to run the image on a cluster

Page 16: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Typical User Workflow

Push Image(s)

Amazon ECR

Docker Hub

Or

> docker build -t dicksonyue/aws-voting-app:ecsdemo . > docker push dicksonyue/aws-voting-app:ecsdemo

Page 17: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Typical User Workflow

Create Task Definition Amazon ECS

Task Definition -  Image -  CPU, memory -  Port mapping -  CMD, ENV

> aws ecs register-task-definition --cli-input-json file://ecs-task.json

Page 18: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Task {

"family": "kata-demo-task",

"containerDefinitions": [

{

"name": "kata-demo-container",

"image": "dicksonyue/aws-voting-app:alpha",

"cpu": 10, "memory": 500,

"portMappings": [{

"containerPort": 8080

}],

"essential": true,

"command": [ "npm", "start"],

"environment" : [

{ "name" : "REDIS_HOST", "value" : "ecs-demo.cw7bo2.0001.usw2.cache.amazonaws.com" },

{ "name" : "REDIS_PORT", "value" : "6379" } ]

}

]}

Resources

Docker image

CMD, ENV

Page 19: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Typical User Workflow

Run Instances EC2

Use custom AMI with Docker support and ECS Agent. Instances will register with default cluster.

> aws ecs create-cluster --cluster-name "ecs-demo" > aws autoscaling create-launch-configuration --cli-input-json file://launch-config.json --user-data file://userdata.txt > aws autoscaling create-auto-scaling-group --cli-input-json file://auto-scaling-group.json

Page 20: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

User data.txt #!/bin/bash

echo ECS_CLUSTER=ecs-demo >> /etc/ecs/ecs.config

Page 21: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Cluster Management: Resource Management

Docker

EC2 Instance

Docker

EC2 Instance

Docker

EC2 Instance

AZ 1 AZ 2

Cluster:ecs-demo

Page 22: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Typical User Workflow

Run Task or

Create Service Amazon ECS

Using the task definition created above > aws ecs run-task --task-definition vote-app-task --

cluster ecs-demo

> aws ecs create-service --cli-input-json file://ecs-service.json

Page 23: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Cluster Management: Scheduling

Docker Task

EC2 Instance

Container

Docker Task

EC2 Instance

Container

Task Container

Docker

EC2 Instance

Task Container

AZ 1 AZ 2

Page 24: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Task vs Service

Task •  One time execute •  Batch job

Service

•  One or different tasks (i.e. nodejs, ngnix) •  Task count (4 nodejs containers) •  Container and ELB port binding •  Auto scaling at task level •  Always on - Web application

Containers

Page 25: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Service {

"cluster": "ecs-demo",

"serviceName": "vote-app-service",

"taskDefinition": "vote-app-task",

"loadBalancers": [

{

"targetGroupArn": "arn:aws:elasticloadbalancing:us-west-2:179303575282:targetgroup/voting-app/99ffe4fab0a151e9",

"containerName": "kata-demo-container",

"containerPort": 8080

}

],

"desiredCount": 2,

"role": "ecsServiceRole”

}

Application load balancer

Container port

IAM Role

Page 26: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

DEMO

Page 27: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Serverless

Page 28: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

2)Con'nuousScaling1)NoServerstoManageAWSLambdaautoma-callyscalesyour

applica-onbyrunningcodeinresponsetoeachtrigger.Yourcoderunsinparallelandprocesseseachtriggerindividually,scalingpreciselywiththesizeoftheworkload.

3)SubsecondMeteringWithAWSLambda,youarechargedforevery100msyourcodeexecutesandthenumberof-mesyourcodeistriggered.Youdon'tpayanythingwhenyourcode

isn'trunning.

AWSLambdaautoma-callyrunsyourcodewithoutrequiringyoutoprovisionor

manageservers.JustwritethecodeanduploadittoLambda.

BenefitsofAWSLambda

Page 29: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

How Lambda works

S3 event notifications

DynamoDB Streams

Kinesis events

Cognito events

SNS events

Custom events

CloudTrail events Lambda DynamoDB

Kinesis S3

Any custom

Redshift

SNS

Any AWS

Page 30: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

AWS Lambda, API Gateway, and AWS IoT regions

Available regions

Singapore

Page 31: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Lambda usage scenarios

Page 32: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Use case: Data processing Example: Amazon S3 bucket triggers

Amazon S3 bucket events

Original object Compressed object 1

2

3

AWS Lambda

Page 33: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Use case: Dynamic data ingestion “Iwanttoapplycustomlogictoprocesscontentbeinguploadedtomydatastore”.•  PDFwatermarking•  Imagethumbnailingandtranscoding•  DocumentmetadataIndexing•  Logaggrega-onandfiltering•  RSSfeedprocessing•  Mediacontentvalida-on

Page 34: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Use case: Realtime data stream processing: Amazon Kinesis

“IwanttoapplycustomlogictoprocesslogsbeinguploadedthroughmyKinesisstream”.•  Clientac-vitytracking•  metricsgenera-on•  datacleansing•  Logfiltering•  indexingandsearching•  Logrou-ng

Page 35: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Use case: mobile backend 1.  AWS Mobile SDK + Amazon Cognito for mobile app

Or AWS IoT for devices

2.  AWS Lambda runs the code 3.  Amazon API Gateway (if you want your own endpoint) 4.  Amazon DynamoDB holds the data

AWS Lambda Amazon DynamoDB

Page 36: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Use case: Serverless web apps

1.  Amazon S3 for serving static content 2.  AWS Lambda for dynamic content 3.  Amazon API Gateway for https access 4.  Amazon DynamoDB for NoSQL data storage

Dynamic content in AWS Lambda

Data stored in Amazon

DynamoDB

API Gateway Static content in Amazon S3

Page 37: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

re:Invent 2015 •  Python •  Scheduled functions •  Longer running times (5 min.) •  Versioning

Recent launches

Since re:Invent •  Higher code storage limits (from 5 GB to

75 GB) •  Custom VPC •  1-minute schedules •  New regional launch •  Node.js 4.3.2 •  1-click CORs setup •  Stage variables •  Custom (Lambda) authorizers •  Builtin Swagger import/export •  AWS CloudFormation support for API

Gateway and versions

New!

Page 38: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

DEMO

Page 39: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Container   ECS   Cluster   Task & Service   AWS CLI or Console

Summary

Serverless   Lambda   Use cases   New features

Page 40: 無伺服器架構和Containers on AWS入門

AWS Cloud Kata for Start-Ups and Developers

Hong Kong

Thank you