Top Banner
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. , 4CSoft 2017.01.21 AWS Step Functions AWSKRUG re:Invent
58

AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

Apr 11, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

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

, 4CSoft

2017.01.21

AWS Step Functions AWSKRUG re:Invent

Page 2: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

• ([email protected]) • 4CSoft Inc. • iOS 4 • Node.js 1 • AWSKRUG

• AWS : EC2, S3, Route53 … Lambda

Page 3: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

re:Invent 2016

Page 4: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

re:Invent 2016

Page 5: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λ

Page 6: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λλλ

Page 7: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λλλ

λ λλ λ

λλ λ

λ

λ

Page 8: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λλλ

λ λλ λ

λλ λ

λ

λ

Queue

Page 9: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λλλ

DBMS

λ λλ λ

λλ λ

λ

λ

Queue

Page 10: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λλλ

DBMS

λ λλ λ

λλ λ

λ

λ

Queue

Page 11: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 12: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

“ ”

“ ”

“ ”“try/catch/finally ”

“ ”

“ ”

Page 13: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 14: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λ λλ

λλ

λ

λ

Page 15: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λλ

λ

λλλ

λ

Page 16: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λλλ

λ

λλ

λ

Page 17: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

λ

λ

λ

λ λλ

λ

Page 18: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

• • state • / • • ( )

Page 19: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

AWS Step Functions

Page 20: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

“ ”

AWS Step Functions,

. AWS Step Functions ..

Mathias Nitzsche, CTO

Page 21: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 22: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 23: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

var Twitter = require(‘twitter'); var client = new Twitter({ consumer_key: process.env.TWITTER_CONSUMER_KEY, consumer_secret: process.env.TWITTER_CONSUMER_SECRET, access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY, access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET });

exports.handler = (event, context, callback) => { var list = event.inputList; var textToTweet = list.shift(); var output = { inputList: list }; client.post('statuses/update', {status: textToTweet}, function(err, reply) { if (err) { console.log('error', err); context.fail(); } else { console.log('tweet', reply); callback(null, output); } }); };

Page 24: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

(Demo)

Page 25: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

– API-levelCreate State Machine – JSON DSL Run Machine – JSON blob , Execution ID . List Executions Describe Execution Stop Execution

Page 26: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

https://states-language.net/spec.html

Page 27: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 28: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

7 State Types

Task

Choice

Parallel

Wait

Fail

Succeed

Pass

Page 29: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

“ ”

AWS Step Function .

AWS .

Jared Browarnik, CTO, TheTake

Page 30: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 31: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

"ChoiceState": { "Type" : "Choice", "Choices": [ { "Variable": "$.productSource", "StringEquals": "screen-scrape", "Next": "ScreenScrapeState" },{ "Variable": "$.productSource", "StringEquals": "vendor-a", "Next": "VendorA" },{ "Variable": "$.productSource", "StringEquals": "vendor-b", "Next": "VendorB" },

{ "Variable": "$.productSource", "StringEquals": "vendor-c", "Next":"VendorC" },{ "Variable": "$.productSource", "StringEquals": "updateProduct", "Next":"UpdateProduct" } ], "Default": "ScreenScrapeState” }

Page 32: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

(Demo)

Page 33: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

“ ”

RESTful . 4~5

. , .

Page 34: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

{ "Comment": "Call out to a RESTful service", "StartAt": "Call out", "States": { "Call out": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:123456789012:function:RestCallout", "Retry": [ { "ErrorEquals": [ "HandledError" ], "MaxAttempts": 10 } ], "End": true } } }

Page 35: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

(Demo)

Page 36: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

“I want to run functions in parallel”

3 OCR

.“

Page 37: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 38: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

"Send for OCR": { "Type": "Parallel", "Next": "Pick result", "Branches": [ { "StartAt": "Prep1", "States": { "Prep1": { "Type": "Pass", "Result": { "inputList": [ "OCR Provider 1" ] }, "Next": "Go1" }, "Go1": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:123456789012:function:StatesBot", "End": true } }

Page 39: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

(Demo)

Page 40: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

?

, JSON .A:

Q:

Page 41: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

Input processing{ "title": "Numbers to add", "numbers": [ 3, 4 ] }

{ "Type": "Task", "InputPath": "$.numbers", "Resource": "arn:aws:lambda…" …

[ 3, 4 ]

Raw input:

State spec:

Task input:

Page 42: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

Input processingQ: InputPath ? A: State raw .

Q: InputPath null ? A: State JSON : {}

Q: InputPath ? A: State JSON .

Page 43: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

Result placement{ "title": "Numbers to add", "numbers": [ 3, 4 ] }

{ "Type": "Task", "InputPath": "$.numbers", "ResultPath": "$.sum”, …

Raw input:

State spec:

Output: { "title": "Numbers to add", "numbers": [ 3, 4 ], ”sum": 7 }

Page 44: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

Result placementQ: ResultPath ? A: , raw .

Q: ResultPath null ? A: State state .

Q: ResultPath ? A: . .

Page 45: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

“try/catch/finally ”

AWS Step Functions Platform as a Service

.

With AWS Step Functions, 60 %

.

Pedro Pimenta, VP R&D, OutSystems

Page 46: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

13 AWS Lambda Task States

6 Choice States

1 Fail State

“try/catch/finally ”

Page 47: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 48: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

"Access Media": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:123456789012:function:FindMedia", "TimeoutSeconds": 2, "Next": "Graceful Exit", "Retry": [ { "ErrorEquals": [ "States.Timeout" ], "IntervalSeconds": 2, "MaxAttempts": 2, "BackoffRate": 1.5 } ], "Catch": [ { "ErrorEquals": [ "States.ALL" ], "Next": "Clean Up" } ] },

Page 49: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

(Demo)

Page 50: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

“ ”

8 .“

Page 51: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

APIs Register Activity Task - Returns ARN Poll For task (by ARN) Report Success Report Failure Report Heartbeat

(Inside the Activity)

Page 52: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

"NextShift": { "Type": "Wait", "TimestampPath": "$.ShiftStart", "Next": "Gather Plant Data" }, "Gather Plant Data": { "Type": "Task", "Resource": "arn:aws:states:ap-northeast-1:123456789012:activity:PlWatch", "TimeoutSeconds": 30000, "HeartBeatSeconds": 120, "Next": "Clean up" }

Page 53: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

“ ”

“ ”

“ ”“try/catch/finally ”

?

“ ”

“ ”

Page 54: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
Page 55: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

2.5¢

?

1,000 0.025 USD

4,000 /

:

Page 56: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

AWS Step Functions ?

Region Region Code

US East (N. Virginia) us-east-1

US East (Ohio) us-east-2

US West (Oregon) us-west-2

EU (Dublin) eu-west-1

Asia Pacific (Tokyo) ap-northeast-1

Page 57: AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)

• SVR201: Serverless Apps with AWS Step Functions - https://www.youtube.com/watch?v=75MRve4nv8s

• CMP319: Building Distributed Applications with AWS Step Functions - https://www.youtube.com/watch?v=-qCFLXY1xa8

• Announcing AWS Step Functions - December 2016 Monthly Webinar Series - https://www.youtube.com/watch?v=vi0q9bODbTE