Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update localstack domain #120

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions terraform-localstack/README.md
Original file line number Diff line number Diff line change
@@ -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..
Copy link

@gtempus gtempus Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did get this access url. But the logs give me this warning:

localstack.deprecations    : /restapis/<api_id>/<stage>/_user_request_ is deprecated (since 3.8.0) and will be removed in upcoming releases of LocalStack! Use /_aws/execute-api/<api_id>/<stage> instead.

Should we use that path instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Hit this issue: localstack/localstack#10461 using that endpoint though as the localstack/localstack image we use doesn't have the fix so pinning to a later image version (localstack/localstack:4.0.3) with the fix.

```bash
terraform apply
```
https://<api gateway id>.execute-api.localhost.localstack.cloud:4566/prod
```

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.
2 changes: 1 addition & 1 deletion terraform-localstack/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
}
3 changes: 2 additions & 1 deletion terraform-localstack/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}