{"id":417,"date":"2017-11-11T10:11:38","date_gmt":"2017-11-11T01:11:38","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2017\/11\/11\/aws_step_functions"},"modified":"2017-11-11T10:11:38","modified_gmt":"2017-11-11T01:11:38","slug":"aws_step_functions","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2017\/11\/11\/aws_step_functions\/","title":{"rendered":"AWS Step Functions \u3092\u89e6\u3063\u3066\u307f\u305f"},"content":{"rendered":"
\u5148\u65e5\u3001Serverlessconf Tokyo 2017<\/a>\u306b\u53c2\u52a0\u3057\u3066\u3001\u3044\u308d\u3044\u308d\u306a\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u8a71\u3092\u805e\u304d\u3001 AWS Step Functions<\/a> \u3092\u4f7f\u3063\u3066\u8907\u6570\u306e AWS Lambda<\/a> \u3092\u7ba1\u7406\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u8a71\u304c\u3044\u308d\u3044\u308d\u3068\u4fbf\u5229\u305d\u3046\u3060\u3063\u305f\u306e\u3067\u3001\u89e6\u3063\u3066\u307f\u305f\u3002<\/p>\n Step Functions \u3092\u4f7f\u3046\u3068\u3001Lambda \u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4e00\u9023\u306e\u30b9\u30c6\u30c3\u30d7\u3068\u3057\u3066\u8996\u899a\u7684\u306b\u5b9a\u7fa9\u3057\u3001\u8907\u6570\u306e Lambda \u3092\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u3068\u3057\u3066\u7ba1\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u306e\u3053\u3068\u3002<\/p>\n \u3055\u3063\u305d\u304f\u3084\u3063\u3066\u307f\u305f\u3002<\/p>\n \u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u306e \u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b\u3002\u3068\u308a\u3042\u3048\u305a\u3001\u5b9a\u756a\u306e Lambda \u306e\u7d50\u679c\u306b\u3088\u308b\u5206\u5c90\u30b9\u30c6\u30c3\u30d7\u3092\u8a66\u3057\u3066\u307f\u305f\u304b\u3063\u305f\u306e\u3067\u3001 \u3082\u306e\u3059\u3054\u304f\u7c21\u5358\u306a Lambda \u3092\u3044\u304f\u3064\u304b\u4f5c\u3063\u3066\u307f\u3066\u3001 \u4e0b\u8a18\u306e JSON \u3092\u5165\u529b\u3057\u3066\u3001<\/p>\n \u3061\u3083\u3093\u3068\u53cd\u6620\u3055\u308c\u305f\u3002<\/p>\n \u3061\u306a\u307f\u306b\u3001\u4f5c\u3063\u305f Lambda \u306f\u4e0b\u8a18\u306e\u3068\u304a\u308a\u3002<\/p>\n \u3010hello.py\u3011<\/p>\n \u3010how_are_you.py\u3011<\/p>\n \u3010response_good.py\u3011 \u3010response_bad.py\u3011 \u3010bye.py\u3011<\/p>\n \u305d\u308c\u305e\u308c\u3001\u56fa\u5b9a\u306e\u6587\u5b57\u5217\u3092\u8fd4\u3059\u3060\u3051\u3002<\/p>\n \u3053\u308c\u3060\u3051\u3067\u3001\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u304c\u4f5c\u308c\u3066\u3057\u307e\u3063\u305f\u3002<\/p>\n<\/p>\n
\u30b9\u30c6\u30c3\u30d7 1: \u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b<\/h2>\n
\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306e\u4f5c\u6210<\/code> \u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n
<\/p>\n
Helloworld<\/code> \u3067\u3002<\/p>\n
\u30b9\u30c6\u30c3\u30d7 2: \u8a2d\u8a08\u56f3\u3092\u9078\u629e\u3059\u308b<\/h2>\n
Choice \u30b9\u30c6\u30fc\u30c8<\/code> \u3092\u9078\u629e\u3002<\/p>\n
<\/p>\n
\u30b9\u30c6\u30c3\u30d7 3: \u30b3\u30fc\u30c9\u3068\u30d3\u30b8\u30e5\u30a2\u30eb\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u3092\u78ba\u8a8d\u3059\u308b<\/h2>\n
\u30b3\u30fc\u30c9<\/code> \u306e\u90e8\u5206\u306b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3068\u3057\u3066\u6e96\u5099\u3055\u308c\u3066\u3044\u308b JSON \u3092\u30d9\u30fc\u30b9\u306b\u3001\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u3068\u3057\u3066\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n
{\n "Comment": "test",\n "StartAt": "hello",\n "States": {\n "hello": {\n "Type": "Task",\n "Resource": "arn:aws:lambda:ap-northeast-1:123456789012:function:hello",\n "Next": "how are you"\n },\n "how are you": {\n "Type": "Task",\n "Resource": "arn:aws:lambda:ap-northeast-1:123456789012:function:how_are_you",\n "Next": "ChoiceState"\n },\n "ChoiceState": {\n "Type" : "Choice",\n "Choices": [\n {\n "Variable": "$.response",\n "StringEquals": "Great",\n "Next": "response_good"\n },\n {\n "Variable": "$.response",\n "StringEquals": "Not so good",\n "Next": "response_bad"\n }\n ],\n "Default": "DefaultState"\n },\n "response_good": {\n "Type" : "Task",\n "Resource": "arn:aws:lambda:ap-northeast-1:123456789012:function:response_good",\n "Next": "bye"\n },\n "response_bad": {\n "Type" : "Task",\n "Resource": "arn:aws:lambda:ap-northeast-1:123456789012:function:response_bad",\n "Next": "bye"\n },\n "DefaultState": {\n "Type": "Fail",\n "Error": "DefaultStateError",\n "Cause": "No Matches!"\n },\n "bye": {\n "Type": "Task",\n "Resource": "arn:aws:lambda:ap-northeast-1:123456789012:function:bye",\n "End": true\n }\n }\n}\n<\/code><\/pre>\n
\u30d3\u30b8\u30e5\u30a2\u30eb\u30ef\u30fc\u30af\u30d5\u30ed\u30fc<\/code> \u306e\u53f3\u5074\u306b\u3042\u308b\u30ea\u30ed\u30fc\u30c9\u30a2\u30a4\u30b3\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u3001 \u30b0\u30e9\u30d5\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u3092\u66f4\u65b0\u3059\u308b\u3068\u3001<\/p>\n
<\/p>\n
event<\/code> \u306e
name<\/code> \u3092\u53d7\u3051\u53d6\u308a\u3001
hello, <name><\/code> \u3068\u8868\u793a\u3057\u3066\u3001\u305d\u306e\u307e\u307e
name<\/code> \u3092\u8fd4\u3059\u3002<\/p>\n
# hello.py\ndef lambda_handler(event, context):\n print "hello, %s" % event[u'name']\n return {u'name': event[u'name']}<\/code><\/pre>\n
event<\/code> \u306e
name<\/code> \u3092\u53d7\u3051\u53d6\u3063\u3066\u3001
Bob<\/code> \u3060\u3063\u305f\u3089\u3001
name<\/code> \u3068\u3001
response<\/code> \u3068\u3057\u3066
Great<\/code> \u3092\u8fd4\u3059\u3002
event<\/code> \u306e
name<\/code> \u3092\u53d7\u3051\u53d6\u3063\u3066\u3001
Bob<\/code> \u4ee5\u5916\u3060\u3063\u305f\u3089\u3001
name<\/code> \u3068\u3001
response<\/code> \u3068\u3057\u3066
Not so good<\/code> \u3092\u8fd4\u3059\u3002<\/p>\n
# how_are_you.py\ndef lambda_handler(event, context):\n if event[u'name'] == 'Bob':\n return {u'name': event[u'name'], u'response': u'Great'}\n else:\n return {u'name': event[u'name'], u'response': u'Not so good'}<\/code><\/pre>\n
# response_good.py\ndef lambda_handler(event, context):\n return 'Good!'<\/code><\/pre>\n
# response_bad.py\ndef lambda_handler(event, context):\n return "What's wrong?"<\/code><\/pre>\n
# bye.py\ndef lambda_handler(event, context):\n return 'Bye!'<\/code><\/pre>\n
\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306e\u4f5c\u6210<\/code> \u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001
\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u5b9f\u884c\u306e IAM \u30ed\u30fc\u30eb<\/code> \u3092\u6307\u5b9a\u3059\u308b\u30c0\u30a4\u30a2\u30ed\u30b0\u304c\u51fa\u3066\u304f\u308b\u306e\u3067\u3001\u6307\u5b9a\u3057\u3066
OK<\/code> \u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3002
(\u30ed\u30fc\u30eb\u304c\u306a\u3044\u5834\u5408\u306f\u3053\u3053\u3067\u4f5c\u6210)<\/p>\n<\/p>\n
\u30b3\u30fc\u30c9\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n