> ## Documentation Index
> Fetch the complete documentation index at: https://docs.launchkitaws.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deployment

> Deploy your LaunchKit AWS application to a scalable, production-ready environment on AWS using the Cloud Development Kit (CDK).

This guide covers the final step in launching your application: deploying it to a live production environment on AWS. We will use the AWS Cloud Development Kit (CDK) to provision all the necessary infrastructure as code, ensuring your deployment is repeatable and scalable.

### A Note on Your Database

It is critical to understand that the LaunchKit AWS CDK stack provisions your **application infrastructure** (compute, CDN, networking, etc.), but it **does not** provision a database.

This is intentional and follows best practices. Separating your stateless application from your stateful database allows for independent scaling, updates, and management, which is crucial for a production environment.

**You must provision your own production-grade Postgres database before starting this guide.**

***

### Prerequisites

Before you can deploy, ensure you have the following set up:

1. **AWS Account & Credentials:** You need an active AWS account. The easiest way to provide credentials is to install the [AWS CLI](https://aws.amazon.com/cli/) and run `aws configure`.
2. **Node.js and NPM:** Ensure you have Node.js (v18.x or later) installed.
3. **AWS CDK Toolkit:** The CDK command-line tool must be installed globally. If you don't have it, run:
   ```bash theme={null}
   npm install -g aws-cdk
   ```

***

### Deployment Steps

#### Step 1: Provision a Production Database

If you haven't already, create a production Postgres database. We recommend a managed service for reliability and ease of use.

Popular options include:

* [Amazon RDS](https://aws.amazon.com/rds/postgresql/)
* [Railway](https://railway.app/)
* [Supabase](https://supabase.com/)

Once your database is created, find and copy its **connection string**. It will look something like this: `postgresql://user:password@host:port/database`.

#### Step 2: Configure Production Secrets

The deployment script reads its configuration from an environment file. It's best practice to create a separate file for production secrets.

1. In the root of your project, create a copy of the example environment file:
   ```bash theme={null}
   cp .env.example .env.prod
   ```

2. Open the new `.env.prod` file and fill in **all** the required variables for your production environment (Stripe, Resend, etc.).

3. Most importantly, add the database connection string you obtained in Step 1:
   ```bash theme={null}
   # .env.prod
   DATABASE_URL="YOUR_DATABASE_CONNECTION_STRING"
   ```

#### Step 3: Install CDK Dependencies

The CDK infrastructure code is in its own directory with its own dependencies.

1. Navigate to the CDK directory:
   ```bash theme={null}
   cd cdk
   ```

2. Install its dependencies:
   ```bash theme={null}
   yarn install
   ```

#### Step 4: Deploy the Stack to AWS

From within the `cdk` directory, run the deployment command. This command tells the CDK to use the variables from your `.env.prod` file.

```bash theme={null}
yarn deploy:prod
```

The deployment process will take several minutes as the CDK provisions all the necessary AWS resources (e.g., VPC, ECS, CloudFront).

***

### After Deployment

Once the process is complete, the CDK will output the `DistributionDomain`. This is the public CloudFront URL for your live application. You can find it in the "Outputs" section of your terminal.

#### Optional: Custom Domain

The feature to automatically configure a custom domain via the CDK is coming soon. For now, you can manually point your domain to the application by creating a `CNAME` record in your DNS provider that points to the CloudFront distribution domain provided in the CDK output.

### Next Steps

Congratulations! You have a fully deployed, production-ready SaaS application. Now is a great time to learn more about the architecture you just deployed.

<Card title="Next: Core Concepts" icon="sitemap" href="/core-concepts/project-structure">
  Explore the architecture of LaunchKit AWS to understand how the frontend,
  backend, and infrastructure all work together.
</Card>
