0

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

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Dynomike
  • 151
  • 2
  • 8
  • 1
    Could you share the line of code that is causing the error? Are you sure you have selected python runtime? It seems like a js error. – hmanolov Aug 25 '19 at 17:22
  • I've wrapped my handler in a try-catch but it doesn't even get to my code. I've updated my post. – Dynomike Aug 25 '19 at 17:42

1 Answers1

1

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:

  1. Unpack the zip file into its own directory.
  2. Add a simple helper that imports your handler and calls it.
  3. Mark everything read-only through chmod or the like on Windows.
  4. Run your helper and see what breaks.

Since you're pulling in PythonRequirementsLambdaLayer directly, you could also unpack that into your test rig to figure out where it's breaking.

Ben
  • 836
  • 8
  • 18