I've been starting with pulumi programs in typescr...
# aws
f
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
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
ahah, that was my next question
l
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
Thanks!
m
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
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
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)
Copy code
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
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.