From bb88a19e4e3e8b763f65f52c972d310ac00b4aad Mon Sep 17 00:00:00 2001 From: James Lok Date: Mon, 23 Jun 2025 12:31:25 +0100 Subject: [PATCH 1/2] AB#18125 updated readme, created packaging script, and terraform states s3 bucket --- README.md | 13 ++++++++++--- package_redis.sh | 5 +++++ terraform/lambda_routes/lambda.tf | 2 +- terraform/terraform.tf | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100755 package_redis.sh create mode 100644 terraform/terraform.tf diff --git a/README.md b/README.md index 2a05002..9fca77a 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,19 @@ This is a websockets project written in Terraform and Python. Your websocket client can connect, subscribe to a topic and receive messages sent to that topic. +## Prerequisites +* Terraform is installed +* You have logged onto AWS using the `aws sso login` + ## Installation 1. Clone the repository -2. Navigate to the `/terraform` directory -3. Run `terraform init` -4. Run `terraform apply` +2. Navigate to the root of this repository +3. Run `./package_redis.sh` to package the Redis module for our lambda functions +4. Navigate to the `/terraform` directory +5. Run `terraform init` +6. Run `terraform workspace select ` where env is one of `testing`, `staging`, or `production`. +7. Run `terraform apply --var-file=.tfvars` ## Usage diff --git a/package_redis.sh b/package_redis.sh new file mode 100755 index 0000000..f100481 --- /dev/null +++ b/package_redis.sh @@ -0,0 +1,5 @@ +mkdir -p lambda_code/python +pip3 install redis async_timeout -t lambda_code/python +cd lambda_code +zip -r redis_layer.zip python +cd .. diff --git a/terraform/lambda_routes/lambda.tf b/terraform/lambda_routes/lambda.tf index 1fc993a..46fb5fb 100644 --- a/terraform/lambda_routes/lambda.tf +++ b/terraform/lambda_routes/lambda.tf @@ -24,7 +24,7 @@ resource "aws_lambda_function" "lambda" { environment { variables = { API_GW_ID = var.api_gw_id - API_GW_STAGE_NAME = var.api_gw_stage_name + API_GW_STAGE_NAME = "${var.api_gw_stage_name}-${terraform.workspace}" ELASTICACHE_ENDPOINT = var.elasticache_endpoint LOG_LEVEL = var.config_log_level } diff --git a/terraform/terraform.tf b/terraform/terraform.tf new file mode 100644 index 0000000..67ab1b3 --- /dev/null +++ b/terraform/terraform.tf @@ -0,0 +1,15 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" # up to 5.99 + } + } + + backend "s3" { + encrypt = true + bucket = "tkc-web-sockets-tf-state-files" + region = "eu-west-1" + key = "websockets/terraform.tfstate" + } +} From 600f0e6fa524e9c946f582f89cfc1cedf16f8779 Mon Sep 17 00:00:00 2001 From: JamesLok1998 <130992753+JamesLok1998@users.noreply.github.com> Date: Tue, 24 Jun 2025 10:02:44 +0100 Subject: [PATCH 2/2] Updated README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9fca77a..ded2137 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,4 @@ TODO - [x] Storage: change dynamoDB to cache e.g. elastic cache - [x] PING/PONG request/response to prevent client connection timeout - [x] Redis connection pooling +- [ ] Create Github action workflow to do current manual task of packaging redis and deploying architecture through terraform