From 4d69f16e64ffab301df7e85a4e9f7f8d81717f46 Mon Sep 17 00:00:00 2001 From: Solomon Negusse Date: Tue, 3 Dec 2024 13:23:55 +0300 Subject: [PATCH 1/4] use static domain that allows microservices to talk to the localstack container and vice versa --- terraform-localstack/outputs.tf | 2 +- terraform-localstack/variables.tf | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/terraform-localstack/outputs.tf b/terraform-localstack/outputs.tf index 0f171ee..6ecc54b 100644 --- a/terraform-localstack/outputs.tf +++ b/terraform-localstack/outputs.tf @@ -3,5 +3,5 @@ output "api_gateway_id" { } output "access_url" { - value = "http://${aws_api_gateway_rest_api.rw_api_gateway.id}.execute-api.localhost.localstack.cloud:4566/prod/" + value = "http://host.docker.internal:4566/restapis/${aws_api_gateway_rest_api.rw_api_gateway.id}/prod/_user_request_" } diff --git a/terraform-localstack/variables.tf b/terraform-localstack/variables.tf index 120a0b9..5f74dff 100644 --- a/terraform-localstack/variables.tf +++ b/terraform-localstack/variables.tf @@ -6,5 +6,6 @@ variable "x_rw_domain" { variable "microservice_host" { type = string - description = "Host in which the microservices will be available. Must be accessible from Localstack's running host (so if you are using docker, \"locahost\" won't work. Your local IP address might be a good guess" + default = "host.docker.internal" + description = "Host in which the microservices will be available. Must be accessible from Localstack's running host (so if you are using docker, \"locahost\" won't work." } From 9a6e564801a20ffdfb4cd78418be9abc2e7921e1 Mon Sep 17 00:00:00 2001 From: Solomon Negusse Date: Tue, 3 Dec 2024 13:25:07 +0300 Subject: [PATCH 2/4] update documentation --- terraform-localstack/README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/terraform-localstack/README.md b/terraform-localstack/README.md index 7b1cec6..40e67cf 100644 --- a/terraform-localstack/README.md +++ b/terraform-localstack/README.md @@ -1,15 +1,16 @@ # Using localstack -1 - Run localstack locally +In local development, we use localstack to emulate API Gateway functionality of routing requests across the various microservices (by matching request path pattern). To get localstack running and provision it with the API Gateway resources: + +1 - Run localstack locally. ```bash -docker run --rm -it -p 4566:4566 -p 4571:4571 localstack/localstack +docker run --rm -it -p 4566:4566 localstack/localstack ``` -2 - Terraform apply the content of this folder - -3 - Start microservices with the following GATEWAY_URL: - +2 - Terraform apply the content of this folder and confirm the changes in the prompt (use terraform version `v1.3.6`). This will output an `access_url` of the form `http://host.docker.internal:4566/restapis/{gateway_id}/prod/_user_request_`. If you choose to use a different port in Step 1, update the access_url variable in outputs.tf to reflect the chosen port.. +```bash +terraform apply ``` -https://.execute-api.localhost.localstack.cloud:4566/prod -``` \ No newline at end of file + +3 - In the microservice repo, set `GATEWAY_URL` variable where it's defined (in `docker-compose-develop` or `dev.env` file) to the `access_url` value from above step and you're all set - requests can now be routed across microservices via the Gateway. Note that as the microservice ports are hardcoded (see `../terraform-k8s-infrastructure/modules/k8s_microservice_routing/microservices/dataset`, for example), need to make sure the local dev container ports match those defined in terraform. \ No newline at end of file From 3bd52a49d9510f06d63417718518d58a136b5def Mon Sep 17 00:00:00 2001 From: Solomon Negusse Date: Wed, 4 Dec 2024 13:21:03 +0300 Subject: [PATCH 3/4] use localstack image version with fix for requests not being forward to backend when using the recommended /_aws/execute-api endpoint --- terraform-localstack/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform-localstack/README.md b/terraform-localstack/README.md index 40e67cf..055c855 100644 --- a/terraform-localstack/README.md +++ b/terraform-localstack/README.md @@ -5,7 +5,7 @@ In local development, we use localstack to emulate API Gateway functionality of 1 - Run localstack locally. ```bash -docker run --rm -it -p 4566:4566 localstack/localstack +docker run --rm -it -p 4566:4566 localstack/localstack:4.0.3 ``` 2 - Terraform apply the content of this folder and confirm the changes in the prompt (use terraform version `v1.3.6`). This will output an `access_url` of the form `http://host.docker.internal:4566/restapis/{gateway_id}/prod/_user_request_`. If you choose to use a different port in Step 1, update the access_url variable in outputs.tf to reflect the chosen port.. From 64ae7e41909cc2b2ed6380506d562cd3511cb0e1 Mon Sep 17 00:00:00 2001 From: Solomon Negusse Date: Wed, 4 Dec 2024 13:22:48 +0300 Subject: [PATCH 4/4] update deprecated gateway endpoint --- terraform-localstack/README.md | 2 +- terraform-localstack/outputs.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform-localstack/README.md b/terraform-localstack/README.md index 055c855..19cf4e8 100644 --- a/terraform-localstack/README.md +++ b/terraform-localstack/README.md @@ -8,7 +8,7 @@ In local development, we use localstack to emulate API Gateway functionality of docker run --rm -it -p 4566:4566 localstack/localstack:4.0.3 ``` -2 - Terraform apply the content of this folder and confirm the changes in the prompt (use terraform version `v1.3.6`). This will output an `access_url` of the form `http://host.docker.internal:4566/restapis/{gateway_id}/prod/_user_request_`. If you choose to use a different port in Step 1, update the access_url variable in outputs.tf to reflect the chosen port.. +2 - Terraform apply the content of this folder and confirm the changes in the prompt (use terraform version `v1.3.6`). This will output an `access_url` of the form `http://host.docker.internal:4566/_aws/execute-api/{gateway_id}/prod`. If you choose to use a different port in Step 1, update the access_url variable in outputs.tf to reflect the chosen port.. ```bash terraform apply ``` diff --git a/terraform-localstack/outputs.tf b/terraform-localstack/outputs.tf index 6ecc54b..02555df 100644 --- a/terraform-localstack/outputs.tf +++ b/terraform-localstack/outputs.tf @@ -3,5 +3,5 @@ output "api_gateway_id" { } output "access_url" { - value = "http://host.docker.internal:4566/restapis/${aws_api_gateway_rest_api.rw_api_gateway.id}/prod/_user_request_" + value = "http://host.docker.internal:4566/_aws/execute-api/${aws_api_gateway_rest_api.rw_api_gateway.id}/prod" }