serverless-python-requirements icon indicating copy to clipboard operation
serverless-python-requirements copied to clipboard

Per-Function Individually:true generates 2 zip files

Open thefiend opened this issue 3 years ago • 2 comments

Folder Structure

- function1/
---- function1.py
- function2/
---- function2.py
---- requirements.txt
- app_function2.py
- app_function1.py
- serverless.yml
- requirements.txt

serverless.yml

service: service-api
package:
  individually: true
  exclude:
    - "*/**"
    - "**"
custom:
  pythonRequirements:
    dockerizePip: non-linux
    noDeploy: []
    slim: false
    useDownloadCache: false
    useStaticCache: false
    usePipenv: false
  env: ${file(env.yml):${self:provider.stage}}
provider:
  name: aws
  stage: ${opt:stage, 'dev'}
  region: ${opt:region, 'ap-southeast-1'}
  runtime: python3.7
  memorySize: 128
  endpointType: regional
  vpc:
    subnetIds:
      - ${self:custom.env.SUBNET_1}
      - ${self:custom.env.SUBNET_2}
  role: ${self:custom.env.ROLE}
  environment:
    API_SERVER: "${self:custom.env.API_SERVER}"
    API_PORT: "${self:custom.env.API_PORT}"
    DEBUG: "${self:custom.env.DEBUG}"
    S3_BUCKET: "${self:custom.env.S3_BUCKET}"
  resourcePolicy:
    - Effect: Allow
      Principal: "*"
      Action: execute-api:Invoke
      Resource:
        - execute-api:/*/*/*
plugins:
  - serverless-python-requirements
  - serverless-offline
functions:
  function1:
    package:
      include:
        - ./function1/**
        - ./app_function1.py
    handler: app_function1.handler
  function2:
    module: ./function2
    package:
      include:
        - ./function2/**
        - ./app_function2.py
    handler: app_function2.handler

It generates 2 zips for function2 in the .serverless folder (one with the source code and the other with all the requirements.txt files) but when tested the Lambda function, it states "Import Error: No function2.py found.".

thefiend avatar Sep 17 '20 11:09 thefiend

Come across a similar issue while trying to setup packaging per-function. Instead of two zip files, serverless package results in:

function.zip  # contains code but no dependencies
function/     # contains the dependencies in a requirements/ folder, but nothing else

I've had to perform an extra zip step to obtain a working function.zip:

DIR=$PWD
(cd .serverless/anatomy/requirements && zip -gr $DIR/.serverless/anatomy.zip .)

ahmedaljawahiry avatar Sep 17 '21 11:09 ahmedaljawahiry

Hello @ahmedaljawahiry :wave: Do you by any chance have the reproducible example?

pgrzesik avatar Sep 30 '21 09:09 pgrzesik