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:
-
Log in to GitHub: Go to github.com and sign in to your account.
-
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)"
-
Generate a New Token:
- Click "Generate new token" → "Generate new token (classic)"
- Note: You may need to confirm your password
-
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)
- ✓
-
Create Token:
- Scroll to the bottom and click "Generate token"
-
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.
- Navigate to the template repository URL
- Click the "Use this template" button
- Create a new repository in your GitHub account
- IMPORTANT: Make sure to check the "Include all branches" checkbox
- Choose a name for your repository (e.g., "my-ai-saas-platform")
- Select visibility (private recommended)
- 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:
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:
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.
Navigate to the CDK Directory
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:
Understanding the Configuration Approach
The AI SaaS Boilerplate uses two main configuration methods:
- CDK Context (cdk.json): For consistent, environment-independent settings like the application name
- 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:
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:
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)
Variable | Description | Example |
---|---|---|
app_name | Application name for resource naming and stack identification | ai-saas |
Environment Variables (in .env)
Variable | Description | Example |
---|---|---|
AWS_DEFAULT_REGION | The AWS region for deployment | eu-west-2 |
AWS_ACCOUNT_ID | Your AWS account ID | 123456789012 |
STAGE | Deployment environment (dev, prod) | dev |
DOMAIN_NAME | Domain for the application (can be empty initially) | `` |
GITHUB_OWNER | Your GitHub username | your-username |
GITHUB_REPO | Your repository name | my-ai-saas-platform |
GITHUB_TOKEN | GitHub personal access token | ghp_xxxxxxxxxxxx |
GITHUB_DEV_BRANCH | Branch name to use for development environment | dev |
GITHUB_PROD_BRANCH | Branch name to use for production environment | main |
STRIPE_API_PUBLIC_KEY | Stripe publishable key | pk_test_... |
STRIPE_API_SECRET_KEY | Stripe secret key | sk_test_... |
STRIPE_WEBHOOK_SECRET_KEY | Stripe webhook signing secret | whsec_... |
GOOGLE_OAUTH_CLIENT_ID | Google OAuth client ID | ....apps.googleusercontent.com |
GOOGLE_OAUTH_CLIENT_SECRET | Google OAuth client secret | Secret value |
GOOGLE_ANALYTICS_ID | Google Analytics tracking ID | G-XXXXXXXXXX |
OPENAI_API_KEY | OpenAI API key for AI services | `` |
Authentication Email Templates
The authentication system uses customizable email templates for user verification:
Template | Description | Location |
---|---|---|
verification_email_subject.txt | Subject line for verification emails | cdk/lib/core/auth/templates/ |
verification_email_body.txt | Body content for verification emails | cdk/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.