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

\"\"<\/p>\n

\u3055\u3063\u305d\u304f\u3084\u3063\u3066\u307f\u305f\u3002<\/p>\n

\u30b9\u30c6\u30c3\u30d7 1: \u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b<\/h2>\n

\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u306e \u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306e\u4f5c\u6210<\/code> \u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n

\"\"<\/p>\n

\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b\u3002\u3068\u308a\u3042\u3048\u305a\u3001\u5b9a\u756a\u306e Helloworld<\/code> \u3067\u3002<\/p>\n

\u30b9\u30c6\u30c3\u30d7 2: \u8a2d\u8a08\u56f3\u3092\u9078\u629e\u3059\u308b<\/h2>\n

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

\u3082\u306e\u3059\u3054\u304f\u7c21\u5358\u306a Lambda \u3092\u3044\u304f\u3064\u304b\u4f5c\u3063\u3066\u307f\u3066\u3001 \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

\u4e0b\u8a18\u306e JSON \u3092\u5165\u529b\u3057\u3066\u3001<\/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

\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

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

\u3010how_are_you.py\u3011<\/p>\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

\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

# 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

\u3053\u308c\u3060\u3051\u3067\u3001\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u304c\u4f5c\u308c\u3066\u3057\u307e\u3063\u305f\u3002<\/p>\n

\u30b3\u30fc\u30c9\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n

\u30b3\u30fc\u30c9<\/code> \u306e\u90e8\u5206\u306b\u5165\u529b\u3059\u308bJSON\u306f\u3001 JSON \u30d9\u30fc\u30b9\u306e Amazon \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u8a00\u8a9e (ASL)<\/a> \u3067\u8a18\u8ff0\u3059\u308b\u3002 <\/p>\n

Type<\/h3>\n

Type<\/code> \u3068\u3057\u3066\u8a2d\u5b9a\u3067\u304d\u308b\u306e\u306f\u3001 Pass<\/code> Task<\/code> Choice<\/code> Wait<\/code> Succeed<\/code> Fail<\/code> Parallel<\/code> \u304c\u3042\u308a\u3001<\/p>\n

\"\"<\/p>\n

\u30d5\u30a3\u30fc\u30eb\u30c9\u3068\u3057\u3066\u306f\u4e0a\u8a18\u306e\u8868\u306e\u3068\u304a\u308a\u3001\u8a2d\u5b9a\u304c\u3067\u304d\u308b\u3002
\u4eca\u56de\u306f\u4e3b\u306b\u3001 Task<\/code> \u3068 Choice<\/code> \u3092\u4f7f\u7528\u3057\u305f\u3002<\/p>\n

Task<\/h3>\n

Task<\/code> \u306b\u306f\u3001 Next<\/code> \u3082\u3057\u304f\u306f "End": true<\/code> \u304c\u5fc5\u8981\u3067\u3001 Next<\/code> \u3067\u6307\u5b9a\u3057\u305f\u6587\u5b57\u5217\u306e\u30bf\u30b9\u30af\u304c\u6b21\u306b\u5b9f\u884c\u3055\u308c\u308b\u3002
Resource<\/code> \u306b\u306f\u3001 Lambda \u306e ARN \u306a\u3069\u3092\u6307\u5b9a\u3059\u308b\u3002<\/p>\n

"hello": {\n  "Type": "Task",\n  "Resource": "arn:aws:lambda:ap-northeast-1:123456789012:function:hello",\n  "Next": "how are you"\n},<\/code><\/pre>\n

ChoiceState<\/h3>\n

ChoiceState<\/code> \u3068\u3057\u3066\u306f\u3001 StringEquals<\/code> \u3084 BooleanEquals<\/code> \u3084 TimestampGreaterThan<\/code> \u306a\u3069\u306e\u6761\u4ef6\u3092\u8a2d\u5b9a\u3067\u304d\u308b\u3002 <\/p>\n

\u4eca\u56de\u306e JSON \u306e ChoiceState<\/code> \u306e\u90e8\u5206\u3067\u306f\u3001 Variable<\/code> \u3067 $.response<\/code> \u3092\u898b\u3066\u3001 StringEquals<\/code> \u3067\u6307\u5b9a\u3057\u305f\u6587\u5b57\u5217\u3068\u4e00\u81f4\u3059\u308b\u304b\u306e\u5224\u5225\u3092\u3057\u3066\u3044\u308b\u3002<\/p>\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},<\/code><\/pre>\n

Variable<\/code> \u3068\u3057\u3066\u3001 $<\/code> \u3067\u7d50\u679c\u3092\u53d7\u3051\u53d6\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002
\u4f8b\u3048\u3070\u3001JSON \u304c\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u7d50\u679c\u3068\u3057\u3066\u6e21\u3063\u3066\u304d\u305f\u3089\u3001<\/p>\n

{\n    "foo": 123,\n    "bar": ["a", "b", "c"],\n    "car": {\n        "cdr": true\n    }\n}<\/code><\/pre>\n

\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5f62\u3067\u3001\u5024\u304c\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n

$.foo => 123\n$.bar => ["a", "b", "c"]\n$.car.cdr => true<\/code><\/pre>\n

\u5b9f\u969b\u306b\u5b9f\u884c\u3057\u3066\u307f\u308b<\/h2>\n

\"\"<\/p>\n

\u65b0\u3057\u3044\u5b9f\u884c<\/code> \u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u3001 \u5b9f\u884c ID<\/code> \u306b Bob<\/code> \u3092\u5165\u308c\u3001 event<\/code> \u3068\u3057\u3066\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3001 \u5b9f\u884c\u306e\u958b\u59cb<\/code> \u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n

{\n    "name": "Bob"\n}<\/code><\/pre>\n

\"\"<\/p>\n

\u7121\u4e8b\u3001\u5b9f\u884c\u3055\u308c\u305f\u3002
Bob<\/code> \u306a\u306e\u3067\u3001 response_good<\/code> \u306e\u65b9\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u306e\u304c\u5206\u304b\u308b\u3002 <\/p>\n

\u4eca\u5ea6\u306f\u3001 name<\/code> \u306b Tom<\/code> \u3092\u5165\u308c\u3066\u5b9f\u884c\u3057\u3066\u307f\u305f\u3089\u3001\u60f3\u5b9a\u3069\u304a\u308a response_bad<\/code> \u306e\u65b9\u304c\u5b9f\u884c\u3055\u308c\u3001\u3061\u3083\u3093\u3068\u5206\u5c90\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u305f\u3002<\/p>\n

\"\"<\/p>\n

\u6599\u91d1<\/h2>\n

AWS Step Functions \u306e\u6599\u91d1\u3068\u3057\u3066\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u306e\u3042\u308b\u30b9\u30c6\u30c3\u30d7\u304b\u3089\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u306b\u79fb\u884c\u3059\u308b\u3068\u3001\u72b6\u614b\u9593\u3092\u9077\u79fb\u3057\u305f\u3053\u3068\u306b\u306a\u308a\u3001 \u5404\u72b6\u614b\u9077\u79fb\u306b\u5bfe\u3057\u3066\u6599\u91d1\u304c\u767a\u751f\u3059\u308b<\/strong>\u3002
\u6bce\u6708 4,000 \u56de\u307e\u3067\u306e\u72b6\u614b\u9077\u79fb\u306f\u7121\u6599\u3067\u3001\u305d\u308c\u4ee5\u964d\u306f\u3001\u72b6\u614b\u9077\u79fb 1,000 \u56de\u3042\u305f\u308a 0.025 USD (\u72b6\u614b\u9077\u79fb 1 \u56de\u3042\u305f\u308a 0.000025 USD)\u3068\u306a\u3063\u3066\u3044\u308b\u3002 <\/p>\n

\u3010\u53c2\u8003\u3011
\n\u6599\u91d1 - AWS Step Functions | AWS<\/a><\/p>\n

\u307e\u3068\u3081<\/h2>\n

\u4eca\u56de AWS Step Functions \u3092\u521d\u3081\u3066\u89e6\u3063\u3066\u307f\u305f\u304c\u3001\u6bd4\u8f03\u7684\u7c21\u5358\u306b\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u304c\u4f5c\u308c\u3066\u3001Lambda \u304c\u7ba1\u7406\u3067\u304d\u308b\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3002
Lambda \u306e\u5236\u9650\u3068\u3057\u3066\u3001\u5b9f\u884c\u6642\u9593\u304c5\u5206\u307e\u3067\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308b\u306e\u3067\u3001\u7d30\u304b\u3044\u6a5f\u80fd\u3067\u8907\u6570\u306e Lambda \u306b\u5206\u5272\u3059\u308b\u30b1\u30fc\u30b9\u304c\u3088\u304f\u3042\u308b\u3068\u601d\u3046\u3002\u305d\u3046\u3044\u3063\u305f\u5834\u5408\u306b\u3001 AWS Step Functions \u3092\u3046\u307e\u304f\u6d3b\u7528\u3057\u3066\u3084\u308c\u3070\u7ba1\u7406\u304c\u697d\u306b\u306a\u308a\u305d\u3046\u306a\u306e\u3067\u3001\u793e\u5185\u3067\u3082\u7a4d\u6975\u7684\u306b\u4f7f\u3063\u3066\u3044\u304d\u305f\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5148\u65e5\u3001Serverlessconf Tokyo 2017\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 \u3092\u4f7f\u3063\u3066\u8907\u6570\u306e AWS Lambda \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 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 […]<\/p>\n","protected":false},"author":3,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,21,9,17],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/417"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=417"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/417\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}