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.