I'm writing an AWS Lambda using the NodeJS12.x runtime. It's fairly straightforward. It sends an email through Postmark. I know SES is an alternative, I've opted not to go that route here.
const postmark = require("postmark");
const postmarkClient = new postmark.ServerClient(process.env.POSTMARK_TOKEN);
exports.handler = function (event, context, callback) {
postmarkClient.sendEmail({
From: "some@email.address",
To: "different@email.address",
Subject: "My emails subject",
TextBody: "My emails text body"
});
}
The uploaded zip structure looks something like this:
lambda.zip:
- node_modules/
-- postmark/
-- axios/
-- other-modules/
- index.js
- package.json
When I upload that zip from my Windows machine and test the lambda, it gives me this error in my CloudWatch logs:
Error: Cannot find module './node_modules/postmark'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js
Cool. I did a good old afternoon of googling and came across, among many other things, another Stack Overflow answer for some fix for a similar problem in a linux system. Octopus suggested I ensure all the files are executable and that I own them by running these commands:
sudo chmod +x *.js -R
sudo chown myself.myself * -R
zip -r lambda.zip .
So I spun up my trusty Linux Subsystem for Windows (cause we have that now), cloned my repo, ran the commands, deployed that new zip file my AWS Lambda Function, and tested away. Voila, postmark delivered upon my inbox an email.
That's great. Windows loses to Linux again. I'm on that train. But I still work in Windows and need to develop and deploy my functions in this environment.
My two questions are as follows:
- What do I need to change to replicate these Linux actions on the Windows side of my machine?
- Why are these actions required?