hey, one issue I am facing using `pulumi` is the m...
# getting-started
l
hey, one issue I am facing using
pulumi
is the my node_modules are not getting uploaded to aws
lambda
. I was wondering if anyone has solved this or point me to some kind of solution of uploading the
node-modules
as my
serverless
function keeps giving me
module not found error
g
can you share your code (with confidential info redacted)?
l
Copy code
import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
import { main } from "../src/index";

const config = new pulumi.Config();

const lambdaRole = new aws.iam.Role("lambdaRole", {
  assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({
    Service: "<http://lambda.amazonaws.com|lambda.amazonaws.com>",
  }),
});

const lambdaRolePolicy = "the policy"


const someService = new aws.lambda.CallbackFunction("service-name", {
  runtime: "nodejs14.x",
  role: lambdaRole,
  callback: main
});


const someServiceSchedule: aws.cloudwatch.EventRuleEventSubscription = aws.cloudwatch.onSchedule(
  "service-name",
  "rate(30 minutes)",
  someService,
);
g
I don't see where your function code is getting uploaded; I see the
callback: main
part, but that's not code getting uploaded. See if these docs help: https://www.pulumi.com/registry/packages/aws/api-docs/lambda/function/#basic-example
(uploading the code directory as a file archive)
l
I see. It was uploading to the lambda function. Now I have also used the file archive, but in that case, do I also have add node_modules too? or just the js mapped files?
so I did use the
file archive
method to upload the function. Even after that, it says
module not found
. Do I have to explicitly also add
node_modules
for my lambda function to work?
g
You do have to add the
node_modules
directory based on what I'm seeing in the AWS docs: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html#nodejs-package-dependencies