Skip to main content

AWS Infrastructure with CDKTF (Python)

This project uses the Cloud Development Kit for Terraform (CDKTF) with Python to define and deploy AWS infrastructure using named AWS profiles via ~/.aws/credentials and ~/.aws/config.


✅ Prerequisites

1. Install Required Tools

Make sure the following tools are installed:

  • Node.js (v16 or later)
  • npm
  • Terraform CLI
  • Python 3.7+
  • AWS CLI

macOS Example:

brew install node
brew install terraform
brew install python
brew install awscli

2. Install CDKTF CLI

npm install -g cdktf-cli

3a. Configure AWS CLI (Option 1 - Use AWS Provided Tooling)

aws configure --profile myprofile

This creates or updates the following files:

~/.aws/credentials:

[myprofile]
aws_access_key_id=YOUR_ACCESS_KEY
aws_secret_access_key=YOUR_SECRET_KEY

~/.aws/config:

[profile myprofile]
region=us-west-2
output=json

3b - 1. Clone the code repo from Fahad Zain Jawaid

git clone https://github.com/fahadzainjawaid/awsIdentityTools

You can follow the ReadMe on the repo above to get latest usage and setup guides.


🚀 Getting Started

1. Install the package

pip install pip install BBAWSLightsailMiniV1a

2. Set Up Python Environment & Install Dependencies

python3 -m venv .venv
source .venv/bin/activate
export PIPENV_VERBOSITY=-1
pip install -r requirements.txt

3. Install AWS Provider Bindings

cdktf get

4. Synthesize Terraform Configuration

cdktf synth

5. Review the Plan

cdktf plan

6. Deploy the Infrastructure

cdktf deploy

7. Destroy the Infrastructure (if needed)

cdktf destroy

✅ ArchitectureMaker Usage

The preferred entrypoint is ArchitectureMaker, which builds stacks from a simple definition dict. Examples are mirrored in the samples directory.

Container + Database (default)

from BuzzerboyAWSLightsailStack import ArchitectureMaker

definition = {
    "product": "bb",
    "name": "sample-container-db",
    "tier": "dev",
    "organization": "buzzerboy",
    "region": "us-east-1",
}

ArchitectureMaker.auto_main(definition, include_compliance=False)

Container Only

from BuzzerboyAWSLightsailStack import ArchitectureMaker

definition = {
    "product": "bb",
    "name": "sample-container",
    "tier": "dev",
    "organization": "buzzerboy",
    "region": "us-east-1",
}

ArchitectureMaker.auto_main_container_only(definition, include_compliance=False)

Database Only

from BuzzerboyAWSLightsailStack import ArchitectureMaker

definition = {
    "product": "bb",
    "name": "sample-db",
    "tier": "dev",
    "organization": "buzzerboy",
    "region": "us-east-1",
    "databases": ["app_db", "analytics_db", "logging_db", "audit_db"],
}

ArchitectureMaker.auto_stack_db_only(definition, include_compliance=False)

Example cdktf.json

{
  "language": "python",
  "app": "python main.py",
  "projectId": "9bad9bb7-b21d-4513-9ce9-74a6e2f7e0d9",
  "sendCrashReports": "true",
  "terraformProviders": [
    "aws@~> 5.0",
    "random@~> 3.5",
    "null@~> 3.2"
  ],
  "terraformModules": [],
  "codeMakerOutput": "imports",
  "context": {}
}

Example requirements.txt

cdktf>=0.17.0,<1.0
constructs>=10.0.0,<11.0
cdktf-cdktf-provider-aws>=12.0.0
cdktf-cdktf-provider-random>=8.0.0
cdktf-cdktf-provider-null>=9.0.0
-e ../../BuzzerboyAWSLightsail

Sample Paths

  • samples/ContainerAndDB
  • samples/ContainerOnly
  • samples/DBOnly

🛠 Useful Commands

Command Description
cdktf get Install provider bindings
cdktf synth Generate Terraform JSON config
cdktf plan Preview planned changes
cdktf deploy Deploy infrastructure to AWS
cdktf destroy Destroy deployed infrastructure

📁 .gitignore Suggestions

.venv/
cdktf.out/
.terraform/
__pycache__/
*.pyc

📝 Notes

  • To install additional Python packages:

    pip install <package>
    pip freeze > requirements.txt
    
  • To suppress pipenv verbosity in environments where pipenv is used:

    export PIPENV_VERBOSITY=-1
    

📚 References

Metadata

Release files for BuzzerboyAWSLightsail 0.336.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BuzzerboyAWSLightsail 0.336.1
File Size Uploaded
buzzerboyawslightsail-0.336.1.tar.gz 19.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for BuzzerboyAWSLightsail 0.336.1
File Interpreter ABI Platform
buzzerboyawslightsail-0.336.1-py3-none-any.whl Python 3 none any Details

Total release size: 45.8 kB

Release files / buzzerboyawslightsail-0.336.1.tar.gz

Download URL buzzerboyawslightsail-0.336.1.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9d89f40c9c34f51b8e788db328e6b94800c7aee9507d0d30825709538669fd0b
BLAKE2b-256 checksum
How to use checksums
c1d57f421ec28de0a6614ad6d01729371528757816058680b1de900d54410966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.14.2

Release files / buzzerboyawslightsail-0.336.1-py3-none-any.whl

Download URL buzzerboyawslightsail-0.336.1-py3-none-any.whl
Size 26.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90f7405821934792ae9d79185b8ab5731b8780be722c022c13e786d9de19748b
BLAKE2b-256 checksum
How to use checksums
568d7a7cb4ec5d5f20c1827deddb90b207adfc182e3b9381f6b8f6bbb65cca8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.336.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page