skip to Main Content

I am writing an application on AWS Lambda in Python that expects to receive information that gets placed in the event dictionary.

def lambda_handler(event, context):
    # TODO implement

    try:
        task = event["task"]
    except:
        return {
            'statusCode': 500,
            'body': json.dumps('Cound not find the requested task.')
        }

When I test the JSON event below within the Lambda console, it is understood by the function, which then does its thing.

{
  "task": "returnID",
  "username": "noneofyourbusiness",
  "password": "pleasedonotask"
}

But when I place this event in the test provided within the AWS API Gateway (console version), it fails to find event["task"].

What else should I check? Is there some other resource that I should consult?

I tried putting the JSON in the query string (even though the method should be POST) and tried again using both POST and GET.

2

Answers


  1. Your task is inside body of the event. You should use:

    task = event["body"]["task"]
    
    Login or Signup to reply.
  2. As you seem to have realized, events come with far more information than just the payload itself. You can checkout the docs for the event format and how you should respond.

    https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html#apigateway-example-event

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search