ran-isenberg / aws-chatbot-fargate-python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChatBot AWS CDK Deployment

license PythonSupport version github-star-badge issues

alt text

This project deploys an AWS Fargate-based ESC cluster web application using AWS CDK (Cloud Development Kit).

The infrastructure includes an ECS cluster, Fargate service, Application Load Balancer, VPC, and WAF and includes security best practices with CDK-nag verification.

The web application is a chatbot but can replaced to any application you wish.

The chatbot is based on an implementation by Streamlit and the initial prompt is that the chatbot is me, Ran the builder, a serverless hero and attempts to answer as me.

The Chatbot uses custom domain (you can remove it or change it to your own domain) and assume an OpenAI token exists in the account in the form of a secrets manager secret for making API calls to OpenAI.

Blogs website > Contact details | ran.isenberg@ranthebuilder.cloud

Twitter Follow Website

Prerequisites

  • AWS CLI configured with appropriate credentials
  • Node.js (with npm)
  • Python 3.12 or higher
  • AWS CDK 2.149.0 or greater installed
  • OpenAI API key deployed as a secret (see cdk/service/Docker/app.py)

Project Structure

  • cdk.service.network_assets_construct: Custom construct for network-related resources.
  • docker/: Directory containing the Dockerfile for the chat application.
  • app.py: Entry point for the CDK application.
  • chat_bot_construct.py - the Fargate construct

CDK Stack Overview

Resources Created

  • VPC: Virtual Private Cloud with 2 Availability Zones.
  • ECR: Amazon Elastic Container Registry to store Docker images.
  • ECS Cluster: Elastic Container Service cluster with Fargate capacity providers.
  • Fargate Task Definition: Defines the container specifications.
  • Fargate Service: Deploys the container and integrates with the Application Load Balancer.
  • Application Load Balancer: Publicly accessible load balancer with SSL termination.
  • WAF: Web Application Firewall to protect the application.
  • S3 Buckets: Used for access logs with encryption and secure settings.
  • IAM Roles and Policies: Permissions for ECS tasks and other services.
  • Auto Scaling: CPU and memory-based auto-scaling configuration.

Deployment

Step 1: Install Dependencies

Navigate to your project directory and install the necessary dependencies:

cd {new repo folder}
poetry shell
poetry install
make deploy

You can also run 'make pr' will run all checks, synth, file formatters and deploy to AWS.

Code Contributions

Code contributions are welcomed. Read this guide.

Code of Conduct

Read our code of conduct here.

Connect

Credits

License

This library is licensed under the MIT License. See the LICENSE file.

About

License:MIT License


Languages

Language:Python 85.4%Language:Makefile 11.8%Language:Dockerfile 2.8%