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

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

Embed Size (px)

Citation preview

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

, 4CSoft

2017.01.21

AWS Step Functions AWSKRUG re:Invent

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

• AWS : EC2, S3, Route53 … Lambda

re:Invent 2016

re:Invent 2016

λ

λλλ

λλλ

λ λλ λ

λλ λ

λ

λ

λλλ

λ λλ λ

λλ λ

λ

λ

Queue

λλλ

DBMS

λ λλ λ

λλ λ

λ

λ

Queue

λλλ

DBMS

λ λλ λ

λλ λ

λ

λ

Queue

“ ”

“ ”

“ ”“try/catch/finally ”

“ ”

“ ”

λ λλ

λλ

λ

λ

λλ

λ

λλλ

λ

λλλ

λ

λλ

λ

λ

λ

λ

λ λλ

λ

• • state • / • • ( )

AWS Step Functions

“ ”

AWS Step Functions,

. AWS Step Functions ..

Mathias Nitzsche, CTO

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); } }); };

(Demo)

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

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

7 State Types

Task

Choice

Parallel

Wait

Fail

Succeed

Pass

“ ”

AWS Step Function .

AWS .

Jared Browarnik, CTO, TheTake

"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” }

(Demo)

“ ”

RESTful . 4~5

. , .

{ "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 } } }

(Demo)

“I want to run functions in parallel”

3 OCR

.“

"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 } }

(Demo)

?

, JSON .A:

Q:

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:

Input processingQ: InputPath ? A: State raw .

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

Q: InputPath ? A: State JSON .

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 }

Result placementQ: ResultPath ? A: , raw .

Q: ResultPath null ? A: State state .

Q: ResultPath ? A: . .

“try/catch/finally ”

AWS Step Functions Platform as a Service

.

With AWS Step Functions, 60 %

.

Pedro Pimenta, VP R&D, OutSystems

13 AWS Lambda Task States

6 Choice States

1 Fail State

“try/catch/finally ”

"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" } ] },

(Demo)

“ ”

8 .“

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

(Inside the Activity)

"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" }

“ ”

“ ”

“ ”“try/catch/finally ”

?

“ ”

“ ”

2.5¢

?

1,000 0.025 USD

4,000 /

:

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

• 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