Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging TypeScript AWS CDK application

Is it possible to debug an AWS CDK TypeScript application? If need for example check which value are in particular variable?

For example in Java are breakpoints. But how can i check that flow goes in the expected way, if have: if (someVariable) {...} in TypeScript code? How can check that if condition is true?

like image 636
Mikhail Politaev Avatar asked Sep 05 '25 05:09

Mikhail Politaev


2 Answers

You can debug AWS CDK applications by simply running it in the language that it is written in. This is easily doable in both Jetbrains IDE's or VSCode. Just execute the index.ts or app.py in debug mode.

The only problem is that context variables in AWS CDK are not available. I uncomment these manually while debugging.

For typescript, you execute the Javascript file and it should help you to debug to make the changes in Typescript

enter image description here

like image 193
snorberhuis Avatar answered Sep 07 '25 20:09

snorberhuis


To debug a typescript cdk app bin/<app>.ts in vscode with context variables account, region, add to .vscode/launch.json:

{
    "type": "node",
    "request": "launch",
    "name": "deploy",
    "skipFiles": [
        "<node_internals>/**"
    ],
    "runtimeArgs": [
        "-r", "./node_modules/ts-node/register/transpile-only"
    ],
    "args": [
        "${workspaceFolder}/node_modules/aws-cdk/bin/cdk.js",
        "deploy",
        "-c", "account=<id>",
        "-c", "region=<region>",
    ]
}

Let the following be the content of bin/<app>.ts. Verify that region holds the context value <id>.

import { App } from 'aws-cdk-lib';
const app: App = new App()
let region: string = app.node.tryGetContext('region')
like image 37
diogo Avatar answered Sep 07 '25 21:09

diogo