16

I'm having some issues with AWS Lambda for Python 3.8. No matter what code I try running, AWS Lambda keeps returning the same response. I am trying to retrieve a information from a DynamoDB instance with the code below:

import json
import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('planets')

def lambda_handler(event, context):
    response = table.get_item(
        Key = {
            'id':'mercury'
        }
    )
    print(response)
    # TODO implement
    return {
        'statusCode': 200,
        'body': response)
    }

I am expecting an output like 'body':{'Item': {'id':'mercury', 'temp':'sizzling hot'}}, or an error even, but I keep getting the response below:

Response:
{
  "statusCode": 200,
  "body": "\"Hello from Lambda!\""
}

I even change up the code, expecting an error, but I still get the same output.

0

1 Answer 1

36

Usually this is due to one of the following reasons:

  1. You are not deploying your code changes. In the new UI, you have to explicitly Deploy your function using Orange button.
  2. You are invoking old lambda version, rather then your latest version, if you are versioning your functions. You must explicitly choose the correct version to invoke.
Sign up to request clarification or add additional context in comments.

4 Comments

It worked! Thank you. Weird that you have to deploy it before you can really test it though.
Popular problem, this one. Would be good if the UI could warn you when clicking Test if you have undeployed changes.
Very confusing, especially for the beginners following the old UI tutorial and trying it on the new UI.
The deploy and test buttons disappear from the UI if your window is too narrow. I was running two windows side by side and could not find deploy or test on the code UI anywhere (as well as the "changes not deployed" indicator). Expanding the tab shows them again. Really bad UI experience.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.