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

2

12

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! :)

Choroiditis answered 15/10, 2019 at 0:20 Comment(0)
C
10

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 :)

Choroiditis answered 15/10, 2019 at 4:28 Comment(1)
I ran into an error running npm install @types/console so I ran npm install console instead and it worked for me.Gillard
M
1

Hi I was also facing the same issue. I run "npm install @types/node --save-dev". This solved my problem and I am able to see the console.log() during cdk.synth

Mefford answered 3/10, 2020 at 22:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.