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

我们两清 提交于 2021-01-20 04:57:06

问题


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.


回答1:


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.


来源:https://stackoverflow.com/questions/64833782/aws-lambda-keeps-returning-hello-from-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!