{"id":573,"date":"2019-09-15T19:30:00","date_gmt":"2019-09-15T10:30:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/09\/15\/api-gateway-resources"},"modified":"2019-09-15T19:30:00","modified_gmt":"2019-09-15T10:30:00","slug":"api-gateway-resources","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/09\/15\/api-gateway-resources\/","title":{"rendered":"AWS SAM\u3068Serverless Framework\u304b\u3089\u5b66\u3076API Gateway\u30ea\u30bd\u30fc\u30b9\u306e\u5206\u5272\u624b\u6cd5"},"content":{"rendered":"
\u6700\u8fd1\u3001 <\/p>\n \u4eca\u56de\u306f\u3001 API Gateway HTTP\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306f\u3001 Body\u5b9a\u7fa9\u306b\u3001\u5168\u3066\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002 \u524d\u8ff0\u306eBody\u5b9a\u7fa9\u306f\u5229\u7528\u305b\u305a\u3001\u8907\u6570\u306eCloudFormation\u30ea\u30bd\u30fc\u30b9\u306b\u5206\u5272\u3057\u3066\u5b9a\u7fa9\u3057\u307e\u3059\u3002 \u3064\u307e\u308a\u3001\u5358\u4e00\u306e \u3053\u306e\u9650\u754c\u306f\u610f\u5916\u306b\u3059\u3050\u306b\u3084\u3063\u3066\u304d\u307e\u3059\u3002 \u3057\u304b\u3057\u306a\u304c\u3089\u3001 \u305d\u308c\u3067\u306f\u3001\u305d\u308c\u305e\u308c\u306e\u30c7\u30d7\u30ed\u30a4\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u304a\u3051\u308b API Gateway\u306b\u306f\u30d9\u30fc\u30b9\u30d1\u30b9\u30de\u30c3\u30d4\u30f3\u30b0\u304c\u5229\u7528\u3067\u304d\u307e\u3059\u3002 <\/p>\n \u305f\u3060\u3057\u3001\u6ce8\u610f\u70b9\u304c\u3042\u308a\u307e\u3059\u3002\u6b21\u7537\u306e\u4f53\u91cd<\/code> \u304c
\u9577\u7537\u306e\u4f53\u91cd<\/code> \u3092\u8d85\u3048\uff12\u53f0\u76ee\u306e\u96fb\u52d5\u30a2\u30b7\u30b9\u30c8\u30b5\u30a4\u30af\u30eb\u3092
\n\u8cb7\u3044\u8db3\u3057\u307e\u3057\u305f\u3002 \u3084\u3063\u3055\u3093<\/code> \u3067\u3054\u3056\u3044\u307e\u3059\u3002<\/p>\n
CloudFormation<\/code> \u306b\u304a\u3051\u308b
API Gateway<\/code> \u306e\u5b9a\u7fa9\u65b9\u6cd5\u3092\u3001
\nAWS SAM<\/code> \u3068
Serverless Framework<\/code> \u306e\u4e8b\u4f8b\u304b\u3089\u7406\u89e3\u3057\u3001
\nAPI Gateway<\/code> \u30ea\u30bd\u30fc\u30b9\u306e\u5206\u5272\u65b9\u6cd5\u306b\u3064\u3044\u3066\u6a21\u7d22\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n
API Gateway HTTP\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u5b9a\u7fa9\u65b9\u6cd5\u306b\u3064\u3044\u3066<\/h2>\n
2\u7a2e\u985e\u306e\u5b9a\u7fa9\u65b9\u6cd5<\/code> \u304c\u3042\u308a\u307e\u3059\u3002
\n\u305d\u308c\u305e\u308c\u3092\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\u305d\u306e1\uff1a\u300cAWS::ApiGateway::RestApi\u300d\u306eBody\u306b\u8a18\u8ff0<\/h3>\n
\n\u4e00\u5ea6\u306b\u5168\u3066\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3092\u8a18\u8ff0\u3067\u304d\u3001
\n\u8907\u6570\u306e\u30ea\u30bd\u30fc\u30b9\u306b\u5206\u5272\u3057\u306a\u3044\u305f\u3081\u5185\u5bb9\u3092\u7406\u89e3\u3057\u3084\u3059\u3044\u3067\u3059\u3002
\n\u5916\u90e8\u306eswagger\u30d5\u30a1\u30a4\u30eb\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u3067\u3001\u8a18\u8ff0\u5185\u5bb9\u3092\u3088\u308a\u7c21\u6f54\u306b\u51fa\u6765\u307e\u3059\u3002<\/p>\nAWS SAM<\/code> \u306f\u3053\u306e\u8a18\u8ff0\u65b9\u6cd5\u3092\u63a1\u7528\u3057\u3066\u304a\u308a\u3001
\nBody\u306e\u5b9a\u7fa9\u3092\u7701\u7565\u3057\u305f\u5834\u5408\u306b\u3082\u3001AWS SAM<\/code> \u304c\u81ea\u52d5\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n
\u30b5\u30f3\u30d7\u30eb\u4f8b\uff1a<\/h4>\n
"ApiGatewayApi1": {\n "Type": "AWS::ApiGateway::RestApi",\n "Properties": {\n "Body": {\n "info": {\n "version": "1.0",\n "title": {\n "Ref": "AWS::StackName"\n }\n },\n "paths": {\n "\/v1\/test1": {\n "get": {\n "x-amazon-apigateway-integration": {\n "httpMethod": "POST",\n "type": "aws_proxy",\n "uri": {\n "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path\/2015-03-31\/functions\/${api1.Arn}\/invocations"\n }\n },\n "responses": {}\n }\n }\n },\n "swagger": "2.0"\n },\n "Name": "api1"\n }\n },<\/code><\/pre>\n
\u305d\u306e2\uff1a\u8907\u6570\u306e\u30ea\u30bd\u30fc\u30b9\u306b\u5b9a\u7fa9<\/h3>\n
\n\u4e0b\u8a18\u306e\u30ea\u30bd\u30fc\u30b9\u304c\u767b\u5834\u3057\u307e\u3059\u3002<\/p>\n\n\n
\n \n\u30ea\u30bd\u30fc\u30b9\u540d<\/th>\n \u5f79\u5272<\/th>\n<\/tr>\n<\/thead>\n \n AWS::ApiGateway::RestApi<\/td>\n REST API \u304c\u4f5c\u6210\u3055\u308c\u307e\u3059<\/td>\n<\/tr>\n \n AWS::ApiGateway::Resource<\/td>\n API \u306b\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059<\/td>\n<\/tr>\n \n AWS::ApiGateway::Method<\/td>\n \u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u672c\u6587\u3092\u5b9a\u7fa9\u3059\u308b<\/td>\n<\/tr>\n \n AWS::ApiGateway::Deployment<\/td>\n API Gateway RestApi \u30ea\u30bd\u30fc\u30b9\u3092\u30b9\u30c6\u30fc\u30b8\u306b\u30c7\u30d7\u30ed\u30a4<\/td>\n<\/tr>\n \n AWS::ApiGateway::Stage<\/td>\n \u30c7\u30d7\u30ed\u30a4\u3059\u308b\u305f\u3081\u306e\u30b9\u30c6\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u307e\u3059<\/td>\n<\/tr>\n \n \u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u7684\u306a\u95a2\u4fc2\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/td>\n <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n AWS::ApiGateway::RestApi\n \u251c AWS::ApiGateway::Resource\n \u2502 \u2514 AWS::ApiGateway::Method\n \u2514 AWS::ApiGateway::Deployment\n \u2514 AWS::ApiGateway::Stage<\/code><\/pre>\n
Serverless Framework<\/code> \u306f\u3053\u306e\u5b9a\u7fa9\u65b9\u6cd5\u3092\u63a1\u7528\u3057\u3066\u304a\u308a\u3001
\nRestApi\u306e\u8ad6\u7406ID<\/code> \u3092\u53c2\u7167\u3059\u308c\u3070
Resource<\/code> \u3084
Method<\/code> \u3092\u8907\u6570\u306e\u30b9\u30bf\u30c3\u30af\u306b\u5bb9\u6613\u306b\u5206\u5272\u53ef\u80fd\u3067\u3059\u3002<\/p>\n
\u672c\u984c\uff1aAPI Gateway\u30ea\u30bd\u30fc\u30b9\u306e\u5206\u5272\u65b9\u6cd5<\/h2>\n
AWS SAM<\/code> \u304a\u3088\u3073\u3001
Serverless Framework<\/code>
API Gateway<\/code> \u306e\u30ea\u30bd\u30fc\u30b9\u4f8b\u304b\u3089\u3001
\n\u30ea\u30bd\u30fc\u30b9\u5206\u5272\u65b9\u6cd5\u3092\u6a21\u7d22\u3057\u307e\u3057\u305f\u3002<\/p>\n\u5fc5\u305a\u7a81\u304d\u5f53\u305f\u308b\u3001CloudFormation\u306e\u30ea\u30bd\u30fc\u30b9\u6570\u5236\u9650200\u306e\u58c1\u306b\u3064\u3044\u3066<\/h3>\n
CloudFormation<\/code> \u306f\u4e00\u3064\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u542b\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u30ea\u30bd\u30fc\u30b9\u6570\u306e\u4e0a\u9650\u3092
\n200<\/code> \u3068\u3057\u3066\u304a\u308a\u3001\u3053\u308c\u306f
\u4e0a\u9650\u89e3\u653e\u7533\u8acb\u3092\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u306a\u3044<\/code> \u5236\u9650 \u3068\u306a\u308a\u307e\u3059\u3002
\nAWS SAM<\/code> \u304a\u3088\u3073\u3001
Serverless Framework<\/code> \u3067\u30ea\u30bd\u30fc\u30b9\u5236\u9650\u306b\u5f15\u3063\u304b\u304b\u308b
\n\u4e3b\u306a\u7406\u7531\u306f\u3001 API Gateway<\/code> \u306eHTTP\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u304c\u5897\u3048\u308b\u3053\u3068\u306b\u3042\u308a\u307e\u3059\u3002<\/p>\n
AWS SAM\u306e\u5834\u5408<\/h4>\n
AWS SAM<\/code> \u306f\u3001
AWS::ApiGateway::RestApi<\/code> \u306eBody\u306b
\n\u5168\u3066\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3092\u8a18\u8ff0\u3057\u307e\u3059\u306e\u3067\u3001
\n\u30ea\u30bd\u30fc\u30b9\u6570\u7684\u306b\u306f\u4f59\u88d5\u304c\u3042\u308b\u3088\u3046\u306b\u4e00\u898b\u3059\u308b\u3068\u898b\u3048\u307e\u3059\u3002
\n\u3057\u304b\u3057 2019\u5e749\u670815\u65e5<\/code> \u6642\u70b9\u3067\u306e\u4ed5\u69d8\u3068\u3057\u3066\u3001
\nAPI Gateway<\/code> \u306e\u30ea\u30bd\u30fc\u30b9 \u3068 \u95a2\u9023\u3059\u308b
Lambda\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3<\/code> \u306f\u540c\u3058\u30b9\u30bf\u30c3\u30af\u306b
\n\u8a18\u8ff0\u3057\u306a\u3044\u3068\u30c7\u30d7\u30ed\u30a4\u306b\u6210\u529f\u3057\u307e\u305b\u3093\u3002\u30a8\u30e9\u30fc\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\nAPI Gateway<\/code> \u3068 \u95a2\u9023\u3059\u308b
Lambda<\/code> \u3092\u542b\u3081\u305f\u30ea\u30bd\u30fc\u30b9\u6570\u306f
200\u304c\u9650\u754c\u3067\u3059<\/code> (2019\u5e749\u670815\u65e5\u6642\u70b9) \u3002<\/p>\n
\n\u306a\u305c\u306a\u3089\u3001 AWS SAM<\/code> \u306f
Lambda<\/code> \u6bce\u306b\u6700\u4f4e2\u3064\u306ePermission\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u3001
\nLambda<\/code> \u304c\u5897\u3048\u308c\u3070\u5897\u3048\u308b\u307b\u3069\u3001Permission\u304c\u5897\u3048\u3001
\n\u30ea\u30bd\u30fc\u30b9\u306e\u5927\u534a\u3092\u5360\u3081\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\nAWS SAM<\/code> \u306f\u3053\u308c\u306b\u3064\u3044\u3066\u3044\u304f\u3064\u304b\u306e Issue \u304c\u767a\u884c\u3055\u308c\u3066\u304a\u308a\u8b70\u8ad6\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n
Serverless Framework\u306e\u5834\u5408<\/h4>\n
Serverless Framework<\/code> \u306f\u3001Permission\u306e\u6570\u306f
Lambda<\/code> \u3068
1:1<\/code> \u3067\u3042\u308b\u305f\u3081\u3001
\nPermission\u306e\u6570\u304c\u30ea\u30bd\u30fc\u30b9\u306e\u5927\u534a\u3092\u5360\u3081\u308b\u3088\u3046\u306a\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\n\u3057\u304b\u3057\u306a\u304c\u3089\u3001 API Gateway<\/code> \u95a2\u9023\u306e\u8907\u6570\u306e\u30ea\u30bd\u30fc\u30b9\u304c\u4f5c\u6210\u3055\u308c\u308b\u305f\u3081\u3001
\n\u5834\u5408\u306b\u3088\u3063\u3066\u306f AWS SAM<\/code> \u3088\u308a\u3082\u30ea\u30bd\u30fc\u30b9\u6570\u3092\u65e9\u304f\u6d88\u8cbb\u3057\u307e\u3059\u3002
\n\u7279\u306b\u3001HTTP\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u304c\u591a\u3044\u5927\u898f\u6a21\u306aAPI\u30b7\u30b9\u30c6\u30e0\u306e\u5834\u5408\u3001
\n Serverless Framework<\/code> \u306e\u307b\u3046\u304c\u30ea\u30bd\u30fc\u30b9\u6570\u306e\u9650\u754c
200<\/code> \u306b
\n \u3059\u3050\u306b\u9054\u3057\u3066\u3057\u307e\u3046\u3067\u3057\u3087\u3046\u3002<\/p>\nServerless Framework<\/code> \u306e\u5834\u5408\u306f
AWS SAM<\/code> \u3068\u6bd4\u8f03\u3057\u3066
\n\u5bb9\u6613\u306b \u30b9\u30bf\u30c3\u30af\u5206\u5272<\/code> \u3067\u304d\u308b\u305f\u3081\u3001\u5b9f\u969b\u306b\u306f
AWS SAM<\/code> \u3088\u308a\u3082
\n\u591a\u304f\u306eHTTP\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3092\u542b\u3081\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002\u3053\u308c\u306b\u3064\u3044\u3066\u306f\u5f8c\u8ff0\u3057\u307e\u3059\u3002<\/p>\n\u305d\u308c\u305e\u308c\u306e\u30c7\u30d7\u30ed\u30a4\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u304a\u3051\u308b\u89e3\u6c7a\u7b56\u3092\u63a2\u308b<\/h2>\n
\n\u89e3\u6c7a\u7b56\u3092\u6a21\u7d22\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\nAWS SAM \uff1a \u30d9\u30fc\u30b9\u30d1\u30b9\u30de\u30c3\u30d4\u30f3\u30b0\u306b\u3088\u308b\u8907\u6570\u306eAPI Gateway\u30ea\u30bd\u30fc\u30b9\u306e\u7d71\u5408<\/h3>\n
\n\u3053\u308c\u306b\u3088\u308a\u3001\u8907\u6570\u306eAPI Gateway\u30ea\u30bd\u30fc\u30b9\u3092\u4e00\u3064\u306e\u30c9\u30e1\u30a4\u30f3\u306b\u96c6\u7d04\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u304d\u3001
\nAPI Gateway\u306e\u6a19\u6e96\u306eURL\u3088\u308a\u3082\u7c21\u6f54\u3067\u5206\u304b\u308a\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n
\n\u30d9\u30fc\u30b9\u30d1\u30b9\u30de\u30c3\u30d4\u30f3\u30b0\u306f\u8907\u6570\u306e\u968e\u5c64\u3092\u542b\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002
\n\u4f8b\u3048\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5206\u5272\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u3059\u3002<\/p>\n