Paste a CDK v2 stack written in Python and get TypeScript back: aws-cdk-lib imports, props objects with camelCase keys and this in place of self. Construct IDs are copied exactly, so the template can match what you deployed from Python.
This looks like it contains a secret.
Your code is sent to an AI service for conversion. Replace real keys and tokens with placeholders before converting.
How to convert a CDK app from Python to TypeScript
To convert an AWS CDK app from Python to TypeScript, paste a stack into the editor above and press Convert to TypeScript. Keyword arguments are gathered into one props object with camelCase keys, self becomes this and each from aws_cdk import becomes an aws-cdk-lib import. Put the result in a TypeScript CDK app, run tsc and check cdk diff.
Add your Python stackPaste a stack into the AWS CDK (Python) editor, use Open file for a .py or .txt file up to 500 KB, or drop a file onto the editor. Sample loads an S3 bucket, a Lambda function and a nightly EventBridge schedule.
Let the secret check runThe page scans for AWS access keys, secret keys, private keys and common API tokens before sending anything, and points out any it finds so you can swap in a placeholder.
Convert to TypeScriptClick Convert to TypeScript or press Ctrl + Enter. The result streams in as it's written, and Stop cancels it. Each conversion takes up to 60,000 characters.
Review the TypeScriptCompare construct IDs with the original and look for TODO: comments marking Python code with no direct TypeScript form. Copy the result or Download it as stack.ts.
Compile and diffCreate a project with cdk init app --language typescript, put the stack in lib/ and instantiate it from the file in bin/. Run npx tsc --noEmit, then cdk diff against the deployed stack.
From Python stack to a type-checked TypeScript app, with cdk diff as the final check.
Why move a CDK app from Python to TypeScript
TypeScript is the language the CDK itself is written in, and every jsii construct library is authored in it. The compiler checks each prop name, type and enum value while you edit. In Python, a misspelled keyword argument or enum member only fails when cdk synth runs the app, and some mistakes, such as passing the wrong kind of value, can get further than that.
Teams also switch when their application code is already TypeScript, such as a Node.js API or a frontend deployed with the CDK. One language, one package manager and one test runner then cover both the app and its infrastructure.
Both languages use the same aws-cdk-lib, so your architecture doesn't change. Converting by hand means regrouping every keyword argument into an object and renaming every method and property. The converter does that for a full stack file, which leaves your review time for construct IDs and custom helpers. Going the other way? Use the CDK TypeScript to Python converter.
The same typo, caught at different times. TypeScript reports it before the app ever runs.
Moving CDK code from Python to TypeScript
TypeScript is the CDK's native language, so every construct your Python app uses has a direct TypeScript equivalent. Keyword arguments such as removal_policy=RemovalPolicy.RETAIN become props objects like { removalPolicy: RemovalPolicy.RETAIN }, self becomes this, and from aws_cdk import aws_s3 as s3 becomes import * as s3 from "aws-cdk-lib/aws-s3".
As long as the stack names and construct IDs stay the same, the synthesized CloudFormation template matches the one you deployed from Python, and cdk diff shows no resource changes.
Set the project up with cdk init app --language typescript, then copy the converted stack into lib/. AWS's guide to working with CDK in TypeScript covers the build and cdk.json details.
Keyword arguments are collected into a single props object, the third argument of every construct.
Where Python and TypeScript CDK code differ
The language-level differences to expect in the converted code. Construct classes and enums keep their names in both.
Python CDK code compared with TypeScript CDK code
Topic
Python
TypeScript
Construct arguments
Keyword arguments after the scope and ID
One props object as the third argument
Missing values
None
undefined, or leave the key out
Booleans
True, False
true, false
Struct values
s3.LifecycleRule(prefix="raw/")
{ prefix: "raw/" } object literal
Custom stack props
Keyword-only parameters: *, queue_name: str
interface QueueStackProps extends StackProps
Type checking
Type hints are optional and not enforced at synth
Checked by tsc before the app runs
Dependencies
requirements.txt with aws-cdk-lib and constructs
package.json with aws-cdk-lib and constructs
Entry point
app.py, run by python3 app.py
bin/app.ts, run by npx ts-node --prefer-ts-exts bin/app.ts
Tests
pytest with Template.from_stack
Jest with Template.fromStack
Key features
Keyword arguments regroupedEvery keyword argument after the scope and ID moves into one props object, with camelCase keys that the TypeScript types expect.
Imports rewritten for aws-cdk-libfrom aws_cdk import aws_s3 as s3 becomes import * as s3 from "aws-cdk-lib/aws-s3", and aliases like lambda_ go back to lambda.
camelCase methods and propertiesgrant_write, bucket_name and from_asset become grantWrite, bucketName and fromAsset.
Typed stack constructorsStacks get the standard (scope: Construct, id: string, props?: StackProps) signature, so the compiler can check how they're used.
Construct IDs copied exactlyIDs stay as written, even when they don't look like TypeScript names, because changing them would replace resources.
Untranslatable code flaggedComments carry over, and anything without a direct TypeScript equivalent gets a TODO: comment.
Checked, streamed and downloadableKeys are detected in your browser before sending, the result streams in with a Stop button, and you can save it as stack.ts.
Free, with no signupConvert right away. A free account raises your limits and lists recent conversions on your dashboard.
Examples: CDK Python converted to TypeScript
Three stacks that show how Python idioms map to TypeScript ones. Choose Try this example to load the Python into the converter. The TypeScript shown is what correct output looks like; yours may be formatted differently.
DynamoDB table with a global secondary index
Struct classes such as dynamodb.Attribute(...) become plain object literals, and a method's keyword arguments become a single options object.
AWS CDK (Python)
from aws_cdk import Stack, RemovalPolicy
from aws_cdk import aws_dynamodb as dynamodb
from constructs import Construct
class UsersStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
table = dynamodb.Table(
self, "Users",
partition_key=dynamodb.Attribute(name="userId", type=dynamodb.AttributeType.STRING),
billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
removal_policy=RemovalPolicy.RETAIN,
)
table.add_global_secondary_index(
index_name="byEmail",
partition_key=dynamodb.Attribute(name="email", type=dynamodb.AttributeType.STRING),
)
Keyword-only parameters on a Python stack become a props interface that extends StackProps, and a Python default value becomes an optional prop with a fallback.
AWS CDK (Python)
from aws_cdk import App, Stack
from aws_cdk import aws_sqs as sqs
from constructs import Construct
class QueueStack(Stack):
def __init__(
self, scope: Construct, construct_id: str, *, queue_name: str, fifo: bool = False, **kwargs
) -> None:
super().__init__(scope, construct_id, **kwargs)
sqs.Queue(self, "Jobs", queue_name=queue_name, fifo=fifo)
app = App()
QueueStack(app, "JobsStack", queue_name="jobs.fifo", fifo=True)
app.synth()
AWS CDK (TypeScript)
import { App, Stack, StackProps } from "aws-cdk-lib";
import * as sqs from "aws-cdk-lib/aws-sqs";
import { Construct } from "constructs";
interface QueueStackProps extends StackProps {
queueName: string;
fifo?: boolean;
}
export class QueueStack extends Stack {
constructor(scope: Construct, id: string, props: QueueStackProps) {
super(scope, id, props);
new sqs.Queue(this, "Jobs", { queueName: props.queueName, fifo: props.fifo ?? false });
}
}
const app = new App();
new QueueStack(app, "JobsStack", { queueName: "jobs.fifo", fifo: true });
Lambda worker fed by an SQS queue
Only the infrastructure code changes language. The function still runs on the Python runtime with the same handler and asset folder.
AWS CDK (Python)
from aws_cdk import Stack, Duration
from aws_cdk import aws_lambda as lambda_
from aws_cdk import aws_sqs as sqs
from aws_cdk.aws_lambda_event_sources import SqsEventSource
from constructs import Construct
class WorkerStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
queue = sqs.Queue(self, "Tasks", visibility_timeout=Duration.minutes(2))
worker = lambda_.Function(
self, "TaskWorker",
runtime=lambda_.Runtime.PYTHON_3_12,
handler="worker.handler",
code=lambda_.Code.from_asset("worker"),
timeout=Duration.minutes(1),
environment={"QUEUE_URL": queue.queue_url},
)
worker.add_event_source(SqsEventSource(queue, batch_size=5))
AWS CDK (TypeScript)
import { Stack, StackProps, Duration } from "aws-cdk-lib";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as sqs from "aws-cdk-lib/aws-sqs";
import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
import { Construct } from "constructs";
export class WorkerStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const queue = new sqs.Queue(this, "Tasks", { visibilityTimeout: Duration.minutes(2) });
const worker = new lambda.Function(this, "TaskWorker", {
runtime: lambda.Runtime.PYTHON_3_12,
handler: "worker.handler",
code: lambda.Code.fromAsset("worker"),
timeout: Duration.minutes(1),
environment: { QUEUE_URL: queue.queueUrl },
});
worker.addEventSource(new SqsEventSource(queue, { batchSize: 5 }));
}
}
Tips for better results
Keep construct IDs identical."NightlyReport" must stay "NightlyReport", or CloudFormation sees a new resource and replaces the old one.
Let the compiler help. Run npx tsc --noEmit after converting. Wrong prop names and missing required props show up as type errors.
Convert helper modules too. Python helpers that build construct props need their own TypeScript versions, so paste them separately.
Check Duration and enum calls.Duration.minutes(5) is the same in both languages, but Python-only helpers must be replaced.
Confirm with cdk diff. Once cdk.json runs the TypeScript app, the diff against the deployed stack should be empty.
Common mistakes when moving CDK to TypeScript
Renaming IDs to look like TypeScript. An ID such as "reports_bucket" is just a string. Leave it as it is, even if it doesn't match your new naming style.
Leaving out new. Every construct is a class, so TypeScript needs new s3.Bucket(...). tsc reports any call that's missing it.
Keeping snake_case keys.removal_policy isn't a known prop in a TypeScript props object, so the compiler rejects it. Every key must be camelCase.
Rewriting the Lambda code as well. Only the infrastructure moves to TypeScript. Keep Runtime.PYTHON_3_12 and the asset path if the function itself stays in Python.
Translating is None checks literally. Optional props are undefined in TypeScript. Use props.name ?? "default" rather than comparing with null.
Frequently asked questions
How do I convert AWS CDK Python code to TypeScript?
Paste a Python stack into the converter at the top of this page and press Convert to TypeScript. Keyword arguments become props objects with camelCase keys, self becomes this and imports move to aws-cdk-lib. Put the result in a TypeScript CDK app, run npx tsc --noEmit, then check cdk diff.
Will moving the CDK app to TypeScript redeploy my resources?
Each construct's keyword arguments become a single props object with camelCase keys. For example, timeout=Duration.minutes(5) becomes timeout: Duration.minutes(5) inside the props.
Do I need to call app.synth() in TypeScript?
The default TypeScript template doesn't call it, because the CDK CLI synthesizes the app when it runs. Leaving a call in is harmless.
What command does cdk.json run for TypeScript?
The default template runs the entry file in bin/ with ts-node, for example npx ts-node --prefer-ts-exts bin/app.ts. Update cdk.json to point at your new entry file.
Do I need to rewrite my Python Lambda functions?
No. The converter changes the infrastructure code only. A function defined with Runtime.PYTHON_3_12 and a Python asset folder keeps running Python after the CDK app moves to TypeScript.
Can Python and TypeScript stacks live in one CDK app?
No. A CDK app runs as a single program in one language. You can keep two separate apps during a migration and share values between their stacks through CloudFormation exports or SSM parameters.
Is my code stored?
No. Your code is sent to an AI model hosted on NVIDIA's API only to produce the conversion, and ChatWithCloud doesn't store or log it. Your latest draft is kept only in your browser. For the full picture, see whether it's safe to paste AWS code into an AI converter.
Is the converter free?
Yes. Without an account you can run 6 conversions a minute and 60 a day. A free account raises that to 12 a minute and 200 a day and lists your recent conversions on your dashboard. The guide to ChatWithCloud free converter limits shows how far they stretch for a real migration.