https://pulumi.com logo
Title
f

fierce-rose-25366

01/24/2023, 10:38 AM
Hey all! I’m trying to run an inline program on AWS Lambda. The only writeable area of the filesystem is
/tmp/
, so I’ve set my work dir and pulumi home there.
stack = pulumi.automation.create_stack(
            "just.testing.stack",
            project_name="just.testing.project",
            program=get_bucket, # simple program that just gets the ARN of a named AWS S3 Bucket
            opts=pulumi.automation.LocalWorkspaceOptions(work_dir="/tmp/", pulumi_home="/tmp/.pulumi"))
This works fine locally and I see the yaml etc generated in my local /tmp. When I run this on Lambda though, I get
FileNotFoundError: [Errno 2] No such file or directory: 'pulumi'
This is strange to me - why is it looking for a directory named
pulumi
in the first place, when my workspace config is different? I’d love any pointers on this.
I’ve narrowed it down a bit - the failure is happening when pulumi tries to create a LocalWorkspace:
2023-01-24T12:34:51 File "/var/task/developer_utils_service.py", line 2589, in test_pulumi
2023-01-24T12:34:51 return CadenceUnsubscribeService(self).sense_check()
2023-01-24T12:34:51 File "/var/task/cadence_unsubscribe_service.py", line 112, in sense_check
2023-01-24T12:34:51 ws = pulumi.automation.LocalWorkspace(work_dir="/tmp/", pulumi_home="/tmp/.pulumi")
2023-01-24T12:34:51 File "/var/lang/lib/python3.9/site-packages/pulumi/automation/_local_workspace.py", line 125, in __init__
2023-01-24T12:34:51 pulumi_version = self._get_pulumi_version()
2023-01-24T12:34:51 File "/var/lang/lib/python3.9/site-packages/pulumi/automation/_local_workspace.py", line 411, in _get_pulumi_version
2023-01-24T12:34:51 result = self._run_pulumi_cmd_sync(["version"])
2023-01-24T12:34:51 File "/var/lang/lib/python3.9/site-packages/pulumi/automation/_local_workspace.py", line 430, in _run_pulumi_cmd_sync
2023-01-24T12:34:51 return _run_pulumi_cmd(args, self.work_dir, envs, on_output)
2023-01-24T12:34:51 File "/var/lang/lib/python3.9/site-packages/pulumi/automation/_cmd.py", line 55, in _run_pulumi_cmd
2023-01-24T12:34:51 with subprocess.Popen(
2023-01-24T12:34:51 File "/var/lang/lib/python3.9/site-packages/sentry_sdk/integrations/stdlib.py", line 193, in sentry_patched_popen_init
2023-01-24T12:34:51 rv = old_popen_init(self, *a, **kw)  # type: ignore
2023-01-24T12:34:51 File "/var/lang/lib/python3.9/subprocess.py", line 951, in __init__
2023-01-24T12:34:51 self._execute_child(args, executable, preexec_fn, close_fds,
2023-01-24T12:34:51 File "/var/lang/lib/python3.9/subprocess.py", line 1821, in _execute_child
2023-01-24T12:34:51 raise child_exception_type(errno_num, err_msg, err_filename)
Looks like the attempt to run
pulumi version
is failing. Must be something wrong in my setup?
🙂 looks like I’m missing the crucial step of installing pulumi CLI, in addition to installing the python lib
b

billowy-army-68599

01/24/2023, 3:32 PM
@fierce-rose-25366 yes, automation API requires the pulumi CLI but that includes the Pulumi engine. you can run Pulumi inside a lambda if you use the docker image support
f

fierce-rose-25366

01/24/2023, 3:43 PM
Thanks @billowy-army-68599! Yeah I’m using Docker on Lambda - I managed to get a step further by installing pulumi CLI in the docker image, but I’m now facing permission issues - looks like the lambda user isn’t able to invoke the docker CLI. Here are my various attempts at fixing this so far in my dockerfile:
# install pulumi
RUN curl -fsSL <https://get.pulumi.com> | sh

# add pulumi to path
ENV PATH="${PATH}:/root/.pulumi/bin"

# test that pulumi can run
RUN pulumi version

# make the lambda user able to execute it - NOT WORKING SO FAR
RUN chmod a+rx /root/.pulumi/bin/pulumi

RUN chmod -R a+wrx /root/.pulumi

RUN chown -R sbx_user1051 /root/.pulumi/bin/pulumi

RUN chown -R sbx_user1051 /root/.pulumi
I recognise this is mostly a lambda/docker question now rather than a pulumi one, but it’d be super helpful if you have any pointers from past experience of doing this.
b

billowy-army-68599

01/24/2023, 3:45 PM
it’s been a really long time since I did this i’m afraid 😞 I’d recommend installing into
sbx_user1051
’s home directory
f

fierce-rose-25366

01/25/2023, 2:10 PM
No worries, thanks for the pointers @billowy-army-68599 !