https://pulumi.com logo
#python
Title
# python
b

bulky-policeman-29913

11/24/2021, 4:16 PM
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?
s

shy-bird-55689

11/24/2021, 4:39 PM
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
  REQUIREMENTS_FILE=${PWD%/*}/source/services/$l/requirements.txt
  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/"
  fi
done
b

bulky-policeman-29913

11/24/2021, 4:40 PM
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
s

shy-bird-55689

11/24/2021, 5:00 PM
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)
b

bulky-policeman-29913

11/24/2021, 5:07 PM
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?
s

shy-bird-55689

11/24/2021, 5:12 PM
yeah when creating the resource its passed into the
code
argument
Copy code
code=pulumi.AssetArchive({
        '.': pulumi.FileArchive('build/lambdas/api-webhooks-lambda.zip')
    })
b

bulky-policeman-29913

11/24/2021, 5:14 PM
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
s

shy-bird-55689

11/24/2021, 5:20 PM
if you are splitting them out then i think the only way you can do that with pulumi will be to use layers
b

bulky-policeman-29913

11/24/2021, 5:35 PM
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!
s

shy-bird-55689

11/24/2021, 5:46 PM
👏
4 Views