question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Lambda Python): pipenv support broken

See original GitHub issue

Describe the bug

Building a python lambda which use pipenv to handle its dependencies fails

Expected Behavior

It’s creates and deploy the lambda with its correct dependencies

Current Behavior

During the build of the lambda in docker, the step which creates the requirements.txt from the Pipfile fails.

The command pipenv lock -r > requirements.txt fails because it no more exists since pipenv v2022.8.13

Sending build context to Docker daemon  47.62kB                                                                                                                                                                    
Step 1/11 : ARG IMAGE=amazon/aws-sam-cli-build-image-python3.7                                                                                                                                                     
Step 2/11 : FROM $IMAGE                                                                                                                                                                                            
 ---> 99b28f6360b6                                                                                                                                                                                                 
Step 3/11 : RUN yum -q list installed rsync &>/dev/null || yum install -y rsync                                                                                                                                    
 ---> Using cache                                                                                                                                                                                                  
 ---> 979f9f9c66bf                                                                                                                                                                                                 
Step 4/11 : RUN pip install --upgrade pip                                                                                                                                                                          
 ---> Using cache                                                                                                                                                                                                  
 ---> 2dc2d8e2bfb7                                                                                                                                                                                                 
Step 5/11 : RUN pip install pipenv poetry                                                                                                                                                                          
 ---> Using cache                                                                                                                                                                                                  
 ---> b5c72af635cd                                                                                                                                                                                                 
Step 6/11 : WORKDIR /var/dependencies                                                                                                                                                                              
 ---> Using cache
 ---> b30e662c1605
Step 7/11 : COPY Pipfile* pyproject* poetry* requirements.tx[t] ./
 ---> Using cache
 ---> 2032949736b3
Step 8/11 : RUN if [ -f 'Pipfile' ]; then pipenv lock -r > requirements.txt; else echo "Pipfile not found"; fi
 ---> Running in bdfc2eee57cb
Usage: pipenv lock [OPTIONS]
Try 'pipenv lock -h' for help.

Error: No such option: -r
The command '/bin/sh -c if [ -f 'Pipfile' ]; then pipenv lock -r > requirements.txt; else echo "Pipfile not found"; fi' returned a non-zero code: 2

Error: docker exited with status 2
    at dockerExec (/home/cdoue/www-dev/projects/crypto_bot_2/node_modules/aws-cdk-lib/core/lib/bundling.js:4:45)
    at Function.fromBuild (/home/cdoue/www-dev/projects/crypto_bot_2/node_modules/aws-cdk-lib/core/lib/bundling.js:1:3442)
    at bundle (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/core/dist/runtime/handler/pythonBundling.js:43:35)
    at Object.bundle (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/core/dist/runtime/handler/python.js:33:27)
    at Module.bundle (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/core/dist/runtime/handler/index.js:17:16)
    at new Function (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/resources/dist/Function.js:223:45)
    at Function.fromDefinition (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/resources/dist/Function.js:468:20)
    at Strategy.createRuleTarget (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/resources/dist/Cron.js:81:25)
    at new Cron (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/resources/dist/Cron.js:29:33)
    at new Strategy (file:///home/cdoue/www-dev/projects/crypto_bot_2/.build/lib/index.js:71:5)
    at EmptyStack.MainStack (file:///home/cdoue/www-dev/projects/crypto_bot_2/.build/lib/index.js:318:3)
    at stack (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/resources/dist/FunctionalStack.js:15:35)
    at App.stack (file:///home/cdoue/www-dev/projects/crypto_bot_2/node_modules/@serverless-stack/resources/dist/App.js:272:16)
    at Module.main (file:///home/cdoue/www-dev/projects/crypto_bot_2/.build/lib/index.js:344:7)
    at file:///home/cdoue/www-dev/projects/crypto_bot_2/.build/run.mjs:92:16

Reproduction Steps

  1. Create a lambda with a python runtime
  2. Use pipenv to handle the dependencies of your lambda code => you have a Pipfile in the folder of your handler code
  3. Try to deploy

Possible Solution

According to the pipenv doc, replace pipenv lock -r > requirements.txt by pipenv requirements > requirements.txt

Additional Information/Context

No response

CDK CLI Version

2.32.0

Framework Version

No response

Node.js Version

14

OS

Ubuntu

Language

Typescript

Language Version

TypeScript (4.7.4)

Other information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
jly36963commented, Aug 16, 2022

I think this is a breaking change in pipenv.

See their changelog

2022-08-13 > Removals and deprecations They want people to use pipenv requirements instead of pipenv lock -r

(I had this same issue this morning)

0reactions
github-actions[bot]commented, Aug 25, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Applications on AWS Lambda | by Alexander Mancevice
The development process can be broken down into six stages: Lock where the full list of dependencies is locked to support deterministic ...
Read more >
Amazon Lambda Python Library - AWS Documentation
They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and...
Read more >
How to install external modules in a Python Lambda Function ...
I'm using the Python AWS CDK in ...
Read more >
REST API - Lambda Powertools Python - Open Source at AWS
Event Handler naturally leads to a single Lambda function handling multiple routes for a given service, which can be eventually broken into ...
Read more >
Python-Lambda: The Essential Library for AWS Cloud Functions
Something you should be aware of at the time of writing: Pip's latest version, 18.1, is actually a breaking change for Pipenv. Thus,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found