I'm trying to create a CloudWatch Synthetics Canary in AWS using terraform, and I'm able to create it fine, but it instantly fails with this message:
Error: Cannot find module '/opt/nodejs/node_modules/exports'
I'm new to Synthetics, Node.js and terraform, so it's a perfect storm, but I feel i'm missing some knowledge. I read that the node.js file needs to be in a folder structure of
my_canary_folder > nodejs > node_modules > my_nodejs_zipfile.zip
but when I created that as instructed , it was empty and didn't work, instead producing that error.
I presumed I had to install nodejs on my MacOS, so I ran npm install
which created the package.json file but didn't create the node_modules
folder. I've tried a number of different combinations of npm init, sudo npm init, sudo npm install
but I can't get the node_modules folder to create so the canary keeps failing. I think I expected that installing nodejs would add some content to the node_modules
folder, but nothing has happened
Does anyone know what I need to do here to get it to run here please?
Here is my main.tf snippet in case this is useful:
resource "aws_synthetics_canary" "portal_test" {
name = "portal_load"
artifact_s3_location = "${var.artifact_location}"
execution_role_arn = "${aws_iam_role.cloudwatch_synthetics_role.arn}"
handler = "exports.handler"
runtime_version = "syn-nodejs-puppeteer-3.6"
zip_file = "nodejs/node_modules/portal_load.zip"
success_retention_period = 31
start_canary = true
}
I've followed a lot of the answers in this link, but nothing seems to work: npm install doesn't create node_modules directory
When I run npm install node
in the application root directory, even with sudo, it creates the package.json
, but not the node_modules folder. I've seen talk of the node_modules
relating to the dependencies section of the package.json
, but I can't find anything that relates to what is required for AWS CloudWatch. I've tried npm i
as well, but the message coming back says that everything has installed ok, but yet still no node_modules
folder