Terraform codes for deploying a Python Lambda API and the AWS EKS platform for running a Flask Web Application.
- Clone Git repository to get the files
git clone git@github.com:zbrondial/helloworld-lambda-eks.git
cd helloworld-lambda-eks
-
Update provider.tf for your AWS credential profile. This can be checked on your ~/.aws/credentials file
-
Still on provider.tf, comment out the terraform block for now. We have to create the S3 bucket and DynamoDB Table first.
# terraform {
# backend "s3" {
# encrypt = true
# bucket = "apihw-infra-tfstate-dev"
# region = "ap-southeast-1"
# dynamodb_table = "apihw-infra-state-lock-dynamo"
# key = "terraform-state/terraform.tfstate"
# }
# }
-
Update locals.tf with the appropriate values
-
Deploy the s3 bucket and dynamodb table for remote statefile storage and management. We will also create a separate terraform workspace for dev and production environment. On this coding task, I've used the "dev" workspace.
terraform init
terraform workspace new dev
terraform workspace new prod
terraform workspace select dev
terraform apply -target aws_s3_bucket.states apihw-infra-tfstate-dev
terraform apply -target aws_dynamodb_table.dynamodb_state_lock apihw-infra-state-lock-dynamo
- Migrate the locally stored terraform.tfstate to S3 backend. Edit again provider.tf, uncomment the terraform block and execute this command.
terraform init -reconfigure
- Before running plan and apply, make sure that you are on the "dev" workspace.
terraform workspace list
terraform init
terraform plan
terraform apply
- https://sayhello.zi-zd.com/
- Enter the Hello World API URL
- https://u99w0hvk0m.execute-api.ap-southeast-1.amazonaws.com/hw

Please access the below repository for the procedure
