Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda keeps returning "\"Hello from Lambda!\"

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.

like image 656
mehsheenman Avatar asked Nov 14 '20 12:11

mehsheenman


People also ask

How do you avoid Lambda Retry?

To stop it from retrying, you should make sure that any error is handled and you tell Lambda that your invocation finished successfully by returning a non-error (or in Node, calling callback(null, <any>) . To do this you can enclose the entire body of your handler function with a try-catch.

What happens when AWS Lambda throws exception?

If Lambda encounters an error, it returns an exception type, message, and HTTP status code that indicates the cause of the error. The client or service that invoked the Lambda function can handle the error programmatically, or pass it along to an end user.

How many times will Lambda Retry?

Lambda functions being invoked asynchronously are retried at least 3 times. Events from Amazon Kinesis streams and Amazon DynamoDB streams are retried until the Lambda function succeeds or the data expires.


1 Answers

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.
like image 62
Marcin Avatar answered Oct 06 '22 10:10

Marcin