Hello I have a lambda written in python I am tryin...
# python
Hello I have a lambda written in python I am trying to deploy that was originally written in Serverless framework. There was a plugin that did a few things for me 1) Dockerized pip cause I am on a Mac and therefore dependency differences if deployed to lambda would cause issues and 2) ran pip to install dependencies 3) bundled dependencies with my code. I am trying to figure out how to accomplish this with pulumi now and not finding a lot of assistance. Can anyone provide some clarity?
i currently package up my layers via a bash script. Here's and example stub that you might find useful
Copy code
for l in "${FOR_LAYERS[@]}"; do
  if [ -f $REQUIREMENTS_FILE ] && [ ! -f layers/$l-layer.zip ]; then
    docker run -v "$PWD":/var/task -v $REQUIREMENTS_FILE:/var/requirements.txt "lambci/lambda:build-python3.8" /bin/sh -c "pip install -r /var/requirements.txt -t python/lib/python3.8/site-packages/; exit"
    zip -r layers/$l-layer.zip python
    docker run -v "$PWD":/var/task "lambci/lambda:build-python3.8" /bin/sh -c "rm -rf python/"
layers huh...i was reading that you can do a /.packages folder maybe?
looks like i might be able to use lambci to spit out my zip
you could do that, can update the above stub to include the code source files as well as setting up the dependencies. I package layers separately as often there are a bunch of common dependencies across our various serives so the layer is then reused. I no longer provide a zip to pulumi to upload for the lambda itself and just point the config to the source directory (pulumi then zips it up as part of pulumi up)
makes sense
we dont have a lot of that re-use in a single account so
does pulumi not have a way to add to an existing file archive?
yeah when creating the resource its passed into the
Copy code
        '.': pulumi.FileArchive('build/lambdas/api-webhooks-lambda.zip')
right i mean if I install packages to a packages folder apparently they have to be at the root
i guess I could spit out the zip from docker
I was going to spit out just pacakges
i had it just dumping packages to my local file system might as well do it all there
if you are splitting them out then i think the only way you can do that with pulumi will be to use layers
she aint pretty but I think it will work inside docker image to spit out this zip
pip install --target ./packages -r requirements.txt && zip -r linkgen.zip ./ -x "packages/*" "tests/*" "*.DS_Store" && cd packages/ && zip -ur ../linkgen.zip ./
and profit!