diff --git a/README.md b/README.md index 2a05002..ded2137 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 @@ -24,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 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" + } +}