I'm developing a lambda function in Python. The function access RDS database using the pyodbc library. To work with the library I'm using layers. My SAM template looks like this and everything works fine while deployed to AWS.
Resources:
# ODBC Lambda Layer
PyODBCLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: pyodbc_layer.zip
# Lambda function
TaskIDFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: taskid/
Handler: app.lambda_handler
Layers:
- !Ref PyODBCLayer
Role: !GetAtt TaskIDFunctionIamRole.Arn
Runtime: python3.6
Environment:
Variables:
ODBCINI: /opt/bin/odbcinst.ini
ODBCSYSINI: /opt/bin
Events:
SendTaskID:
Type: Api
Properties:
Path: /task/{id}
Method: get
The problem begins when I'm trying to run this locally with sam build && sam local invoke -d 5890 TaskIDFunction --event myEvent.json
I'm getting error message Unable to import module 'app': No module named 'pyodbc'
which I understand and typically the solution would be to add pyodbc
to requiremens.txt file for local debugging.
However, after I have done that, the sam build
command fails with the following message
Build Failed
Error: PythonPipBuilder:ResolveDependencies - {pyodbc==4.0.26(wheel)}
I can pip install pyodbc
without problems but for some reason, sam build
fails.
I have tried various combinations with removing the layer from the template and installing PyODBC manually to get this running locally but no success.
I dont have reputation enough to comment, so:
Im getting the same error. Wondering if you could evolve this, and if so, how did you do it?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.