{"id":564,"date":"2019-07-31T10:14:39","date_gmt":"2019-07-31T01:14:39","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/07\/31\/step_functions_local"},"modified":"2019-07-31T10:14:39","modified_gmt":"2019-07-31T01:14:39","slug":"step_functions_local","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/07\/31\/step_functions_local\/","title":{"rendered":"Docker \u3067 Step Functions Local \u306e\u5b9f\u884c\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b"},"content":{"rendered":"
\u6700\u8fd1\u3001\u8eca\u3092\u8cfc\u5165\u3057\u305f\u306e\u3067\u3001\u8272\u3005\u306a\u3068\u3053\u308d\u306b\u9060\u51fa\u3092\u3057\u3066\u3044\u307e\u3059\u3002\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5185\u5c71\u3067\u3059\u3002<\/p>\n
\u4eca\u56de\u306f\u3001Step Functions \u3092\u30ed\u30fc\u30ab\u30ebPC\u5185\u3067\u5b9f\u884c\u3059\u308b\u74b0\u5883\u306e\u69cb\u7bc9\u306b\u3064\u3044\u3066\u3001\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n
Step Functions \u306f\u3001\u8907\u6570\u306e Lambda \u95a2\u6570\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u6a5f\u80fd\u3092\u5b9f\u88c5\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002
\n\u30eb\u30fc\u30d7\u3084\u5206\u5c90\u306a\u3069\u306e\u30ed\u30b8\u30c3\u30af\u3092\u7d44\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\n\u30ed\u30b8\u30c3\u30af\u304c\u8907\u96d1\u306b\u306a\u3063\u3066\u304f\u308b\u3068\u3001\u30ed\u30fc\u30ab\u30ebPC\u3067\u52d5\u4f5c\u78ba\u8a8d\u3057\u305f\u3044\u3068\u601d\u3046\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n
\u30ed\u30fc\u30ab\u30ebPC\u3067\u52d5\u4f5c\u3055\u305b\u308b\u305f\u3081\u306b Step Functions Local \u3068\u3044\u3046\u30c4\u30fc\u30eb\u304c\u516c\u5f0f\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002
\n\u4eca\u56de\u306f\u3001Docker \u3068 Step Functions Local \u3092\u7528\u3044\u3066\u3001\u52d5\u4f5c\u30c1\u30a7\u30c3\u30af\u74b0\u5883\u3092\u30ed\u30fc\u30ab\u30ebPC(Mac)\u4e0a\u306b\u69cb\u7bc9\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n
\u3055\u3063\u3055\u3068\u8a66\u3057\u305f\u3044\u65b9\u306f\u4ee5\u4e0b\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<\/p>\n
https:\/\/github.com\/memememomo\/step-functions-local-test<\/a><\/p>\n <\/p>\n \u4e0a\u8a18\u306e\u3088\u3046\u306a\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u307e\u3059\u3002\u8a2d\u5b9a\u3059\u308b\u30b3\u30f3\u30c6\u30ca\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u4e8c\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n SAM Local \u306f\u3001\u30ed\u30fc\u30ab\u30ebPC\u4e0a\u3067 Lambda \u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u30c4\u30fc\u30eb\u3067\u3059\u3002Lambda \u95a2\u6570\u306e\u5b9f\u884c\u6642\u306b\u306f\u3001\u5b9f\u884c\u7528\u306e\u30b3\u30f3\u30c6\u30ca\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u6ce8\u610f\u70b9\u3068\u3057\u3066\u3001Docker Compose \u3067\u4f5c\u6210\u3057\u305f\u30cd\u30c3\u30c8\u30ef\u30fc\u30af(net)\u3092\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b<\/strong> \u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u3053\u306e\u3053\u3068\u306b\u3064\u3044\u3066\u306f\u5f8c\u8ff0\u3057\u307e\u3059\u3002<\/p>\n \u307e\u305f\u3001\u56f3\u306b\u306f\u542b\u3081\u3066\u3044\u307e\u305b\u3093\u304c\u3001Go\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30d3\u30eb\u30c9\u3059\u308b\u7528\u306e\u30b3\u30f3\u30c6\u30ca\u3082\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n \u5404\u30b3\u30f3\u30c6\u30ca\u7528\u306e Dockerfile \u3092\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n SAM Local \u7528\u306e\u30b3\u30f3\u30c6\u30ca\u3067\u306f\u3001Python \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u30a4\u30e1\u30fc\u30b8\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002 Step Functions Local \u7528\u306e\u30b3\u30f3\u30c6\u30ca\u3067\u306f\u3001\u516c\u5f0f\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u30a4\u30e1\u30fc\u30b8\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n Go\u30d7\u30ed\u30b0\u30e9\u30e0\u30d3\u30eb\u30c9\u7528\u306e\u30b3\u30f3\u30c6\u30ca\u3067\u306f\u3001Go\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u30a4\u30e1\u30fc\u30b8\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002 Docker \u30b3\u30f3\u30c6\u30ca\u5185\u3067\u5b9f\u884c\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n SAM Local \u3067\u8aad\u307f\u8fbc\u307e\u305b\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8(template.yml)\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u69cb\u6210<\/h2>\n
\n
\u5404 Dockerfile \u306e\u8a2d\u5b9a<\/h2>\n
SAM Local \u7528\u306e Dockerfile<\/h3>\n
\nDockerfile \u3067\u306f\u3001SAM Local \u7528\u306e\u30b3\u30de\u30f3\u30c9(aws-sam-cli)\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n# Dockerfile_sam\nFROM python:3.5-alpine\n\nENV PYTHONUSERBASE=\/usr\/local\n\nRUN apk add --no-cache py-pip git bash gcc libc-dev && \n pip install --upgrade pip && \n pip install --user awscli==1.16.76 aws-sam-cli==0.9.0\n\nWORKDIR \/var\/opt\nCOPY . \/var\/opt\/\n\nEXPOSE 3001<\/code><\/pre>\n
Step Functions Local \u7528\u306e Dockerfile<\/h3>\n
# Dockerfile_stepfunctions\nFROM amazon\/aws-stepfunctions-local\n\nEXPOSE 8083<\/code><\/pre>\n
Go\u30d7\u30ed\u30b0\u30e9\u30e0\u30d3\u30eb\u30c9\u7528\u306e Dockerfile<\/h3>\n
\nDockerfile \u3067\u306f\u3001\u5fc5\u8981\u306a\u30c4\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n# Dockerfile_go\nFROM golang:1.11.5-alpine\n\nRUN apk add --no-cache git bash make curl gcc libc-dev openssl && \n go get -u github.com\/golang\/dep\/cmd\/dep\n\nWORKDIR \/go\/src\/step-functions-local-test\nCOPY . \/go\/src\/step-functions-local-test\n\nRUN dep ensure\nRUN cd .\/handlers\/helloworld\/ && CGO_ENABLED=0 GOOS=linux go build -v -installsuffix cgo -o main .<\/code><\/pre>\n
\u5404\u7a2e\u30b9\u30af\u30ea\u30d7\u30c8<\/h2>\n
Go\u30d7\u30ed\u30b0\u30e9\u30e0\u30d3\u30eb\u30c9\u30b9\u30af\u30ea\u30d7\u30c8<\/h3>\n
go-build.sh<\/code> \u3068\u3044\u3046\u540d\u524d\u3067\u3001Go\u30d7\u30ed\u30b0\u30e9\u30e0\u30d3\u30eb\u30c9\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\n\u5185\u5bb9\u3068\u3057\u3066\u306f\u3001\u4f9d\u5b58\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u30b3\u30f3\u30d1\u30a4\u30eb\u30b3\u30de\u30f3\u30c9\u306e\u5b9f\u884c\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n#!\/usr\/bin\/env bash\n\ndep ensure\ncd .\/handlers\/helloworld\/ && CGO_ENABLED=0 GOOS=linux go build -v -installsuffix cgo -o main .<\/code><\/pre>\n
SAM Local \u8d77\u52d5\u30b9\u30af\u30ea\u30d7\u30c8<\/h3>\n
start-lambda.sh<\/code> \u3068\u3044\u3046\u540d\u524d\u3067\u3001SAM Local \u3092\u8d77\u52d5\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\n\u5148\u8ff0\u3057\u305f\u3068\u304a\u308a\u3001Lambda\u95a2\u6570\u5b9f\u884c\u7528\u30b3\u30f3\u30c6\u30ca\u306bDocker\u306e\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3092\u8a2d\u5b9a\u3059\u308b<\/strong> \u3088\u3046\u306b\u3057\u307e\u3059\u3002\u3053\u308c\u304c\u884c\u308f\u308c\u3066\u3044\u306a\u3044\u3068\u3001SAM Local\u306eLambda\u304b\u3089\u4ed6\u306e\u30b3\u30f3\u30c6\u30ca(DynamoDB Local\u306a\u3069)\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002
\n--docker-network<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3001Docker\u306e\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
#!\/bin\/bash\n\nsam local start-lambda \n --docker-volume-basedir "${VOLUME}" \n --docker-network step-functions-local-test_net \n --host 0.0.0.0 \n --template template.yml<\/code><\/pre>\n
Lambda\u95a2\u6570\u7528\u306e\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n
handlers\/helloworld\/main.go<\/code> \u3068\u3044\u3046\u540d\u524d\u306e\u30d5\u30a1\u30a4\u30eb\u3067\u3001Lambda\u95a2\u6570\u7528\u306eGo\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\n\u4eca\u56de\u306f\u3001"Hello World!"\u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u8fd4\u3059\u3060\u3051\u306eLambda\u95a2\u6570\u3092\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\npackage main\n\nimport "github.com\/aws\/aws-lambda-go\/lambda"\n\nfunc handler() (string, error) {\n return "Hello World!", nil\n}\n\nfunc main() {\n lambda.Start(handler)\n}<\/code><\/pre>\n
Gopkg.toml<\/code> \u3068\u3044\u3046\u540d\u524d\u306e\u30d5\u30a1\u30a4\u30eb\u3067\u3001\u4f9d\u5b58\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n
[prune]\n go-tests = true\n unused-packages = true\n\n[[constraint]]\n name = "github.com\/aws\/aws-lambda-go"\n version = "1.2.0"\n<\/code><\/pre>\n
SAM \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8(template.yml)\u306e\u8a2d\u5b9a<\/h2>\n
\n"HelloWorld"\u3068\u3044\u3046\u540d\u524d\u306eLambda\u95a2\u6570\u3092\u4f5c\u6210\u3057\u3001\u5148\u7a0b\u4f5c\u6210\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\nAWSTemplateFormatVersion: '2010-09-09'\nTransform: AWS::Serverless-2016-10-31\n\nGlobals:\n Function:\n Runtime: go1.x\n Timeout: 900\n\nResources:\n HelloWorld:\n Properties:\n CodeUri: .\/handlers\/helloworld\n FunctionName: HelloWorld\n Handler: main\n Type: AWS::Serverless::Function<\/code><\/pre>\n
Step Functions Local \u306e\u8a2d\u5b9a<\/h2>\n