Skip to main content
Backdrift generates standard AWS CDK (Cloud Development Kit) code. You can export this code and deploy it yourself, modify it, or use it as a learning resource.

What is CDK?

AWS CDK is an open-source framework that lets you define cloud infrastructure using programming languages. Backdrift generates Python CDK code.

Export the CDK Project

From the Artifacts tab, click Export CDK to download a ZIP file containing:
cdk-project/
├── app.py                    # CDK app entry point
├── requirements.txt          # Python dependencies
├── cdk.json                  # CDK configuration
├── stacks/
│   ├── cognito_stack.py      # Authentication
│   ├── dynamodb_stack.py     # Database tables
│   ├── lambda_stack.py       # API handlers
│   ├── api_gateway_stack.py  # REST API
│   ├── eventbridge_stack.py  # Scheduled jobs
│   ├── sqs_stack.py          # Async queues
│   ├── ses_stack.py          # Email
│   ├── s3_stack.py           # File storage
│   └── cloudwatch_stack.py   # Monitoring
├── handlers/
│   ├── crud.py               # CRUD operations
│   ├── health.py             # Health check
│   ├── authorizer.py         # JWT validation
│   └── jobs/                 # Job handlers
└── README.md                 # Deployment instructions

Deploy Yourself

Prerequisites

  • Python 3.9+
  • AWS CLI configured with credentials
  • AWS CDK CLI installed

Steps

# Unzip the export
unzip cdk-export.zip
cd cdk-project

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # Linux/Mac
# or: .venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

# Bootstrap CDK (first time only)
cdk bootstrap

# Preview changes
cdk diff

# Deploy
cdk deploy --all

Why Export?

No Lock-in

Your infrastructure is standard AWS resources. Take it with you anytime.

Customization

Modify the generated code to add features Backdrift doesn’t support yet.

Learning

Study how production infrastructure is built with CDK.

CI/CD Integration

Integrate with your existing deployment pipelines.

What’s Generated

Cognito Stack

# User Pool with password policies
user_pool = cognito.UserPool(
    self, "UserPool",
    user_pool_name=f"{project_name}-users",
    self_sign_up_enabled=True,
    password_policy=cognito.PasswordPolicy(
        min_length=8,
        require_lowercase=True,
        require_uppercase=True,
        require_digits=True,
    ),
)

DynamoDB Stack

# Table for each entity with GSIs
tasks_table = dynamodb.Table(
    self, "TasksTable",
    table_name=f"{project_name}-tasks",
    partition_key=dynamodb.Attribute(
        name="id",
        type=dynamodb.AttributeType.STRING
    ),
    billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
    point_in_time_recovery=True,
)

# Global Secondary Index for tenant queries
tasks_table.add_global_secondary_index(
    index_name="by-org",
    partition_key=dynamodb.Attribute(
        name="org_id",
        type=dynamodb.AttributeType.STRING
    ),
)

Lambda Stack

# CRUD handlers with proper IAM permissions
create_task = lambda_.Function(
    self, "CreateTask",
    runtime=lambda_.Runtime.PYTHON_3_11,
    handler="crud.create_handler",
    code=lambda_.Code.from_asset("handlers"),
    environment={
        "TABLE_NAME": tasks_table.table_name,
    },
)
tasks_table.grant_write_data(create_task)

Modifying the Export

Common modifications:

Add a VPC

from aws_cdk import aws_ec2 as ec2

vpc = ec2.Vpc(self, "ApiVpc", max_azs=2)

# Update Lambda to run in VPC
create_task = lambda_.Function(
    self, "CreateTask",
    vpc=vpc,
    vpc_subnets=ec2.SubnetSelection(
        subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS
    ),
    # ... rest of config
)

Add Custom Domain

from aws_cdk import aws_route53 as route53
from aws_cdk import aws_certificatemanager as acm

certificate = acm.Certificate(
    self, "ApiCert",
    domain_name="api.example.com",
    validation=acm.CertificateValidation.from_dns(hosted_zone)
)

api.add_domain_name(
    "CustomDomain",
    domain_name="api.example.com",
    certificate=certificate
)

Add WAF

from aws_cdk import aws_wafv2 as waf

web_acl = waf.CfnWebACL(
    self, "ApiWaf",
    scope="REGIONAL",
    # ... WAF rules
)

Stack Dependencies

The CDK project respects dependencies between stacks:
cognito_stack

dynamodb_stack

lambda_stack ← depends on tables and auth

api_gateway_stack ← depends on Lambda functions

amplify_stack ← depends on API URL

Admin Dashboard

Learn about managing your deployed infrastructure.