0

I am getting a 500 Internal Server Error with the following code in an AWS Lambda function and I cannot figure out why. The python code runs fine locally without any exceptions.

def lambda_handler (event, context):
    return {
        "statusCode": 200,
        'headers': {
            'Access-Control-Allow-Headers': 'Content-Type',
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
        },
        "body": [],
    }

1 Answer 1

2

The problem is that body MUST BE A STRING. Objects will not work.

The (very simple) solution that took me an hour or so to figure out:

def lambda_handler (event, context):
    return {
        "statusCode": 200,
        'headers': {
            'Access-Control-Allow-Headers': 'Content-Type',
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
        },
        "body": "[]",
    }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.