https://pulumi.com logo
Title
b

breezy-butcher-78604

04/07/2020, 7:59 AM
i’m attempting to create some AWS lambdas with pulumi however I’m having some trouble. my pulumi project is configured so the source code is in
src/
rather than in the top level dir. my function definition looks like this:
const myFunction = new aws.serverless.Function("my-func", {
    callback: (a, b, c) => { console.log(a,b,c); }
});
but when i run
pulumi up
i get the following error:
Error reading file '<path-to-project>/src/package.json' when computing package dependencies. Error: ENOENT: no such file or directory, open '<path-to-project>/src/package.json'
is there a way I can get pulumi to look up a directory? or is there a way i can define a function inline without it having to check the package.json?
s

stocky-island-3676

04/07/2020, 8:01 AM
@breezy-butcher-78604 Why not simply running
pulumi up
in
src/
working-directory?
b

breezy-butcher-78604

04/07/2020, 8:02 AM
because the
Pulumi.yaml
file is not in that directory
my dir structure is as follows:
src/
  index.ts
config/
  Pulumi.dev.yaml
  Pulumi.prod.yaml
Pulumi.yaml
package.json
package-lock.json
s

stocky-island-3676

04/07/2020, 8:04 AM
Aha. Do you have set
"main": "src/index"
in the
package.json
? No
tsconfig.json
?
b

breezy-butcher-78604

04/07/2020, 8:09 AM
i don’t have
main
set in package.json, and I do have a
tsconfig.json
file but chose to omit it from the above for simplicity
pulumi itself functions fine, i can create resources fine, this appears to be a problem with the function serialisation functionality requiring a package.json to be in the same dir as the template code
s

stocky-island-3676

04/07/2020, 8:11 AM
Ah, I see. So, then I can’t help you on this. Sorry. Best you check in the code in
pulumi-aws
.
g

gentle-diamond-70147

04/07/2020, 5:28 PM
You can specify the entrypoint in your
Pulumi.yaml
in a similar manner to package.json:
main: src/
I believe that should do it.
b

breezy-butcher-78604

04/08/2020, 1:39 AM
i’ve already got that in my
Pulumi.yaml
file, the problem isn’t that pulumi cant find the index.ts, its that when it goes to create the
myFunc
resource, it needs to serialise the code in
callback
. I assume part of that process involves reading a
package.json
file to figure out what dependencies to package with it.
since there’s no
package.json
file in
src
(since there are no dependencies) it seems to fail.
g

gentle-diamond-70147

04/08/2020, 2:32 AM
Gotcha. I was thinking setting that in
Pulumi.yaml
would help. Can you open an isssue at https://github.com/pulumi/pulumi-aws with code to reproduce it?
b

breezy-butcher-78604

04/08/2020, 2:33 AM
sure thing
f

faint-table-42725

04/08/2020, 3:54 AM
@breezy-butcher-78604 I replied to the issue with a modification for what I think you’re trying to accomplish
If that’s not quite right, let me know
b

breezy-butcher-78604

04/08/2020, 4:09 AM
that seems to work, but it now means any paths i use in the template are now relative to the top-level dir. not a huge issue though
thanks Lee
👍 1