DeployFrame Docs

Deployment Configuration

Clone the repository and configure the environment variables required for deploying your AI SaaS platform

Deployment Configuration

This guide covers setting up your GitHub repository and configuring both the CDK context and environment variables required to deploy your AI SaaS platform. Setting up these configurations correctly is essential for a successful deployment of all infrastructure components.

Creating Your GitHub Personal Access Token

Create a GitHub Personal Access Token

Follow these steps to create a GitHub personal access token for AWS Amplify deployment:

  1. Log in to GitHub: Go to github.com and sign in to your account.

  2. Access Developer Settings:

    • Click on your profile photo in the top-right corner
    • Select "Settings" from the dropdown menu
    • Scroll down and click on "Developer settings" in the left sidebar
    • Click on "Personal access tokens" → "Tokens (classic)"
  3. Generate a New Token:

    • Click "Generate new token" → "Generate new token (classic)"
    • Note: You may need to confirm your password
  4. Configure Token Settings:

    • Token name: Enter a descriptive name (e.g., "AI SaaS Amplify Deployment")
    • Expiration: Choose an appropriate expiration (30 days, 60 days, or custom)
    • Scopes: Select the following permissions:
      • repo (Full control of private repositories)
      • admin:repo_hook (Full control of repository hooks)
  5. Create Token:

    • Scroll to the bottom and click "Generate token"
  6. Copy Your Token:

    • IMPORTANT: Copy the generated token immediately
    • GitHub will only show this token once
    • Store it securely for use in your .env file

Treat your token like a password. Never share it publicly or commit it to version control. If you believe your token has been compromised, revoke it immediately in GitHub and create a new one.

Repository Setup

Create Repository from Template

After purchasing the AI SaaS Boilerplate, you'll receive access to the GitHub template repository.

  1. Navigate to the template repository URL
  2. Click the "Use this template" button
  3. Create a new repository in your GitHub account
  4. IMPORTANT: Make sure to check the "Include all branches" checkbox
  5. Choose a name for your repository (e.g., "my-ai-saas-platform")
  6. Select visibility (private recommended)
  7. Click "Create repository from template"

Checking the "Include all branches" checkbox ensures that both dev and main branches are included in your new repository, which is required for proper deployment to different environments.

Clone Your New Repository

Clone the repository you just created to your local machine:

git clone https://github.com/your-username/your-repository-name.git
cd your-repository-name

Replace your-username and your-repository-name with your actual GitHub username and the repository name you chose.

When cloning your private repository, you'll be prompted for authentication. Use your GitHub username as the username and the personal access token you created earlier as the password (GitHub has disabled password authentication for Git operations since August 2021).

Set Up the Development Branch Locally

The template repository comes with both main and dev branches. After cloning, set up tracking for the development branch:

git fetch origin dev
git checkout -b dev origin/dev

This ensures your local dev branch properly tracks the remote dev branch. By default, the deployment will target the dev branch since the default configuration uses stage=dev.

It's recommended to start with the development environment first before deploying to production.

The repository has a monorepo structure with separate folders for frontend, backend, and infrastructure (CDK). Navigate to the CDK directory where we'll configure the deployment:

cd cdk

Understanding the Configuration Approach

The AI SaaS Boilerplate uses two main configuration methods:

  1. CDK Context (cdk.json): For consistent, environment-independent settings like the application name
  2. Environment Variables (.env): For environment-specific settings like API keys and deployment stage

This dual approach has several advantages:

  • Consistency: Application-wide settings remain consistent across all environments
  • Security: Sensitive information like API keys aren't stored in version control
  • CI/CD Friendly: Environment variables are easy to integrate with CI/CD systems like GitHub Actions
  • Flexibility: Environment-specific settings can vary between development, staging, and production

For the initial core deployment, we'll use placeholder values for third-party services like Stripe and Google OAuth. You'll update these with real values after verifying the core infrastructure.

Configuring Your Application Name

Set Your Application Name in CDK Context

Open the cdk.json file in the cdk directory and update the app_name property in the context section:

{
  "app": "python3 app.py",
  "watch": {
    // watch configuration...
  },
  "context": {
    // Various AWS CDK configuration flags...
    "@aws-cdk/aws-lambda:recognizeLayerVersion": true,
    // More configuration flags...
    
    "app_name": "ai-saas"  // Change this value to your preferred application name
  }
}

You can keep the default name ai-saas or change it to your preferred application name.

Once you deploy resources with a specific application name, changing it will create new resources rather than updating existing ones. Choose your application name carefully before your first deployment.

Setting Up Environment Variables

Create Environment Variables File

Create a file named .env in your project's cdk directory:

# Environment Stage
STAGE=dev
 
# AWS Configuration
AWS_DEFAULT_REGION=eu-west-2
AWS_ACCOUNT_ID=123456789012
 
# Domain Configuration (Leave empty for initial deployment)
DOMAIN_NAME=
 
# GitHub Configuration (Required for Amplify Deployment)
GITHUB_OWNER=your-github-username
GITHUB_REPO=your-repository-name
GITHUB_TOKEN=your-github-personal-access-token
GITHUB_DEV_BRANCH=dev
GITHUB_PROD_BRANCH=main
 
# Stripe Integration (Placeholders for now)
STRIPE_API_PUBLIC_KEY=pk_test_placeholder
STRIPE_API_SECRET_KEY=sk_test_placeholder
STRIPE_WEBHOOK_SECRET_KEY=whsec_placeholder
 
# Google OAuth (Placeholders for now)
GOOGLE_OAUTH_CLIENT_ID=placeholder.apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRET=placeholder_secret
 
# Google Analytics
GOOGLE_ANALYTICS_ID=G-PLACEHOLDER
 
# OpenAI API (Leave empty for initial deployment)
OPENAI_API_KEY=
 
# AWS Bedrock Configuration
AWS_BEDROCK_REGION=us-east-1

Make sure to replace placeholders with your actual values:

  • Set your actual AWS account ID from the previous step
  • Update GitHub values with your username, repository name, and token
  • Leave DOMAIN_NAME and OPENAI_API_KEY empty for initial deployment
  • Other placeholder values (like Stripe and Google OAuth) can be updated later

The .env file should not be committed to version control. Make sure to add it to your .gitignore file.

Understanding Key Configuration Variables

Here's an explanation of the key configuration options used in the deployment process:

CDK Context (in cdk.json)

VariableDescriptionExample
app_nameApplication name for resource naming and stack identificationai-saas

Environment Variables (in .env)

VariableDescriptionExample
AWS_DEFAULT_REGIONThe AWS region for deploymenteu-west-2
AWS_ACCOUNT_IDYour AWS account ID123456789012
STAGEDeployment environment (dev, prod)dev
DOMAIN_NAMEDomain for the application (can be empty initially)``
GITHUB_OWNERYour GitHub usernameyour-username
GITHUB_REPOYour repository namemy-ai-saas-platform
GITHUB_TOKENGitHub personal access tokenghp_xxxxxxxxxxxx
GITHUB_DEV_BRANCHBranch name to use for development environmentdev
GITHUB_PROD_BRANCHBranch name to use for production environmentmain
STRIPE_API_PUBLIC_KEYStripe publishable keypk_test_...
STRIPE_API_SECRET_KEYStripe secret keysk_test_...
STRIPE_WEBHOOK_SECRET_KEYStripe webhook signing secretwhsec_...
GOOGLE_OAUTH_CLIENT_IDGoogle OAuth client ID....apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRETGoogle OAuth client secretSecret value
GOOGLE_ANALYTICS_IDGoogle Analytics tracking IDG-XXXXXXXXXX
OPENAI_API_KEYOpenAI API key for AI services``

Authentication Email Templates

The authentication system uses customizable email templates for user verification:

TemplateDescriptionLocation
verification_email_subject.txtSubject line for verification emailscdk/lib/core/auth/templates/
verification_email_body.txtBody content for verification emailscdk/lib/core/auth/templates/

These templates support the following placeholders:

  • {app_name} - Automatically replaced with your application name from CDK context
  • {####} - Replaced with the verification code (required in the email body)

The system includes default templates that work well for most deployments. The templates are loaded at deployment time and can be customized if needed for specific branding requirements.

Next Steps

Now that you've configured both your CDK context and environment variables required for deployment, you're ready to proceed to the Core Deployment Process section to deploy the infrastructure using these settings.