{"id":456,"date":"2018-05-21T19:00:00","date_gmt":"2018-05-21T10:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2018\/05\/21\/localstack-lambda"},"modified":"2018-05-21T19:00:00","modified_gmt":"2018-05-21T10:00:00","slug":"localstack-lambda","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2018\/05\/21\/localstack-lambda\/","title":{"rendered":"LocalStack\u3067Lambda\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u30ed\u30fc\u30ab\u30eb\u3067\u52d5\u304b\u3059"},"content":{"rendered":"

MMM\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u67f3\u6cbc\u3067\u3059\u3002
\n\u6587\u9ce5\u304c\u63db\u7fbd\u671f\u306a\u306e\u3067\u90e8\u5c4b\u4e2d\u306b\u7fbd\u304c\u821e\u3063\u3066\u307e\u3059\u3002<\/p>\n

\u4eca\u56de\u306fAtlassian\u304c\u958b\u767a\u3057\u3066\u3044\u308bLocalStack\u3092\u4f7f\u3063\u3066\u3001Lambda\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u30ed\u30fc\u30ab\u30eb\u306b\u9589\u3058\u3066\u52d5\u304b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n

LocalStack\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/h1>\n

\u307e\u305a\u306f\u3001LocalStack<\/a>\u3092\u4f7f\u3063\u3066\u307f\u307e\u3059\u3002
\npip\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001
\ndocker\u30a4\u30e1\u30fc\u30b8\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u305d\u3061\u3089\u3092\u4f7f\u3063\u3066\u3044\u304d\u307e\u3059\u3002
\n\u4eca\u56de\u306f\u516c\u5f0f\u306edocker-compose.yml\u3092\u4f7f\u3063\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9f\u884c\u3057\u307e\u3057\u305f\u3002<\/p>\n

 $ wget https:\/\/raw.githubusercontent.com\/localstack\/localstack\/master\/docker-compose.yml\n $ docker-compose up -d<\/code><\/pre>\n

\u3057\u3070\u3089\u304f\u3059\u308b\u3068\u3053\u306e\u3088\u3046\u306b\u3001LocalStack\u306e\u30b3\u30f3\u30c6\u30ca\u304c\u4e0a\u304c\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n

$ docker ps  \nCONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                                                      NAMES\nca98225f6bba        localstack\/localstack   "\/usr\/bin\/supervisor\u2026"   13 minutes ago      Up 13 minutes       0.0.0.0:4567-4583->4567-4583\/tcp, 0.0.0.0:8080->8080\/tcp   sam_localstack_1<\/code><\/pre>\n

\u30dd\u30fc\u30c8\u304c\u7a7a\u304f\u306e\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n

$ netstat -an\nActive Internet connections (servers and established)\nProto Recv-Q Send-Q Local Address           Foreign Address         State  \ntcp6       0      0 :::8080                 :::*                    LISTEN  \ntcp6       0      0 :::4567                 :::*                    LISTEN  \ntcp6       0      0 :::4568                 :::*                    LISTEN  \ntcp6       0      0 :::4569                 :::*                    LISTEN  \ntcp6       0      0 :::4570                 :::*                    LISTEN  \ntcp6       0      0 :::4571                 :::*                    LISTEN  \ntcp6       0      0 :::4572                 :::*                    LISTEN  \ntcp6       0      0 :::4573                 :::*                    LISTEN  \ntcp6       0      0 :::4574                 :::*                    LISTEN  \ntcp6       0      0 :::4575                 :::*                    LISTEN  \ntcp6       0      0 :::4576                 :::*                    LISTEN  \ntcp6       0      0 :::4577                 :::*                    LISTEN  \ntcp6       0      0 :::4578                 :::*                    LISTEN  \ntcp6       0      0 :::4579                 :::*                    LISTEN  \ntcp6       0      0 :::4580                 :::*                    LISTEN  \ntcp6       0      0 :::4581                 :::*                    LISTEN  \ntcp6       0      0 :::4582                 :::*                    LISTEN  \ntcp6       0      0 :::4583                 :::*                    LISTEN\n\n(\u4ee5\u4e0b\u7565)<\/code><\/pre>\n

8080\u756a\u53ca\u30734567~4583\u304c\u7a7a\u304f\u3068\u601d\u3044\u307e\u3059\u3002
\n\u3053\u306e\u72b6\u614b\u3067 localhost:8080<\/code> \u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n

\"\"<\/p>\n

\u3053\u306e\u3088\u3046\u306b\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u3059\u3002<\/p>\n

8080\u756a\u4ee5\u5916\u306e\u30dd\u30fc\u30c8\u306f\u306a\u306b\u304b\u3068\u3044\u3046\u3068\u3001AWS\u306e\u5404\u30b5\u30fc\u30d3\u30b9\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002
\n
README<\/a>\u306b\u8aac\u660e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

\u4f8b\u3048\u3070\u3001S3\u3092\u5229\u7528\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002
\nREADME\u306b\u3088\u308c\u3070S3\u306e\u30dd\u30fc\u30c8\u306f4572\u306a\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d0\u30b1\u30c3\u30c8\u3068\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n

$ aws --endpoint-url=http:\/\/localhost:4572 s3api create-bucket --bucket sam_test\n$ echo "Hello world" > s3.txt\n$ aws --endpoint-url=http:\/\/localhost:4572 s3 cp .\/s3.txt s3:\/\/sam_test<\/code><\/pre>\n

\u3053\u308c\u3067\u5148\u7a0b\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u30ea\u30ed\u30fc\u30c9\u3057\u3066\u307f\u308b\u3068\u3001\u30d0\u30b1\u30c3\u30c8\u304c\u3067\u304d\u3066\u3044\u307e\u3059!!<\/p>\n

\"\"<\/p>\n

\u3053\u308c\u3060\u3051\u3067\u3082\u3001\u30ed\u30fc\u30ab\u30eb\u3067S3\u30d0\u30b1\u30c3\u30c8\u3092\u30e2\u30c3\u30af\u3067\u304d\u308b\u305f\u3081\u3001\u958b\u767a\u4e2d\u306b\u5b9f\u969b\u306eS3\u30d0\u30b1\u30c3\u30c8\u3092\u898b\u306b\u884c\u304f\u5fc5\u8981\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u3002\u4fbf\u5229\u3002<\/p>\n

\u4eca\u56de\u306f\u3001LocalStack\u4e0a\u306eLambda\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306b\u95a2\u6570\u3092\u4f5c\u6210\u3057\u3001\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n

Lambda\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u4f5c\u6210<\/h1>\n

\u305d\u308c\u3067\u306f\u3001Lambda\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u307e\u3059\u3002
\naws cli<\/code> \u306e lambda create-function<\/code> \u3059\u308c\u3070\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u666e\u901a\u306b\u4f5c\u3063\u305f\u3060\u3051\u3067\u306fLocalStack\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306b\u4f5c\u308c\u306a\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u4f5c\u308a\u65b9\u3092\u3057\u307e\u3059\u3002
\n\u307e\u305a\u306f\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3002<\/p>\n

$ vi lambda.py\n\ndef lambda_handler(event, context):  \n    print(event)  \n    return 'LocalStack TEST'<\/code><\/pre>\n

zip\u5316\u3057\u307e\u3059\u3002<\/p>\n

$ zip lambda.zip lambda.py<\/code><\/pre>\n

\u305d\u3057\u3066\u3001create-function\u3057\u307e\u3059\u3002<\/p>\n

$ aws --endpoint-url=http:\/\/localhost:4574 --region us-east-1 --profile localstack lambda create-function --function-name=f1 --runtime=python2.7 --role=r1 --handler=lambda.lambda_handler --zip-file fileb:\/\/lambda.zip<\/code><\/pre>\n

\u6700\u5927\u306e\u30dd\u30a4\u30f3\u30c8\u306f --endpoint-url=http:\/\/localhost:4574<\/code> \u3067\u3059\u3002\u3053\u308c\u3067LocalStack\u306b\u4f5c\u3063\u3066\u304f\u308c\u307e\u3059\u3002
\n\u3046\u307e\u304f\u3067\u304d\u308c\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n

{\n    "TracingConfig": {},\n    "FunctionName": "f1",\n    "VpcConfig": {\n        "SubnetIds": [\n            null\n        ],\n        "SecurityGroupIds": [\n            null\n        ]\n    },\n    "FunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:f1",\n    "Environment": {\n        "Variables": {},\n        "Error": {}\n    },\n    "Handler": "lambda.lambda_handler",\n    "Role": "r1",\n    "Runtime": "python2.7"\n}<\/code><\/pre>\n

\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u30ea\u30ed\u30fc\u30c9\u3059\u308c\u3070\u3001\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u304c\u3067\u304d\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

\"\"<\/p>\n

\u3061\u306a\u307f\u306b\u3001\u53f3\u306e Show code<\/code> \u304b\u3089\u30b3\u30fc\u30c9\u3092\u898b\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u4fbf\u5229\u3002<\/p>\n

\"\"<\/p>\n

\u5b9f\u884c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n

$ aws lambda --endpoint-url=http:\/\/localhost:4574 invoke --function-name f1 --payload '{"key1":"value1"}' result.log\n{\n    "StatusCode": 200\n}<\/code><\/pre>\n

200\u304c\u8fd4\u308b\u3068\u601d\u3044\u307e\u3059\u3002
\n\u30ed\u30b0\u3092\u898b\u3066\u307f\u307e\u3059\u3002<\/p>\n

$ cat result.log\nLocalStack TEST<\/code><\/pre>\n

\u30d0\u30c3\u30c1\u30ea\u3067\u3059\u306d!!<\/p>\n

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

Lambda\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u4f5c\u6210 \u2192 \u5b9f\u884c\u3092\u30ed\u30fc\u30ab\u30eb\u3067\u5b8c\u7d50\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3082\u66f8\u304d\u3084\u3059\u304f\u306a\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u306b\u51fa\u308b\u5fc5\u8981\u3082\u306a\u304f\u3001AWS\u30ea\u30bd\u30fc\u30b9\u3068\u3057\u3066\u306e\u30b3\u30b9\u30c8\u3082\u8003\u616e\u3057\u306a\u304f\u3066\u3044\u3044\u306e\u3067\u3001\u958b\u767a\u6642\u306b\u306f\u975e\u5e38\u306b\u6709\u7528\u304b\u3068\u601d\u3044\u307e\u3059\u3002
\n\u4eca\u56de\u306f\u66f8\u3044\u3066\u3044\u307e\u305b\u3093\u304c\u3001aws-sam-local\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3088\u308a\u5b9f\u969b\u306e\u74b0\u5883\u306b\u8fd1\u3065\u3051\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n

\u306a\u304a\u3001\u4ee5\u4e0b\u306e\u307a\u30fc\u30b8\u3067MMM\u306eAWS Lambda\u3078\u306e\u53d6\u308a\u7d44\u307f\u3092\u3054\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3059\u3002\u305c\u3072\u5408\u308f\u305b\u3066\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n

\u30fb\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\uff08AWS Lambda\uff09<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

MMM\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u67f3\u6cbc\u3067\u3059\u3002 \u6587\u9ce5\u304c\u63db\u7fbd\u671f\u306a\u306e\u3067\u90e8\u5c4b\u4e2d\u306b\u7fbd\u304c\u821e\u3063\u3066\u307e\u3059\u3002 \u4eca\u56de\u306fAtlassian\u304c\u958b\u767a\u3057\u3066\u3044\u308bLocalStack\u3092\u4f7f\u3063\u3066\u3001Lambda\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u30ed\u30fc\u30ab\u30eb\u306b\u9589\u3058\u3066\u52d5\u304b\u3057\u3066\u307f\u307e\u3059\u3002 LocalStack\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u307e\u305a\u306f\u3001LocalStack\u3092\u4f7f\u3063\u3066\u307f\u307e\u3059\u3002 pip\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001 docker\u30a4\u30e1\u30fc\u30b8\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u305d\u3061\u3089\u3092\u4f7f\u3063 […]<\/p>\n","protected":false},"author":1,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,21],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/456"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=456"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/456\/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=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}