Hey y’all Has anyone tried out running the Pulumi...
# typescript
h
Hey y’all Has anyone tried out running the Pulumi automation API inside an AWS lambda function. Getting an error
window is not defined
, seems to be occurring when the lambda is starting up. end of stack trace points to this line - https://github.com/pulumi/pulumi/blob/f74a5dfec10c83584e65b3535cbbc138741ba2c5/sdk/nodejs/proto/status_pb.js#L16
Copy code
{
  "errorType": "ReferenceError",
  "errorMessage": "window is not defined",
  "stack": [
    "ReferenceError: window is not defined",
    "    at file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:292090:22",
    "    at node_modules/.pnpm/@pulumi+pulumi@3.132.0_typescript@5.6.2/node_modules/@pulumi/pulumi/proto/status_pb.js (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:292091:7)",
    "    at __require2 (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:24:51)",
    "    at node_modules/.pnpm/@pulumi+pulumi@3.132.0_typescript@5.6.2/node_modules/@pulumi/pulumi/provider/server.js (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:292291:36)",
    "    at __require2 (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:24:51)",
    "    at node_modules/.pnpm/@pulumi+pulumi@3.132.0_typescript@5.6.2/node_modules/@pulumi/pulumi/provider/index.js (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:292814:15)",
    "    at __require2 (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:24:51)",
    "    at node_modules/.pnpm/@pulumi+pulumi@3.132.0_typescript@5.6.2/node_modules/@pulumi/pulumi/index.js (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:367822:33)",
    "    at __require2 (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:24:51)",
    "    at node_modules/.pnpm/@pulumi+aws@6.51.1_typescript@5.6.2/node_modules/@pulumi/aws/index.js (file:///var/task/packages/pulumi-test/src/event-handlers/function-pulumi-test.mjs:506518:19)"
  ]
}
v
window
is a browser element, it looks like there's some issue executing in AWS lambda and pulumi thinks its running in a browser, when really it should be returning
global
are you using the latest version of pulumi? also, have you checked for issues regarding this?
i've never tried it personally, but would be interested to get to the bottom of it
h
using pulumi/pulumi: 3.132.0 and pulumi/aws:6.51.1 I've looked through the issues and slack archive, there are relatable issues that I've found. This one seems close to what I'm experiencing - https://archive.pulumi.com/t/8085070/which-results-from-node-modules-pulumi-pulumi-proto-status-p#57587909-18fa-40e4-85f6-97900d91e210 From that conversation, Would I need to install the pulumi library instead of bundling it? I do have the pulumi cli available as a lambda layer attached to the lambda
v
i'd probably recommend trying executing the program via the CLI in the lambda to see if that mitigates the issue
h
alright, I'll give that a go. Appreciate the quick responses and will follow up once I have new info.
v
no problems, feel free to dm me and i'll always respond if i'm online
i've just had a read of the thread you posted, and it looks like including
window
is symptomatic of bundling. are you able to try without bundling as you suggested?
that could be a better/more lightweight mitigation
h
yeah I'll try that out as well.
c
I am trying to do the same, run Pulumi Automation in a AWS Lambda. Do you have more details on your solution?
because I got the same issue:
ReferenceError: window is not defined
h
I was able to get through the error
ReferenceError: window is not defined
with the suggestion of installing the pulumi library instead of bundling it when deploying to the AWS lambda I'm getting a new error but it looks like its a function serialization error so trying to sort that out now. @victorious-church-57397 - Thanks again for taking a look
v
awesome news, hope you manage to get to the bottom of it all!
c
@hundreds-student-32136 good news ! Could you share the code to solve the issue please 🙏 ?
Hello, I faced this same situation. Here is what I did: • Create a Lambda function using a container image • Exclude pulumi from esbuild by marking dependencies as external:
esbuild --external:@pulumi/pulumi --external:@pulumi/aws
• Install pulumi in Docker
Copy code
FROM base AS pulumi-install
RUN curl -fsSL <https://get.pulumi.com/> | bash -s -- --version 3.137.0
• Install the pulumi nodejs dependencies
Copy code
RUN pnpm install -w @pulumi/pulumi
RUN pnpm install -w @pulumi/aws
Additional points: • set PULUMI_HOME, can be in Docker like
ENV PULUMI_HOME="/tmp"
• increase Ephemeral storage in Lambda: 512 MB is not enough. 3072 MB is better to install pulumi and plugins • increase lambda memory to 2048 MB That's all folks 😉