This project is a Book Search Application that allows users to search for books using natural language queries. The application integrates with the OpenLibrary Web Service to fetch book data and uses a Large Language Model (LLM) to process queries and generate natural language responses. The goal is to provide a fast, intuitive search experience with response times under 1-3 seconds.
Users need a fast, intuitive way to search for books using natural language descriptions. The challenge is to build a system that can process these queries, fetch relevant data, and generate natural language responses within 1-3 seconds.
The application follows a client-server architecture:
- Tech Stack: React, Fetch API (for HTTP requests)
- Core Features:
- Smart Search: Supports natural language queries for intuitive book discovery.
- Dynamic Recommendations: Displays book titles, authors, and summaries based on user input.
- Responsive UI: Optimized for both desktop and mobile devices.
- Tech Stack:
- Python: FastAPI
- Docker: Containerization
- LLM API: HF API, OpenAI API
- Core Features:
- Query Understanding: The LLM extracts key details from user queries.
- Information Retrieval: Calls the OpenLibrary API to fetch relevant book metadata.
- Response Generation: Summarizes book descriptions and crafts natural language responses.
- Caching for Performance: Frequently searched queries are cached, reducing API calls and improving response times.
This section walks through deploying the backend service on AWS using IAM, ECR, and ECS. The deployment process ensures a secure, scalable, and containerized environment for the application.
Before we begin, ensure you have:
- An AWS account with administrative access.
- The AWS CLI installed and configured.
- Docker installed on your local machine.
- Your backend service containerized using Docker.
- Log in to your AWS account and navigate to the AWS IAM Console.
- In the left sidebar, click Users → Create User.
- Provide a username (e.g.,
backend-deploy-user
). - Select Access Key - Programmatic Access.
Attach the following policies to grant the necessary permissions:
- AmazonEC2ContainerRegistryFullAccess – Allows full access to Amazon ECR (push, pull, delete images).
- AmazonECS_FullAccess – Provides full permissions to create and manage ECS resources.
- IAMFullAccess – Enables role and permission management.
- CloudWatchLogsFullAccess – Allows access to CloudWatch for ECS logging.
- AmazonS3ReadOnlyAccess – Grants read-only access to S3, useful if storing static assets or configuration.
- In the IAM user settings, navigate to Security Credentials.
- Scroll to the Access Keys section and click Create Access Key.
- Copy both the Access Key ID and Secret Access Key. Store these securely.
- Install AWS CLI by running the command in terminal:
brew install awscli
- Run the following command and enter the IAM credentials when prompted:
aws configure
- Open the Amazon ECR Console.
- Click Create Repository.
- Enter a repository name (e.g.,
backend-service
). - Select Private Repository.
- Click Create and note the repository URI.
To push Docker images to ECR, first authenticate your local Docker client:
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
Ensure you replace the following variables:
${AWS_REGION}
with the AWS region (e.g.,us-east-2
)${AWS_ACCOUNT_ID}
with your AWS account ID.
Once the Amazon ECR repository is set up, we need to build, tag, and push the Docker image. This ensures that the backend service is properly containerized and stored in AWS Elastic Container Registry (ECR) for deployment.
We will use docker buildx
to build the image. This ensures compatibility with AWS Fargate, which runs on linux/amd64 architecture.
docker buildx build \
--platform linux/amd64 \
--provenance=false \
-t ${ECR_REPOSITORY_NAME}:latest \
--load .
--platform linux/amd64
→ Ensures compatibility with AWS Fargate.--provenance=false
→ Disables provenance metadata, reducing build time.-t ${ECR_REPOSITORY_NAME}:latest
→ Tags the image locally as latest.--load
→ Loads the built image into the local Docker daemon.
Tagging is required so the image can be correctly referenced when pushing to ECR.
docker tag ${ECR_REPOSITORY_NAME}:latest \
${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY_NAME}:latest
${ECR_REPOSITORY_NAME}:latest
→ The locally built image.${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY_NAME}:latest
→ The ECR repository where the image will be pushed.
docker push ${AWS_ACCOUNT_ID}.dkr.ecr.us-east-2.amazonaws.com/${ECR_REPOSITORY_NAME}:latest
Now that our Docker image is stored in Amazon ECR, we can deploy it to Amazon ECS (Elastic Container Service) using Fargate, AWS’s serverless container orchestration service.
- Open the ECS Console.
- In the left sidebar, click Clusters → Create Cluster.
- Select Fargate (serverless).
- Configure the cluster settings as needed (default settings are fine for most cases).
- Click Create.
A task definition tells ECS how to run a container, including CPU/memory limits, networking, and container settings.
- Navigate to Task Definitions → Create New Task Definition.
- Choose Fargate as the launch type and click Next.
- Configure the container settings:
- Container Name:
backend-service
- Image URI: Use the ECR repository URI from Step 2.
- Memory/CPU: Choose an appropriate size (e.g.,
512 MB / 0.25 vCPU
). - Port Mappings: Set 8000 (or the port your backend listens on).
- Container Name:
- Click Create.
A service ensures that the task (container) runs continuously and handles scaling.
- Navigate to ECS Clusters and select your cluster.
- Click Create Service.
- Configure the service:
- Launch Type:
Fargate
- Task Definition: Select the one created in Step 3.2.
- Service Name:
backend-service
- Number of Tasks: Set an appropriate number (
1
for testing, scale up for production).
- Launch Type:
- Click Deploy.
- Navigate to your ECS Cluster → Services.
- Click on your running service and note the Public IP of the running task.
- Test the deployment by sending a request:
curl http://${PUBLIC_IP}:8080
If the service responds correctly, your backend is now successfully running on AWS ECS Fargate.
When changes are made to the backend service, the updated Docker container needs to be deployed to Amazon ECS to ensure the latest version of the application is running in the cluster. Below are the steps to build, tag, push, and deploy the updated container.
First, build the Docker image for the backend service. This step compiles the application into a container that can be deployed to ECS.
docker buildx build \
--platform linux/amd64 \
--provenance=false \
-t ${ECR_REPOSITORY_NAME}:latest \
--load .
After building the image, tag it with the full ECR repository URL. This step prepares the image to be pushed to the Amazon Elastic Container Registry (ECR).
docker tag ${ECR_REPOSITORY_NAME}:latest \
${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY_NAME}:latest
docker push ${AWS_ACCOUNT_ID}.dkr.ecr.us-east-2.amazonaws.com/${ECR_REPOSITORY_NAME}:latest
Finally, update the ECS service to use the newly pushed container image. This step triggers a new deployment, replacing the old containers with the updated version.
aws ecs update-service --cluster ${ECS_CLUSTER_NAME} --service ${ECS_SERVICE_NAME} --force-new-deployment --region ${AWS_REGION}
This section outlines the steps required to deploy the frontend of the Book Search Application using AWS Amplify. AWS Amplify automates the deployment process, integrating directly with GitHub for continuous deployment. By following these steps, you can ensure a smooth and efficient deployment process.
Before starting the deployment process, ensure the following steps are completed:
- AWS Account: You need an AWS account with the necessary permissions to create and manage Amplify applications.
- GitHub Repository: The frontend code should be hosted in a GitHub repository.
- Node.js and Yarn: Ensure Node.js and Yarn are installed on your local machine.
Run the linting tool to ensure the code adheres to the project's coding standards:
yarn run lint
Generate an optimized production build of the application:
yarn run build
This command compiles the React application into a set of static files that can be served by a web server.
- Go to the AWS Amplify Console.
- Sign in with your AWS credentials.
- Click the "Create New Application" button to start the process.
- Select GitHub as the source code provider.
- Choose the name of the repository from your GitHub account.
- Select the
main
branch for deployment.
Since the frontend application is part of a monorepo, specify the root directory:
- Set the root directory to
frontend
to ensure Amplify knows where to find the source code.
- Click the "Next" button to proceed.
- AWS Amplify will automatically build and deploy the application to the cloud.
Once the deployment is complete, the application will be accessible at the provided Amplify URL.