问题
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:
- You are not deploying your code changes. In the new UI, you have to explicitly
Deploy
your function using Orange button. - 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