Welcome to the SmartContentPipelineAi Project Backend! This project sets up a serverless infrastructure for the SmartContentPipelineAi project using AWS CDK (Cloud Development Kit). The stack includes S3 for data storage, Lambda functions for processing, and API Gateway for exposing APIs. This enables automatic deployment, secure data handling, and API integrations.
Before proceeding, ensure you have the following installed:
- S3 Bucket: Used for storing and managing data.
- Lambda Functions: Execute serverless functions to handle different tasks.
- API Gateway: Exposes endpoints for external communication.
- IAM Roles: Provides necessary permissions for Lambda functions.
To install AWS CDK, ensure you have Node.js (with NPM), AWS CLI configured, and then run
npm install -g aws-cdk
First, clone the repository from GitHub:
git clone https://github.com/TejaTalachiru/smartcontent-pipeline-ai.git
cd backend
To create and activate a virtual environment (Mac/Linux):
python -m venv .venv
source .venv/bin/activate
python -m venv .venv
.venv\Scripts\activate.bat
Install the Python dependencies using the following command:
pip install -r requirements.txt
You need to specify the S3 bucket name in the cdk.json
file. Open the file and update the value for bucket_name
:
{
"app": "python3 app.py",
"context": {
"bucket_name": "<your-unique-bucket-name>"
}
}
Ensure you are logged in to your AWS account:
aws configure
You will need to input your AWS Access Key, Secret Key, and default region.
Before deploying the stack, you need to bootstrap your environment:
cdk bootstrap
To generate the CloudFormation template for this project:
cdk synth
To deploy the stack to your AWS environment:
cdk deploy
This will deploy the S3 bucket, Lambda functions, API Gateway, and IAM roles.
This CDK project deploys multiple Lambda functions:
SummaryLambda
: Handles requests for summary creation.TitleLambda
: Handles requests for title generation.UpdateDataLambda
: Manages data updates.GetDataLambda
: Fetches data from S3.GeneratePresignedUrlNewLambda
: Generates presigned URLs for new uploads.GeneratePresignedUrlExistingLambda
: Generates presigned URLs for existing objects.GetPresignedUrlLambda
: Retrieves presigned URLs.TranslationLayer
: To generate the IDML.
Once the stack is successfully deployed, you will see the API URL in the deployment outputs. With this URL, you can access the following API endpoints:
- Summary API (POST):
/summary
- Title API (POST):
/title
- Update Data API (POST):
/update_data
- Get Data API (GET):
/get_data
- Generate Presigned URL for New Uploads (GET):
/generate_presigned_url_new
- Generate Presigned URL for Existing Files (GET):
/generate_presigned_url_existing
- Get Presigned URL (GET):
/get_presigned_url
- Idml Generation (GET):
/idml_gen
To delete the resources and avoid incurring charges, run:
cdk destroy
cdk ls
: List all stacks in the app.cdk synth
: Emit the synthesized CloudFormation template.cdk deploy
: Deploy this stack to your AWS account/region.cdk diff
: Compare the deployed stack with the current state.cdk docs
: Open the CDK documentation.
If you encounter any issues during the setup or deployment process, try the following steps:
Check AWS CLI Configuration: Ensure your AWS CLI is configured correctly by running:
aws configure
Confirm that the region, access key, and secret key are correctly set.
Virtual Environment Issues: If you encounter issues with the virtual environment (e.g., packages not found), try recreating the environment:
deactivate # If the virtualenv is currently active
rm -rf .venv # Delete the existing virtual environment
python -m venv .venv # Recreate the virtual environment
source .venv/bin/activate # Activate on MacOS/Linux
.venv\Scripts\activate.bat # Activate on Windows
pip install -r requirements.txt # Reinstall dependencies
- Ensure that the bucket name in cdk.json is unique.
- Check CloudFormation in the AWS Console for any specific error messages.
- Validate that your AWS credentials have the necessary permissions to create resources.
- S3 Bucket Already Exists: Ensure your bucket name is globally unique in the
cdk.json
file. - Ensure you have necessary IAM roles and permissions to deploy the Stack.