Skip to content

dipalikulshrestha/FSND_project4

Repository files navigation

Deploying a Flask API

This is the project starter repo for the fourth course in the Udacity Full Stack Nanodegree: Server Deployment, Containerization, and Testing.

In this project you will containerize and deploy a Flask API to a Kubernetes cluster using Docker, AWS EKS, CodePipeline, and CodeBuild.

The Flask app that will be used for this project consists of a simple API with three endpoints:

  • GET '/': This is a simple health check, which returns the response 'Healthy'.
  • POST '/auth': This takes a email and password as json arguments and returns a JWT based on a custom secret.
  • GET '/contents': This requires a valid JWT, and returns the un-encrpyted contents of that token.

The app relies on a secret set as the environment variable JWT_SECRET to produce a JWT. The built-in Flask server is adequate for local development, but not production, so you will be using the production-ready Gunicorn server when deploying the app.

Initial setup

  1. Fork this project to your Github account.
  2. Locally clone your forked version to begin working on the project.

Dependencies

  • Docker Engine
    • Installation instructions for all OSes can be found here.
    • For Mac users, if you have no previous Docker Toolbox installation, you can install Docker Desktop for Mac. If you already have a Docker Toolbox installation, please read this before installing.
  • AWS Account
    • You can create an AWS account by signing up here.

Project Steps

Completing the project involves several steps:

  1. Write a Dockerfile for a simple Flask API
  2. Build and test the container locally
  3. Create an EKS cluster
  4. Store a secret using AWS Parameter Store
  5. Create a CodePipeline pipeline triggered by GitHub checkins
  6. Create a CodeBuild stage which will build, test, and deploy your code

For more detail about each of these steps, see the project lesson here.

EXTERNAL IP

ad78b1a6210334513b3414d40b2b8fd5-668181699.us-west-2.elb.amazonaws.com

##Reference Output [ec2-user@ip-172-31-18-214 ~]$ kubectl get services simple-jwt-api -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR simple-jwt-api LoadBalancer 10.100.32.184 ad78b1a6210334513b3414d40b2b8fd5-668181699.us-west-2.elb.amazonaws.com 80:30820/TCP 33m app=simple-jwt-api [ec2-user@ip-172-31-18-214 ~]$ export TOKEN=curl -d '{"email":"dipali.kulshrestha@gmail.com","password":"mypasssword"}' -H "Content-Type: application/json" -X POST ad78b1a6210334513b3414d40b2b8fd5-668181699.us-west-2.elb.amazonaws.com/auth | jq -r '.token' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 258 100 193 100 65 9650 3250 --:--:-- --:--:-- --:--:-- 12900 [ec2-user@ip-172-31-18-214 ~]$ curl --request GET 'ad78b1a6210334513b3414d40b2b8fd5-668181699.us-west-2.elb.amazonaws.com/contents' -H "Authorization: Bearer ${TOKEN}" | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 75 100 75 0 0 8333 0 --:--:-- --:--:-- --:--:-- 8333 { "email": "dipali.kulshrestha@gmail.com", "exp": 1590862559, "nbf": 1589652959 } [ec2-user@ip-172-31-18-214 ~]$

About

FSND Project4 Repo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors