From 0c73bdff8aa34bb8168ef1aaf5a5d9ed5ff495eb Mon Sep 17 00:00:00 2001 From: bertrand <bpinel@ippon.fr> Date: Sun, 10 Feb 2019 17:32:15 +0100 Subject: [PATCH] Update terraform script to include S3 lambda code bucket and to correct some strage behaviour... --- cloud/lambda/lambda-jsonapi.zip | Bin 0 -> 3321 bytes cloud/terraform/api-gateway.tf | 233 ++++++++++++++++++++++---------- cloud/terraform/bucket.tf | 11 ++ cloud/terraform/lambda.tf | 8 +- 4 files changed, 181 insertions(+), 71 deletions(-) create mode 100644 cloud/lambda/lambda-jsonapi.zip diff --git a/cloud/lambda/lambda-jsonapi.zip b/cloud/lambda/lambda-jsonapi.zip new file mode 100644 index 0000000000000000000000000000000000000000..4c88a99dae208b141ce3294d9ead26ee0d7b52e3 GIT binary patch literal 3321 zcmZ|SS2!CC+XwIjF@m5J#bX3DLaAMQ6NFHugsRolh^=PrXzi`Fsj5xw9kfQQ+Pkf- zl-h(U-ahYl_Fdn1-3Rx5^8cUQM?a)4F$n_z03ZiACG+TaC%M|IPyqlLLI40AfDPbm zjj^$_7IyS>b+LAHxaa8k$e02^oRKDCf!}>%;q6Na0Fs;n0f7Hj{9?iQOz8X$2=2wZ zBWN=x0xEJ*J(fbo?oNxCZSQ^S0Extc*hmubsD|REo0oa$C&?MK{ErBW9`(J$;-i-V zUSj$b2J}+!oU<98cwe1XjxX?6JSR?lw|>fAOD=78GZj~jhG*gP`T@7bok-67S5@{K zW@Gr~vo*I>@XN(nOWIfN+6h+=u)1I5*tNcaSXb+^pWU3SFAHby?I|o?cAT#I?GR?3 z=yKrpuP@gIc6_eFSNzaT(~b=TUm$+_!F+~N9Fq|}4{s$XO~MC5cO-P7EQyEI8MXZR z12c>O8bDld+PUW^C=O6VRNHYCJv`ynP4Ic~R`L6X@!K){h{s+Vh}8>7-US?RGxrR* zbT;{m$iqkM+p*Q|ghH@ut>nl%_~7bmi}BZYgLFn$cT|>-oQK0?TfRXLE;ji{WKtb> zfUzh-)pJ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7jzWSwSR_eWS+EqQeIO%dtJ zif0+~)A#v=go<hIq;}zl69Zg#uKgBXWoYfbg7wL+1SYteeRP3}9gPz|tMiU!UNi6R zzOmCEDy|O+D;y((IMQ&??a|m>l#-)22n3Rbure^l+shyXR^ss%R%{M6hJ4-|AMZ~o z%(YGD3!t@pXin8Yx|aJ9ufPQxX>?gBqQlVEXJLQQkhxR`PjNu><KL+IJn;SHG9Aqt zs^OX%BoQ`CVAv^aPR_Gp?x%^fYuld>8>HhCAoOIZW;!zunf!=Cm=V0(c$iWQU`i3$ zr3$>;-2O%&LSD%X=f+*O0?B<R{AzGP>UPOPCwyQ5$w4$XHuAH!Tn62niZJe(HV2MY zs~?EqtzDGM+fFJY@Z|5oY5Ra*%)>`TmY=}CszM(r$UP8A8T7GHQY({__eJ%gPTG`0 z&04)E8q7F@$bFQHgBU+Z%^*lKVqT*uy&MlD;T%Uo4vAo&$0MQVqe71luPKqbKq7YH v|4$>#f0Y6N{KW>~edxc}|6vo*|JdYzxdf>TBK<c2{5z(9ckEx_00931#hD|B literal 0 HcmV?d00001 diff --git a/cloud/terraform/api-gateway.tf b/cloud/terraform/api-gateway.tf index 3030fb5..45bb796 100644 --- a/cloud/terraform/api-gateway.tf +++ b/cloud/terraform/api-gateway.tf @@ -26,7 +26,48 @@ resource "aws_api_gateway_method" "typePathGet" { http_method = "GET" authorization = "NONE" } - +# OPTIONS on path /{type} for supporting CORS +resource "aws_api_gateway_method" "typePathOptions" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_resource.typePath.id}" + http_method = "OPTIONS" + authorization = "NONE" +} +resource "aws_api_gateway_method_response" "typeOptions200" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_resource.typePath.id}" + http_method = "${aws_api_gateway_method.typePathOptions.http_method}" + status_code = "200" + response_models { + "application/json" = "Empty" + } + response_parameters { + "method.response.header.Access-Control-Allow-Headers" = true, + "method.response.header.Access-Control-Allow-Methods" = true, + "method.response.header.Access-Control-Allow-Origin" = true + } +} +resource "aws_api_gateway_integration" "typeOptionsIntegration" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_resource.typePath.id}" + http_method = "${aws_api_gateway_method.typePathOptions.http_method}" + type = "MOCK" + passthrough_behavior = "WHEN_NO_TEMPLATES" + request_templates { + "application/json" = "{\"statusCode\": 200}" + } +} +resource "aws_api_gateway_integration_response" "typeOptionsIntegrationResponse" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_resource.typePath.id}" + http_method = "${aws_api_gateway_method.typePathOptions.http_method}" + status_code = "${aws_api_gateway_method_response.typeOptions200.status_code}" + response_parameters = { + "method.response.header.Access-Control-Allow-Headers" = "'Content-Type,Access-Control-Allow-Origin,X-Amz-Date,Authorization,X-Requested-With,X-Requested-By,X-Api-Key,X-Amz-Security-Token'", + "method.response.header.Access-Control-Allow-Methods" = "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin" = "'*'" + } +} # POST on path /{type} resource "aws_api_gateway_method" "typePathPost" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" @@ -42,7 +83,48 @@ resource "aws_api_gateway_method" "typeIdPathGet" { http_method = "GET" authorization = "NONE" } - +# OPTIONS on path /{type}/{id} +resource "aws_api_gateway_method" "typeIdPathOptions" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_resource.typeIdPath.id}" + http_method = "OPTIONS" + authorization = "NONE" +} +resource "aws_api_gateway_method_response" "typeIdOptions200" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_resource.typeIdPath.id}" + http_method = "${aws_api_gateway_method.typeIdPathOptions.http_method}" + status_code = "200" + response_models { + "application/json" = "Empty" + } + response_parameters { + "method.response.header.Access-Control-Allow-Headers" = true, + "method.response.header.Access-Control-Allow-Methods" = true, + "method.response.header.Access-Control-Allow-Origin" = true + } +} +resource "aws_api_gateway_integration" "typeIdOptionsIntegration" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_resource.typeIdPath.id}" + http_method = "${aws_api_gateway_method.typeIdPathOptions.http_method}" + type = "MOCK" + passthrough_behavior = "WHEN_NO_TEMPLATES" + request_templates { + "application/json" = "{\"statusCode\": 200}" + } +} +resource "aws_api_gateway_integration_response" "typeIdOptionsIntegrationResponse" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_resource.typeIdPath.id}" + http_method = "${aws_api_gateway_method.typeIdPathOptions.http_method}" + status_code = "${aws_api_gateway_method_response.typeIdOptions200.status_code}" + response_parameters = { + "method.response.header.Access-Control-Allow-Headers" = "'Content-Type,Access-Control-Allow-Origin,X-Amz-Date,Authorization,X-Requested-With,X-Requested-By,X-Api-Key,X-Amz-Security-Token'", + "method.response.header.Access-Control-Allow-Methods" = "'GET,OPTIONS,DELETE,PATCH'", + "method.response.header.Access-Control-Allow-Origin" = "'*'" + } +} # DELETE on path /{type}/{id} resource "aws_api_gateway_method" "typeIdPathDelete" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" @@ -59,6 +141,8 @@ resource "aws_api_gateway_method" "typeIdPathPatch" { authorization = "NONE" } +############################################## +# GET on {type} # Setup Integration Request for GET on {type} resource "aws_api_gateway_integration" "lambdaJsonTypeGet" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" @@ -74,77 +158,15 @@ resource "aws_api_gateway_integration" "lambdaJsonTypeGet" { "application/json" = "${file("template.vm")}" } } - -# Setup Integration Request for POST on {type} -resource "aws_api_gateway_integration" "lambdaJsonTypePost" { - rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" - resource_id = "${aws_api_gateway_method.typePathPost.resource_id}" - http_method = "${aws_api_gateway_method.typePathPost.http_method}" - - integration_http_method = "POST" - type = "AWS" - uri = "${aws_lambda_function.lambda-jsonapi.invoke_arn}" - # Transforms the incoming XML request to JSON - passthrough_behavior = "WHEN_NO_TEMPLATES" - request_templates { - "application/json" = "${file("template.vm")}" - } -} - -# Setup Integration Request for GET on {type}/{id} -resource "aws_api_gateway_integration" "lambdaJsonTypeIdGet" { - rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" - resource_id = "${aws_api_gateway_method.typeIdPathGet.resource_id}" - http_method = "${aws_api_gateway_method.typeIdPathGet.http_method}" - - integration_http_method = "POST" - type = "AWS" - uri = "${aws_lambda_function.lambda-jsonapi.invoke_arn}" - # Transforms the incoming XML request to JSON - passthrough_behavior = "WHEN_NO_TEMPLATES" - request_templates { - "application/json" = "${file("template.vm")}" - } -} - -# Setup Integration Request for DELETE on {type}/{id} -resource "aws_api_gateway_integration" "lambdaJsonTypeIdDelete" { - rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" - resource_id = "${aws_api_gateway_method.typeIdPathDelete.resource_id}" - http_method = "${aws_api_gateway_method.typeIdPathDelete.http_method}" - - integration_http_method = "POST" - type = "AWS" - uri = "${aws_lambda_function.lambda-jsonapi.invoke_arn}" - # Transforms the incoming XML request to JSON - passthrough_behavior = "WHEN_NO_TEMPLATES" - request_templates { - "application/json" = "${file("template.vm")}" - } -} - -# Setup Integration Request for PATCH on {type}/{id} -resource "aws_api_gateway_integration" "lambdaJsonTypeIdPatch" { - rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" - resource_id = "${aws_api_gateway_method.typeIdPathPatch.resource_id}" - http_method = "${aws_api_gateway_method.typeIdPathPatch.http_method}" - - integration_http_method = "POST" - type = "AWS" - uri = "${aws_lambda_function.lambda-jsonapi.invoke_arn}" - # Transforms the incoming XML request to JSON - passthrough_behavior = "WHEN_NO_TEMPLATES" - request_templates { - "application/json" = "${file("template.vm")}" - } -} - # Setup Integration Response for status code 200 and GET on {type} resource "aws_api_gateway_method_response" "200TypeGet" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" resource_id = "${aws_api_gateway_method.typePathGet.resource_id}" http_method = "${aws_api_gateway_method.typePathGet.http_method}" status_code = "200" + response_parameters { + "method.response.header.Access-Control-Allow-Origin" = true + } } resource "aws_api_gateway_integration_response" "200TypeGetIntegrationResponse" { @@ -155,8 +177,28 @@ resource "aws_api_gateway_integration_response" "200TypeGetIntegrationResponse" response_templates = { "application/json" = "" } + response_parameters { + "method.response.header.Access-Control-Allow-Origin" = "'*'" + } + depends_on = ["aws_api_gateway_integration.lambdaJsonTypeGet"] } +############################################## +# POST on {type} +# Setup Integration Request for POST on {type} +resource "aws_api_gateway_integration" "lambdaJsonTypePost" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_method.typePathPost.resource_id}" + http_method = "${aws_api_gateway_method.typePathPost.http_method}" + integration_http_method = "POST" + type = "AWS" + uri = "${aws_lambda_function.lambda-jsonapi.invoke_arn}" + # Transforms the incoming XML request to JSON + passthrough_behavior = "WHEN_NO_TEMPLATES" + request_templates { + "application/json" = "${file("template.vm")}" + } +} # Setup Integration Response for status code 200 and POST on {type} resource "aws_api_gateway_method_response" "200TypePost" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" @@ -173,8 +215,25 @@ resource "aws_api_gateway_integration_response" "200TypePostIntegrationResponse" response_templates = { "application/json" = "" } + depends_on = ["aws_api_gateway_integration.lambdaJsonTypePost"] } +############################################## +# GET on {type}/{id} +# Setup Integration Request for GET on {type}/{id} +resource "aws_api_gateway_integration" "lambdaJsonTypeIdGet" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_method.typeIdPathGet.resource_id}" + http_method = "${aws_api_gateway_method.typeIdPathGet.http_method}" + integration_http_method = "POST" + type = "AWS" + uri = "${aws_lambda_function.lambda-jsonapi.invoke_arn}" + # Transforms the incoming XML request to JSON + passthrough_behavior = "WHEN_NO_TEMPLATES" + request_templates { + "application/json" = "${file("template.vm")}" + } +} # Setup Integration Response for status code 200 and GET on {type}/{id} resource "aws_api_gateway_method_response" "200TypeIdGet" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" @@ -190,9 +249,26 @@ resource "aws_api_gateway_integration_response" "200TypeIdGetIntegrationResponse status_code = "${aws_api_gateway_method_response.200TypeIdGet.status_code}" response_templates = { "application/json" = "" - } + } + depends_on=["aws_api_gateway_integration.lambdaJsonTypeIdGet"] } +############################################## +# DELETE on {type}/{id} +# Setup Integration Request for DELETE on {type}/{id} +resource "aws_api_gateway_integration" "lambdaJsonTypeIdDelete" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_method.typeIdPathDelete.resource_id}" + http_method = "${aws_api_gateway_method.typeIdPathDelete.http_method}" + integration_http_method = "POST" + type = "AWS" + uri = "${aws_lambda_function.lambda-jsonapi.invoke_arn}" + # Transforms the incoming XML request to JSON + passthrough_behavior = "WHEN_NO_TEMPLATES" + request_templates { + "application/json" = "${file("template.vm")}" + } +} # Setup Integration Response for status code 200 and DELETE on {type}/{id} resource "aws_api_gateway_method_response" "200TypeIdDelete" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" @@ -209,8 +285,25 @@ resource "aws_api_gateway_integration_response" "200TypeIdDeleteIntegrationRespo response_templates = { "application/json" = "" } + depends_on= ["aws_api_gateway_integration.lambdaJsonTypeIdDelete"] } +############################################## +# PATCH on {type}/{id} +# Setup Integration Request for PATCH on {type}/{id} +resource "aws_api_gateway_integration" "lambdaJsonTypeIdPatch" { + rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" + resource_id = "${aws_api_gateway_method.typeIdPathPatch.resource_id}" + http_method = "${aws_api_gateway_method.typeIdPathPatch.http_method}" + integration_http_method = "POST" + type = "AWS" + uri = "${aws_lambda_function.lambda-jsonapi.invoke_arn}" + # Transforms the incoming XML request to JSON + passthrough_behavior = "WHEN_NO_TEMPLATES" + request_templates { + "application/json" = "${file("template.vm")}" + } +} # Setup Integration Response for status code 200 and PATCH on {type}/{id} resource "aws_api_gateway_method_response" "200TypeIdPatch" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" @@ -218,7 +311,6 @@ resource "aws_api_gateway_method_response" "200TypeIdPatch" { http_method = "${aws_api_gateway_method.typeIdPathPatch.http_method}" status_code = "200" } - resource "aws_api_gateway_integration_response" "200TypeIdPatchIntegrationResponse" { rest_api_id = "${aws_api_gateway_rest_api.jsonapi.id}" resource_id = "${aws_api_gateway_resource.typeIdPath.id}" @@ -227,12 +319,15 @@ resource "aws_api_gateway_integration_response" "200TypeIdPatchIntegrationRespon response_templates = { "application/json" = "" } + depends_on = ["aws_api_gateway_integration.lambdaJsonTypeIdPatch"] } resource "aws_api_gateway_deployment" "jsonapiDeployment" { depends_on = [ + "aws_api_gateway_integration.typeOptionsIntegration", "aws_api_gateway_integration.lambdaJsonTypeGet", "aws_api_gateway_integration.lambdaJsonTypePost", + "aws_api_gateway_integration.typeIdOptionsIntegration", "aws_api_gateway_integration.lambdaJsonTypeIdGet", "aws_api_gateway_integration.lambdaJsonTypeIdPatch", "aws_api_gateway_integration.lambdaJsonTypeIdDelete" diff --git a/cloud/terraform/bucket.tf b/cloud/terraform/bucket.tf index 830525d..0e7b86d 100644 --- a/cloud/terraform/bucket.tf +++ b/cloud/terraform/bucket.tf @@ -7,6 +7,17 @@ variable "bucket_name_staging" { default = "ember-aws-ehipster-staging" } +resource "aws_s3_bucket" "lambda-bucket" { + bucket = "lambda-jsonapi-code-bucket" + acl = "public-read" +} +resource "aws_s3_bucket_object" "lambda-bucket-code" { + bucket = "${aws_s3_bucket.lambda-bucket.bucket}" + key = "v1.0.0/lambda-jsonapi.zip" + source = "../lambda/lambda-jsonapi.zip" + etag = "${md5(file("../lambda/lambda-jsonapi.zip"))}" +} + resource "aws_s3_bucket" "production" { bucket = "${var.bucket_name_production}" acl = "public-read" diff --git a/cloud/terraform/lambda.tf b/cloud/terraform/lambda.tf index 6f30758..27252ef 100644 --- a/cloud/terraform/lambda.tf +++ b/cloud/terraform/lambda.tf @@ -10,8 +10,8 @@ resource "aws_lambda_function" "lambda-jsonapi" { function_name = "lambda-jsonapi" # The bucket name as created before running terraform scripts with "aws s3api create-bucket" - s3_bucket = "lambda-jsonapi-code-bucket" - s3_key = "v1.0.0/lambda-jsonapi.zip" + s3_bucket = "${aws_s3_bucket.lambda-bucket.bucket}" + s3_key = "${aws_s3_bucket_object.lambda-bucket-code.key}" # "main" is the filename within the zip file (main.js) and "handler" # is the name of the property under which the handler function was @@ -20,6 +20,8 @@ resource "aws_lambda_function" "lambda-jsonapi" { runtime = "nodejs8.10" role = "${aws_iam_role.lambda_jsonapi.arn}" + + depends_on = ["aws_s3_bucket.lambda-bucket"] } @@ -33,4 +35,6 @@ resource "aws_lambda_permission" "apigw" { # The /*/* portion grants access from any method on any resource # within the API Gateway "REST API". source_arn = "${aws_api_gateway_deployment.jsonapiDeployment.execution_arn}/*/*" + + depends_on = ["aws_iam_role.lambda_jsonapi"] } \ No newline at end of file -- GitLab