Problem: my zipped deployment folder that contains my python code is too big!
I looked inside and there’s stuff in there that should be ignored according to my .gitignore
Here is the contents of the (too-big) zipped folder that is deployed to S3
(I DL it from S3 and unzipped the contents)
I should note that my service project is nested one level below another service project, like so…
-root
—main.project.with.own.deployment
------my.project.with.big.zip
---------.gitignore
---------handler.py
--------etc…
What I do most recently is use gulp to build a deployment folder containing all my files/folders. Then within that folder is what I actually deploy. This allows me to have more processes in place for CI/CD.
We a single serverless.yml that contains a bunch of resources and 4 python lambdas. Each lambda needed a different set of python libraries and pre-compiled binaries. I found the best way to hald this was to “package individually” and exclude everything:
package:
individually: true
exclude:
- ".*/**"
Then in each lambda, include only the binaries/libs I needed. e.g.,
With the new release, include and exclude are depreciated and will be removed completely in future releases. Please adhere to
patterns
Here is an example:
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: python-sls-test
frameworkVersion: '3'
configValidationMode: error
custom:
SERVICE_NAME: ${env:SERV_NAME, 'python-default'}
REGION: ${env:AWS_REGION, 'us-east-1'}
provider:
name: aws
runtime: python3.9
stage: ${opt:stage, 'dev'}
region: us-east-1
deploymentMethod: direct
memorySize: 512
deploymentPrefix: serverless
deploymentBucket:
name: sls-vj-deploy
maxPreviousDeploymentArtifacts: 3
# you can add packaging information here
package:
patterns:
- '!exclude-me.py'
- '!venv/**'
- '!README.md'
- '!build/**'
# Package each function individually
individually: true
functions:
testFunction:
handler: lambdas/handler.test
package:
patterns:
- lambdas/**