提问人:ds90 提问时间:9/3/2023 更新时间:9/3/2023 访问量:27
无法调试具有与 dynamoDB 集成的 velocity 模板的 AWS API 网关
can't debug AWS API gateway with velocity template integrating with dynamoDB
问:
我正在测试 AWS 实例中的 API 网关,其中包含一个强制查询字符串参数(名为“tag”)和 3 个其他非强制性查询字符串参数。该 API 设置为通过集成请求链接到 AWS 服务,该集成请求在将 API 请求发送到 dynamoDB 之前使用 Apache Velocity 模板转换 API 请求。模板如下:
#set($tag = $input.params('tag'))
#set($wifi = $input.params('wifi'))
#if($wifi)
#set($wifiBool = $wifi=='true' ? true : false)
#end
#set($exclusiveStartKey = $input.params('exclusive_start_key'))
#set($limit = $input.params('limit'))
#if($limit)
#set($limitInt = $tool.parseInt($limit))
#end
#set($logMessage = "tag: $tag, wifiBool: $wifiBool, exclusiveStartKey: $exclusiveStartKey, limitInt: $limitInt")
$logMessage
{
"TableName":"places",
"KeyConditionExpression":"tag=:tag",
#if($wifi)
"FilterExpression": "wifi=:wifi",
#end
"ExpressionAttributeValues": {
":tag":{
"S":$tag
} #if($wifi),
":wifi":{
"BOOL":$wifiBool
}
#end
} #if($exclusiveStartKey),
"ExclusiveStartKey": $exclusiveStartKey,
#end #if($limit),
"Limit": $limitInt,
#end
}
其目的是根据作为查询字符串传递的多个参数查询 DynamoDB 表;唯一一个必填项是“tag”,它也是 DynamoDB 表的分区键。我按照以下策略设置了 API Gateway 的角色:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:PartiQLSelect",
"dynamodb:PartiQLUpdate",
"dynamodb:GetItem",
"dynamodb:PartiQLInsert",
"dynamodb:Scan",
"dynamodb:Query",
"dynamodb:UpdateItem",
"dynamodb:PartiQLDelete"
],
"Resource": "my_table_arn"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
"logs:GetLogEvents",
"logs:FilterLogEvents"
],
"Resource": "*"
}
]
}
用于与 dynamoDB 交互的 HTTP 方法(API 网关在后台使用的方法是 POST,而我设置的方法(用于直接向 API 网关发出请求的方法)是 GET。当我使用带有查询参数“tag=office”的请求测试 API 时,获得的日志如下:
Execution log for request 211c0796-d739-491f-9a13-a144a524cef0
Sat Sep 02 18:04:07 UTC 2023 : Starting execution for request: 211c0796-d739-491f-9a13-a144a524cef0
Sat Sep 02 18:04:07 UTC 2023 : HTTP Method: GET, Resource Path: /places
Sat Sep 02 18:04:07 UTC 2023 : Method request path: {}
Sat Sep 02 18:04:07 UTC 2023 : Method request query string: {tag=office}
Sat Sep 02 18:04:07 UTC 2023 : Method request headers: {}
Sat Sep 02 18:04:07 UTC 2023 : Method request body before transformations:
Sat Sep 02 18:04:07 UTC 2023 : Request validation succeeded for content type application/json
Sat Sep 02 18:04:07 UTC 2023 : Execution failed due to configuration error: Unable to transform request
Sat Sep 02 18:04:07 UTC 2023 : Method completed with status: 500
我不知道我做错了什么,如果有人能帮忙,我将不胜感激
答: 暂无答案
评论