Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <env>` where env is one of `testing`, `staging`, or `production`.
7. Run `terraform apply --var-file=<env>.tfvars`

## Usage

Expand All @@ -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
5 changes: 5 additions & 0 deletions package_redis.sh
Original file line number Diff line number Diff line change
@@ -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 ..
2 changes: 1 addition & 1 deletion terraform/lambda_routes/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions terraform/terraform.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}