我正在尝试使用 Python 3.6 创建简单的 Lambda 函数。
该函数应该在请求查询字符串参数中获取一个 userId(我在 DynamoDB 中的主键),如果项目存在于 DB 中,则返回 200,这是我的 lambda 函数
import boto3
import os
from boto3.dynamodb.conditions import Key, Attr
def lambda_handler(event, context):
userId = event["userId"]
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(os.environ['Customers'])
items = table.query(
KeyConditionExpression=Key('userId').eq(userId)
)
return items["Items"]
Run Code Online (Sandbox Code Playgroud)
当我在 Lambda 接口中进行测试时,它可以工作并返回正确的用户,但是,当从 Postman 尝试或使用 API Gateway 时,它返回以下错误
{
"errorMessage": "'userId'",
"errorType": "KeyError",
"stackTrace": [
[
"/var/task/index.py",
7,
"lambda_handler",
"userId = event["userId"]"
]
]
}
Run Code Online (Sandbox Code Playgroud)
我正在使用自己的域通过CloudFront为HTTPS s3存储桶提供服务。我不希望它因为QA环境而被缓存。
我想知道我怎么能做到这一点。是使用Origin Cache Headers还是使用0生存时间进行自定义?