Let’s run the AI App in production on AWS.

AWS Setup


Add Credentials

To run on AWS, you need one of the following:

  1. The ~/.aws/credentials file with your AWS credentials
  2. AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY environment variables

To create the credentials file, install the aws cli and run aws configure


Add Region and Subnets

Add 2 Subnets to the workspace/settings.py file (required for ECS services)

ws_settings = WorkspaceSettings(
    # -*- AWS settings
    # Add your Subnet IDs here
    subnet_ids=["subnet-xyz", "subnet-xyz"],

Please check that the subnets belong to the selected aws_region

Update Secrets


Streamlit App Password

Update the streamlit app password in workspace/secrets/prd_app_secrets.yml

# OPENAI_API_KEY: "sk-***"

RDS database password

Update the RDS database password in workspace/secrets/prd_db_secrets.yml

# Secrets used by prd RDS database

Create AWS resources

Create AWS resources using:

phi ws up --env prd --infra aws

This will create:

  1. ECS Cluster for the application.
  2. ECS Task Definitions and Services that run the application on the ECS cluster.
  3. LoadBalancer to route traffic to the application.
  4. Security Groups that control incoming and outgoing traffic.
  5. Secrets for managing application and database secrets.
  6. RDS Database for Knowledge Base and Storage.

Press Enter to confirm and grab a cup of coffee while the resources spin up.

  • The RDS database takes about 5 minutes to activate.
  • These resources are defined in the workspace/prd_resources.py file.
  • Use the ECS console to view services and logs.
  • Use the RDS console to view the database instance.

Production Streamlit App

Open the LoadBalancer DNS provided when creating the Streamlit App

PDF Assistant

  • Enter the APP_PASSWORD from the prd_app_secrets.yml file (default: admin)
  • Click on PDF Assistant in the sidebar
  • Enter a username and wait for the knowledge base to load.
  • Choose the RAG or Autonomous Assistant type.
  • Ask "How do I make pad thai?"

Chat with pdf

Similarly checkout the Image and Website Assistants.

Production FastApi


Enable FastApi

Update the workspace/settings.py file and set prd_api_enabled=True

ws_settings = WorkspaceSettings(
    # Uncomment the following line

Create FastApi resources

phi ws up --env prd --infra aws --group api

Press Enter to confirm


View API Endpoints

  • Open the LoadBalancer DNS + the /docs endpoint to view the API Endpoints.
  • Load the knowledge base using /v1/assitants/load-knowledge-base
  • Test the v1/assitants/chat endpoint with
  "message": "How do I make pad thai?",
  "assistant": "AUTO_PDF"
  • Integrate with your front-end or product.

API Endpoints

Update Production

Follow this guide to update your production application. You'll need to:

  1. Create a new image
  2. Update the ECS Task Definition and Services.

Delete AWS resources

Play around and then delete AWS resources using:

phi ws down --env prd --infra aws

or delete individual resource groups using:

phi ws down --env prd --infra aws --group app


Congratulations on running your AI App on AWS. Next Steps: