DeployFrame Docs

Core Deployment Process

Deploy the core infrastructure of your AI SaaS platform using Python CDK

Core Deployment Process

This guide provides streamlined instructions for deploying the core infrastructure of your AI SaaS platform to AWS using Python CDK. The deployment will create all necessary AWS resources with the placeholder configurations for third-party services set in the previous step.

Prerequisites

Before proceeding, ensure you have:

CDK automatically reads values from your .env file. We also expose them to this shell so the upcoming AWS CLI commands (e.g., the Amplify build trigger) can access them.

Setting Up the Python Environment

cd cdk

Create a Python Virtual Environment

python3 -m venv .venv
source .venv/bin/activate

Creating a virtual environment keeps your project dependencies isolated from your system Python.

Install Dependencies

pip install -r requirements.txt

This will install all the required AWS CDK dependencies and other Python packages needed for deployment.

Deployment Steps

Load Environment Variables for This Shell

CDK automatically reads values from the .env file, but we need to expose these variables to the current shell session for AWS CLI commands.

# Expose everything from .env to the current session
set -a && source .env && set +a

If you update values in your .env file during this session, you'll need to run the above command again for shell commands to see the new values. CDK deployment tools will automatically use the updated values from the file.

Validate Configuration with CDK Synthesis

cdk synth

This command synthesizes AWS CloudFormation templates from your CDK code but doesn't deploy any resources. It helps catch configuration errors before deployment.

If this command completes without errors, your configuration is valid and you can proceed to deployment.

If you see errors, check your environment variables and ensure all required values are present and correctly formatted.

Deploy Core Infrastructure

cdk deploy --all --require-approval never

This command deploys all resources without prompting for approval of IAM policy changes.

Deployment will take approximately 15-20 minutes to complete as AWS provisions all the resources.

Important deployment outputs such as API endpoints and application URLs are stored as CloudFormation exports and can be retrieved programmatically when needed in later steps.

Trigger Your First Front-end Build

The Amplify app is now created, but the front-end has not built yet, so the URL will return a "not deployed" message until a build is triggered.

# Extract the app_name from cdk.json
APP_NAME=$(jq -r '.context.app_name' cdk.json)
echo "Using app_name from cdk.json: $APP_NAME"
 
# Set the export name pattern using the extracted APP_NAME
EXPORT_NAME="${APP_NAME}-${STAGE}-amplify-app-id"
 
# Retrieve the Amplify App ID by export name
AMPLIFY_APP_ID=$(aws cloudformation list-exports \
  --query "Exports[?Name=='$EXPORT_NAME'].Value" \
  --output text)
  
echo "Amplify App ID: $AMPLIFY_APP_ID"
 
# Start the build using the extracted App ID
aws amplify start-job \
  --app-id $AMPLIFY_APP_ID \
  --branch-name dev \
  --job-type RELEASE

You can also trigger the same build from the AWS Amplify console: Amplify ➜ Build history ➜ Redeploy.

Understanding What Was Deployed

Next Steps

After successfully deploying the core infrastructure and triggering the first front-end build, proceed to Verifying Core Deployment to ensure that your basic infrastructure is working correctly before setting up third-party integrations.