Skip to content

cs399f24/voting_lambda_apigateway_dynamodb_s3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This version of the voting system hosts the index.html file in an S3 bucket and the API for voting with an API Gateway. Each endpoint of the API is implemented as a Lambda function that interacts with DynamoDB.

Architecture

Developer Setup

  • Clone the repo in Cloud9

  • Create a virtual environement

    python3 -m venv .venv
    
  • Activate the virtual environment

    source .venv/bin/activate
    
  • Install the requirements

    pip install -r requirements.txt
    

Deploy

  • Create DynamoDB table

    ./create_dynamodb_table.sh
    

    NOTE: This will not create the table if it already exists

  • (Optional) Reset votes to 0

    python reset_dynamodb_table.py
    
  • Create the lambda function that will process GET /results

    ./create_get_results_lambda.sh
    

    NOTE: This will not create the function if it already exists

  • Create the lambda function that will process POST /vote

    ./create_post_vote_lambda.sh
    

    NOTE: This will not create the function if it already exists

  • Create the API Gateway with the both endpoints

    python create_voting_api.py
    
  • Deploy the API

    ./deploy.sh
    
  • Test that the endpoints are working (NOTE: this will add one "yes" vote)

    ./test.sh
    

    This test requires manual verification: The script calls the GET /results endpoint, which returns the current number of votes. Then it calls the POST /vote endpoint, which also returns the number of votes (with +1 "yes" vote). Finally, it shows the headers for the OPTIONS /vote, which should be a 200 status code with the access-control headers set for CORS.

  • Update the index.html in the S3 bucket

    ./update_index.sh
    

Tear Down

  • Delete the API

    ./delete_api.sh
    
  • Delete the lambda function for GET /results

    ./delete_get_results_lambda.sh
    
  • Delete the lambda function for POST /vote

    ./delete_post_vote_lambda.sh
    

TODO

  • Create a script to reset the database
  • Refactor the Lambda functions
    • duplicate code to get current counts
    • Application vs. delivery mechanism (API Gateway)
  • system is hard coded for my bucket name
  • create script to make DynamoDB table (if not present)
  • change lambda runtime to python3.12

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published