Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output AWS CDK synth to terminal/web browser [if possible]

FYI, just want to let you guys know that I'm writing this AWS CDK app with:

  • TypeScript
  • I'm using a Macbook to write the app,running macOS Mojave 10.14.6.
  • my node version is 10.16.3
  • NPM version is 6.9.0
  • My AWS CDK version is 1.10.0 (build 19ae072). I got this detail by running cdk --version on my bash terminal

Problem definition

Hi everyone, I'm very VERY new to AWS CDK and currently I'm still playing around with it. So far I feel like it definitely offers so much more flexibility compared to typing cloudformation template.

However, one thing that I can't figure out is how to output values of a variable just like System.println() in Java or console.log in JavaScript

What I've tried so far

Now, I'm very new to TypeScript but so far I've tried using console.log() command in one of the TypeScript files and it just doesn't allow me to use it:

Everytime I try to do this:

console.log(name); //name is a string

I get this in visual studio:

enter image description here

It honestly doesn't help that I'm very new to TypeScript as well so that also comes into play with me having difficulty learning AWS CDK (but still, I'm loving it so far)

I already have the console node module installed in the cdk app project folder ./node_modules right here:

enter image description here

~Any help would be greatly appreciated~

Thanks so much in advance! :)

like image 910
blue2609 Avatar asked Oct 15 '19 00:10

blue2609


1 Answers

I found out a way to do it, it's all good now.

Basically you can use console.log(name) in order to print out to terminal when doing cdk synth but there are 2 things I need to do before I can use it.

1.) I need to have import console = require('console'); at the top of the TypeScript file

2.) I need run npm install @types/console to fix some errors regarding the console being of any type

Anyway, it's all fixed now :)

like image 175
blue2609 Avatar answered Oct 14 '22 12:10

blue2609