python - AWS/Python Lambda 函数检查是否存在查询字符串

标签 python python-3.x amazon-web-services aws-lambda

在接收事件 api 查询字符串的 lambda 函数中,我想检查一个是否存在。如果是,则以下工作:

if event['queryStringParameters']['order'] == 'desc':
        file_names.append('hello')

我已经尝试过 event['queryStringParameters']['order'] != null 但如果没有使用 lambda 函数的订单查询字符串,该函数将中断导致 502 响应。如何检查查询字符串是否在未中断的情况下未被使用?

最佳答案

在引用它之前总是检查字典是否包含一个键。

if 'queryStringParameters' in event and 'order' in event['queryStringParameters']:

关于python - AWS/Python Lambda 函数检查是否存在查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52205712/

相关文章:

python - OCR应用前图像清洗

python - 我怎样才能使用 python 获取停用词列表

amazon-web-services - 使用 MWS API 获取业务报告(详细信息页面销售和流量)?

amazon-web-services - 如何在客户端应用程序中订阅 AWS Event Bus 事件

Python 结构模式匹配

python - 标记 pandas 数据框中日期范围内的日期时间列表

python - Strptime 周错误

python-3.x - 用 PyPDF2 填充的 pdf 表单不显示在打印中

python - Pytorch 运行时错误 : expected scalar type Float but found Byte

amazon-web-services - 检查停止的 AWS EC2 实例是否将获得带有 boto3 的公共(public) IP