Skip to content

Random Quote Web App - Terraform (IAC) AWS App Deployment

Notifications You must be signed in to change notification settings

searles9/Quote_App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quote App / Terraform AWS Deployment

What is this?

This is a web application that allows you to request a random quote.

Website

Architecture

Diagram Everything is deployed to AWS using Terraform. That includes the IAM policies, the website code, the DynamoDB table data, etc... You can view the main.tf file to get a better idea of everything that is deployed.

Basic overview:

  • User goes to a static website which is hosted in S3
  • When the "Get Quote" button is clicked, it calls an API Gateway endpoint
  • The api triggers a lamdbda function
  • The lamdba function queries dynamodb and returns a random quote from the database
  • The random quote is sent back to the client PC and is displayed in a <p> HTML element

Technical challenges:

From my research, there is no native way to query a random item in DynamoDB (which is a sham because that option exists in other database types). There are creative solutions that can make this possible, but most have some sort of major draw back or require additional heavy lifiting. To eliminate some complexity in this project, I set the partition key of the DynamoDb table as "id" and inserted 10 records that each contiained an id within 1-10. Then in the lambda function, I queried dynamodb for a random id inside the range 1-10. A better long-term/scalable solution would probably be to use a database that allows for searching random records.


Get it up and running:

  1. Run terraform apply to build the terraform resources:
terraform apply --auto-approve
  1. Grab the "quote_api_ url output": QuoteOutput
  2. Update the website javascript file to use that new api url: ApiURL
  3. Run another apply to update the website code:
terraform apply --auto-approve
  1. The site should now be operational. You can use the website url output to quickly get to the static website: WebsiteURL Website

Important notes

  • I could have broken some of the resources into modules - I just didnt want to go through that extra work for this particular project
  • I am aware that the website UI looks like trash. That wasn't the main focus of the project.

Some Technical Notes

  • Test invoke the function: aws lambda invoke --region=us-east-1 --function-name=$(terraform output -raw function_name) response.json
  • curl: curl "$(terraform output -raw base_api_url)/quote"

Documentation / Guides