Comments (5)
Hi there,
It looks like this is coming from your lambda function, can you confirm that you build your function with all its requirements?
In the meantime, if you can share a reproducible, we can test on our side as well.
from aws-sam-cli.
In attention to your observation on the build:
I have reviewed the build process and resolved all appearing warnings by updating the referred packages now having the following versions:
chardet. 5.2.0
psycopg2-binary. 2.9.9
requests. 2.32.3
urllib3. 2.2.2
This is the build command:
sam build --use-container --build-image docker.artifactory.my.domain.com/sam/build-python3.12 --template sam-templates/my-template.yaml
Here is the requirements.txt file with the following content:
psycopg2-binary==2.9.9
setuptools==60.5.0
This is the excerpt of the settings in the template file:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
my-app
SAM Template for my-app server-less stack
Globals:
Function:
Handler: app.lambda_handler
Runtime: python3.12
Layers:
- !Ref UtilsLayer
- !Ref StaticLayer
Timeout: 900
Environment:
Variables:
Resources:
# common modules
UtilsLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ../layer-adp/python
CompatibleRuntimes:
- python3.12
Metadata:
BuildMethod: python3.12
# static modulea
StaticLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ../../layer-static/python
CompatibleRuntimes:
- python3.12
Metadata:
BuildMethod: python3.12
# function
TemplatesForUserAPIFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ../app-src
Handler: my_api.get_app
Events:
GroupsApi:
Type: Api
Properties:
Path: /app
Method: GET
As you can see above, I have 2 lambda layers and as the build goes perfect with no errors or warnings and when calling the service after the application server is initialized then the referred error message comes up.
As a side note:
I noticed is that even though I have LOCALLY installed this psycopg2-binary==2.9.9 package, it turns out that when run the build while being network disconnected I get the following error:
PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: psycopg2-binary==2.9.9
Could this indicate that while having locally the package installed it is retrieved from somewhere else?
Once connected back to internet the dependency gets satisfied and the build goes unblemished.
from aws-sam-cli.
Thanks for providing more details.
I've tried to build a python3.12 lambda function with the requirements below;
psycopg2-binary==2.9.9
setuptools==60.5.0
I was able to build it with no issues.
I saw that you are using a custom build image, may I ask why you need it? Can you just run sam build --use-container --template sam-templates/my-template.yaml
to see if it is going to succeed?
I noticed is that even though I have LOCALLY installed this psycopg2-binary==2.9.9 package, it turns out that when run the build while being network disconnected I get the following error:
PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: psycopg2-binary==2.9.9
AWS SAM CLI uses PIP cli to manage dependencies. And it downloads them depending on the architecture of your lambda function. It can't use local dependencies all the time since OS or architecture might be different from what you are targeting. If you prefer, you can run your own build process by defining a Makefile
, the process is explained here: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-custom-runtimes.html
from aws-sam-cli.
the public.ecr.aws/lambda/python:3.11
(and public.ecr.aws/sam/build-python3.11
) image has setuptools
installed by default
❯ docker run -it --entrypoint="" public.ecr.aws/lambda/python:3.11 pip list
Package Version
--------------- -------
awslambdaric 2.0.10
boto3 1.34.42
botocore 1.34.42
jmespath 1.0.1
pip 24.0
python-dateutil 2.8.2
s3transfer 0.10.0
setuptools 65.5.0
simplejson 3.17.2
six 1.16.0
urllib3 1.26.18
wheel 0.43.0
whereas, the public.ecr.aws/lambda/python:3.12
(and public.ecr.aws/sam/build-python3.12
) doesn't
❯ docker run -it --entrypoint="" public.ecr.aws/lambda/python:3.12 pip list
Package Version
--------------- -------
awslambdaric 2.0.10
boto3 1.34.42
botocore 1.34.42
jmespath 1.0.1
pip 24.0
python-dateutil 2.8.2
s3transfer 0.10.0
simplejson 3.17.2
six 1.16.0
urllib3 1.26.18
wheel 0.43.0
from aws-sam-cli.
Finally, I had the application now running on python 3.12.
Having that mndeveci was able to run it, what I did was to start from a clean slate with a type of 'hello world' application then added the modules one by one and turned out that never had an issue! It's like something somehow was not getting updated. Don't know what that something was.
I was considering to migrate the implementation to python 3.11 runtime as a last resort but had to try the virtual 'start from scratch' out for a last try.
Appreciate your help guys
from aws-sam-cli.
Related Issues (20)
- VStudio Debug for Typescript Lambda function gives Runtime.ImportModuleError HOT 7
- Feature request: Support for Python requirements files with different names HOT 3
- Bug: "sam build - TypeError" When building Docker Image from documentation HOT 1
- SamCli standard template with no modifications fails validation HOT 6
- Feature request: switch to add SO_REUSEPORT to main socket in local start-lambda / start-api HOT 1
- JSON decode error HOT 4
- Lambda response must be valid json HOT 3
- Feature request: Support publishing SAM template to SAR that leverages an existing macro HOT 2
- Getting `ValueError: Function name is required` when running API Gateway from Terraform HOT 4
- Bug: sam local start-api - ResponseParserError HOT 2
- `'str' object has no attribute 'decode'` when `PortAlreadyInUse` error is raised. HOT 2
- Feature request: Enhance generate-event to support chained events in common patterns. HOT 3
- Version 1.120.0 Affected by CVE-2024-5535 HOT 1
- Bug: sam deploy - KeyError HOT 2
- Feature request: Upgrade cfn-lint dependency HOT 2
- Add Rust support to aws cli --use-container builds HOT 1
- Cannot find module 'app' when using "hello world typescript" example HOT 10
- Bug: AWS::Serverless::Function ImageUri with function (ex: using !If) fails with type error HOT 3
- Bug: Template not rendered correctly HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sam-cli.