Reputation: 161
When running my python-based aws lambda, I get a read-only file system error.
But, I'm not doing any logging, it looks like serverless is.
{
"errorMessage": "Unable to marshal response: OSError(30, 'Read-only file system') is not JSON serializable",
"errorType": "Runtime.MarshalError"
}
Error --------------------------------------------------
Error: Invoked function failed
at AwsInvoke.log (/usr/local/Cellar/serverless/1.50.0/libexec/lib/node_modules/serverless/lib/plugins/aws/invoke/index.js:101:31)
Here is my serverless.yml
provider:
name: aws
runtime: python3.7
functions:
main:
handler: main.handler
package:
include:
- src/main.py
layers:
- {Ref: PythonRequirementsLambdaLayer}
environment:
REGION_NAME: us-west-2
custom:
pythonRequirements:
dockerFile: ./Dockerfile
layer: true
plugins:
- serverless-python-requirements
I've wrapped my handler in a try-catch but it doesn't even get to my code.
I expect my lambda to run my code without error
Upvotes: 0
Views: 2382
Reputation: 934
The error message Unable to marshal response {repr} is not JSON serializable
occurs when the handler returns a value that is not JSON serializable to Lambda.
At some point, something is trapping an exception and returning the exception object.
Let's then look at OSError(30, 'Read-only file system')
. This is also a common issue with Lambda: writing is only permitted under /tmp
. Your code is mounted in a read-only volume.
I've wrapped my handler in a try-catch but it doesn't even get to my code.
Strictly, it doesn't get to your handler.
Importing a module runs it from the top; those def
and class
blocks are just glorified assignments into the module namespace. And when you import other modules, they can run arbitrary code, and they can absolutely try to write to the filesystem.
One simple way to diagnose this further would be to:
chmod
or the like on Windows.Since you're pulling in PythonRequirementsLambdaLayer directly, you could also unpack that into your test rig to figure out where it's breaking.
Upvotes: 1