aws step functions를 이용한 마이크로서비스 개발하기 - 김현민 (4csoft)
TRANSCRIPT
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
, 4CSoft
2017.01.21
AWS Step Functions AWSKRUG re:Invent
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); } }); };
– API-levelCreate State Machine – JSON DSL Run Machine – JSON blob , Execution ID . List Executions Describe Execution Stop Execution
"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” }
{ "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 } } }
"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 } }
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
“
"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" } ] },
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" }
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