AWS Lambda不断从Lambda返回"\"你好! [英] AWS Lambda keeps returning "\"Hello from Lambda!\"

查看:70
本文介绍了AWS Lambda不断从Lambda返回"\"你好!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在适用于Python 3.8的AWS Lambda上遇到了一些问题.无论我尝试运行哪种代码,AWS Lambda都会始终返回相同的响应.我正在尝试使用以下代码从DynamoDB实例中检索信息:

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)
    }

我希望得到类似'body':{'Item':{'id':'mercury','temp':'sizzling hot'}} 的输出,甚至是错误,但我不断收到以下回复:

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.

推荐答案

通常这是由于以下原因之一:

Usually this is due to one of the following reasons:

  1. 未部署您的代码更改.在新的用户界面中,您必须使用橙色按钮显式地 Deploy 功能.
  2. 如果要对功能进行版本控制,则您要调用的是旧的lambda版本,而不是最新的版本.您必须明确选择要调用的正确版本.
  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.

这篇关于AWS Lambda不断从Lambda返回"\"你好!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆