AWS CDK — Cannot find module ‘@aws-cdk/aws-ec2’

Question:

I just started playing around with AWS CDK yesterday and I found something very weird.

First of all, I’m using TypeScript for my CDK app (I used cdk init --language typescript to generate the project files and I tried to import aws-ec2 module so this is what I did:

However, when importing the aws-ec2 module this way, I got this error when trying to deploy the stack:

This is very weird because the API docs right here clearly stated that this is how I should import the aws-ec2 module in TypeScript

Answer:

You need to install the node package before you could import and use it

Execute below on the command line to install npm package for aws-cdk

Leave a Reply