https://pulumi.com logo
Title
f

fresh-spring-82225

01/31/2023, 9:51 PM
I've been starting with pulumi programs in typescript, but I have a lambda that needs to be in python to take advantage of a particular 3p library. Does anyone know if I can deploy a lambda written in python from a pulumi program written in typescript?
l

little-cartoon-10569

01/31/2023, 9:54 PM
Yes. There's no problem here.
It's just a file that gets uploaded.
It's probably worth building the lambda zip before running the Pulumi program. If you can depend on the zip existing, your Pulumi code becomes much simpler.
f

fresh-spring-82225

01/31/2023, 9:56 PM
ahah, that was my next question
l

little-cartoon-10569

01/31/2023, 9:57 PM
You can do it from Pulumi, but then you have to manage pre-deploy code carefully. There are mixins in Pulumi for this, but I find them less than helpful, because they conflate pre-deploy and in-deploy logic.
Which is a bit head-wrecking.
f

fresh-spring-82225

01/31/2023, 9:58 PM
Thanks!
m

miniature-musician-31262

01/31/2023, 9:59 PM
If you did want to do it in Pulumi, it might look something like this — this example is written in Python and zips up a Python function, but the TS program code would be structurally the same: https://github.com/pulumi/templates/blob/master/serverless-aws-python/__main__.py#L21-L25
l

little-cartoon-10569

01/31/2023, 10:02 PM
That uses FileArchive to create a zip of a directory. It's a great example, but it doesn't deal with the problem of dependencies. Is there another example of a Python lambda with some dependent packages?
o

orange-policeman-59119

01/31/2023, 11:59 PM
You could use the Pulumi Command provider inside the program, or a build step (makefile, npm script, etc.) run before
pulumi up
to run steps like in AWS' docs: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-create-package-with-dependency e.g.: (pseudocode)
const packageDeps = new command.local.run({
  "command": "pip install ... && zip -r ../my-deployment-package.zip . && ...",
  "dir": "./function",
});
I'm using https://www.pulumi.com/registry/packages/command/api-docs/local/run/ here because it will run on every execution, but it will run on preview and deploy.
g

great-sunset-355

02/01/2023, 1:12 PM
I got bitten by uploading
.zip
with python several times (depend on packages) so in my case, I prefer building docker images with python instead. Docker build flow is well integrated in pulumi as well.