GithubHelp home page GithubHelp logo

fastapi_fargate's Introduction

This is a sample FastAPI Repo that can be Dockerized to run in the cloud.

It was built as a tutorial to get a simple Python API up and running on AWS ECS Fargate.

IMPORTANT: Don't run this as is in production.

To run on ECS Fargate, do the following:

  1. Create a repository on DockerHub.
  2. In your CLI (at the root of the project), run:
poetry install

You should now be able to run the API locally with:

poetry run python backend/main.py

and see {"Hello":"World"} at http://localhost:8001/.

  1. To build the container, run:
docker build -t fastapi_fargate .
  1. Tag the container with:
docker tag fastapi_fargate:latest <Your_DockerHub_Username>/<Your_DockerHub_RepositoryName>:latest

and push with:

docker push <DockerHub_Username>/<DockerHub_RepositoryName>:latest
  1. In AWS, create an IAM role with permissions SecretsManagerReadWrite and AmazonECSTaskExecutionRolePolicy.
  2. Go to AWS Secrets Manager and create a secret with key-value pairs for "username" and "password". Username is your Docker username, and the password is an access token that you can create at DockerHub Security.
  3. Under ECS, create a cluster and then create a Task Definition. Select your IAM role you just created under Task Roles.
  4. Under Container Details, use docker.io/<Your_DockerHub_Username>/<Your_DockerHub_RepositoryName>:latest, select Private registry authentication, and use the Secrets Manager ARN that you created in step 6.
  5. Create your service in your ECS cluster with the Task Definition you just created.
  6. Once your service is up and running, click into your service, go to the Networking tab, and go to the attached security group. Under inbound rules, add port 80 with source 0.0.0.0/0.

You should see {"Hello":"World"} if you go to the running task in ECS and visit the public IP address in your browser.

fastapi_fargate's People

Contributors

echantler avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.