{"id":614,"date":"2020-03-06T14:35:40","date_gmt":"2020-03-06T05:35:40","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/03\/06\/sls-step-functions"},"modified":"2020-03-06T14:35:40","modified_gmt":"2020-03-06T05:35:40","slug":"sls-step-functions","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/03\/06\/sls-step-functions\/","title":{"rendered":"Serverless Framework \u3067 Step Functions \u3092\u8a2d\u5b9a\u3059\u308b"},"content":{"rendered":"

\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5185\u5c71\u3067\u3059\u3002\u53c2\u52a0\u3059\u308b\u4e88\u5b9a\u3060\u3063\u305f\u30a4\u30d9\u30f3\u30c8\u304c\u3001\u30b3\u30ed\u30ca\u306e\u5f71\u97ff\u3067\u3053\u3068\u3054\u3068\u304f\u4e2d\u6b62\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u65e9\u304f\u7d42\u606f\u3059\u308b\u3068\u826f\u3044\u3067\u3059\u306d\u3002<\/p>\n

\u4eca\u56de\u306f\u3001Serverless Framework\u3092\u4f7f\u7528\u3057\u3066\u3001Step Functions\u306e\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n

\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4ee5\u4e0b\u306b\u7f6e\u3044\u3066\u3042\u308a\u307e\u3059\u3002
\nhttps:\/\/github.com\/memememomo\/sls-step-functions-sample<\/a><\/p>\n

Docker\u3068Serverless Framework\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u524d\u63d0\u3067\u3059\u3002<\/p>\n

Docker
\n
https:\/\/www.docker.com\/<\/a><\/p>\n

Serverless Framework
\n
https:\/\/serverless.com\/<\/a><\/p>\n

\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4f5c\u6210<\/h2>\n

\u307e\u305a\u306f\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u7528\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n

$ mkdir sls-step-functions-sample\n$ cd sls-step-functions-sample<\/code><\/pre>\n

Docker\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u4f5c\u6210\u3068\u521d\u671f\u5316<\/h2>\n

Serverless Framework\u3092Docker\u3067\u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n

version: '3'\nservices:\n  sls:\n    build:\n      context: .\/\n      dockerfile: Dockerfile\n    volumes:\n      - .:\/opt\/app\n    env_file:\n      - aws-credentials<\/code><\/pre>\n
FROM amaysim\/serverless:1.60.0\nWORKDIR \/opt\/app\nCOPY . \/opt\/app\/<\/code><\/pre>\n

\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u305f\u3089\u3001 docker-compose\u30b3\u30de\u30f3\u30c9\u3067\u30d3\u30eb\u30c9\u3057\u307e\u3059\u3002<\/p>\n

$ docker-compose build<\/code><\/pre>\n

ServerlessFramework\u306e\u521d\u671f\u5316<\/h2>\n

Docker\u30b3\u30f3\u30c6\u30ca
\n\u4e0a\u3067\u3001ServerlessFramework\u306e\u521d\u671f\u5316\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n

$ docker-compose run sls sls create -t aws-nodejs\n$ docker-compose run sls npm init -y<\/code><\/pre>\n

ServerlessFramework\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n

Step Functions\u306e\u8a2d\u5b9a\u3092\u3059\u308b\u305f\u3081\u306b\u3001\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u5fc5\u8981\u306a\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n

$ docker-compose run sls npm install -D serverless-pseudo-parameters\n$ docker-compose run sls npm install -D serverless-step-functions<\/code><\/pre>\n

Step Functions\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u4ed6\u306b\u3001\u7591\u4f3c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\u3082\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u306b\u3088\u308a\u3001 #{AWS::AccountId}<\/code> \u3084 #{AWS::Region}<\/code> \u306a\u3069\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u304c\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u4e0a\u3067\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

\u3053\u308c\u3089\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u6709\u52b9\u306b\u3059\u308b\u305f\u3081\u3001Serverless Framework\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u8a18\u3057\u307e\u3059\u3002<\/p>\n

plugins:\n  - serverless-step-functions\n  - serverless-pseudo-parameters<\/code><\/pre>\n

\u30b5\u30f3\u30d7\u30eb\u7528\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210<\/h2>\n

\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001hello<\/code> \u3068 world<\/code> \u3092\u305d\u308c\u305e\u308c\u8fd4\u3059\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n

'use strict';\n\nmodule.exports.hello = async event => {\n  return {\n    statusCode: 200,\n    body: JSON.stringify(\n      {\n        message: 'Hello',\n      },\n      null,\n      2\n    ),\n  };\n};\n\nmodule.exports.world = async event => {\n    return {\n        statusCode: 200,\n        body: JSON.stringify(\n            {\n                message: 'World',\n            },\n            null,\n            2\n        ),\n    }\n};<\/code><\/pre>\n

\u3053\u308c\u3089\u306eLambda\u95a2\u6570\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306b\u3001Serverless Framework\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u8a18\u3057\u307e\u3059\u3002<\/p>\n

functions:\n  hello:\n    name: hello\n    handler: handler.hello\n  world:\n    name: world\n    handler: handler.world<\/code><\/pre>\n

Step Functions\u306e\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306e\u8a2d\u5b9a<\/h2>\n

Step Functions\u306e\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u306f\u6b63\u5f0f\u306b\u306fJSON\u3067\u5b9a\u7fa9\u3059\u308b\u306e\u3067\u3059\u304c\u3001Serverless Framework\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u306fYAML\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n

stepFunctions:\n  stateMachines:\n    HelloWorld:\n      name: hello-world\n      definition:\n        StartAt: Hello\n        States:\n          Hello:\n            Type: Task\n            Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello\n            Next: World\n          World:\n            Type: Task\n            Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:world\n            End: true<\/code><\/pre>\n

hello\u3068world\u3092\u9806\u756a\u306b\u5b9f\u884c\u3059\u308b\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

\"\"<\/p>\n

\u30c7\u30d7\u30ed\u30a4\u3068\u5b9f\u884c<\/h2>\n

\u4ee5\u4e0a\u3067\u3001\u3072\u3068\u3068\u304a\u308a\u306e\u8a2d\u5b9a\u304c\u7d42\u308f\u3063\u305f\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30c7\u30d7\u30ed\u30a4\u3057\u307e\u3059\u3002<\/p>\n

$ docker-compose run sls sls deploy<\/code><\/pre>\n

\u30b3\u30de\u30f3\u30c9\u306e\u5b9f\u884c\u304c\u7d42\u308f\u308b\u3068\u3001AWS\u4e0a\u306eStep Functions\u306e\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u300c\u5b9f\u884c\u306e\u958b\u59cb\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u5b9f\u884c\u3059\u308b\u3068\u3001\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u304c\u6b63\u5e38\u306b\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n

\"\"<\/p>\n

\u4ee5\u4e0a\u304c\u3001Step Functions\u306e\u8a2d\u5b9a\u306e\u6d41\u308c\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n

\u304a\u308f\u308a\u306b<\/h2>\n

Serverless Framework\u3067\u3001Step Functions\u306e\u8a2d\u5b9a\u3092\u884c\u3046\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002\u3068\u3063\u304b\u304b\u308a\u3068\u3057\u3066\u3001\u53c2\u8003\u306b\u3057\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5185\u5c71\u3067\u3059\u3002\u53c2\u52a0\u3059\u308b\u4e88\u5b9a\u3060\u3063\u305f\u30a4\u30d9\u30f3\u30c8\u304c\u3001\u30b3\u30ed\u30ca\u306e\u5f71\u97ff\u3067\u3053\u3068\u3054\u3068\u304f\u4e2d\u6b62\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u65e9\u304f\u7d42\u606f\u3059\u308b\u3068\u826f\u3044\u3067\u3059\u306d\u3002 \u4eca\u56de\u306f\u3001Serverless Framework\u3092\u4f7f\u7528\u3057\u3066\u3001Step Functions\u306e\u30b9\u30c6\u30fc\u30c8\u30de\u30b7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002 \u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4ee5\u4e0b\u306b\u7f6e\u3044\u3066\u3042\u308a\u307e\u3059\u3002 https:\/\/github.com\/memememomo\/sls-step-functi […]<\/p>\n","protected":false},"author":5,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,21],"tags":[136,339],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/614"}],"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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=614"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/614\/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=614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}