我正在開發一個使用 HTTPS/POST 請求將 API Gateway 集成到 DynamoDB 的 terraform 腳本。基本目標是將 API 請求正文中傳遞的記錄插入 DynamoDB 表中。我正在使用 aws_api_gateway_integration 來定義集成,并且我正在傳遞應包含兩個屬性(BusinessUnitId和Frequency)的請求模板。我的腳本如下所示 -
resource aws_api_gateway_integration schedule_post_integration {
rest_api_id = aws_api_gateway_rest_api.schedule.id
resource_id = aws_api_gateway_resource.schedule_resource.id
http_method = aws_api_gateway_method.schedule_post_method.http_method
type = "AWS"
integration_http_method = "POST"
uri = "arn:aws:apigateway:${var.target_region}:dynamodb:action/PutItem"
credentials = aws_iam_role.schedule_api_dynamodb_role.arn
request_templates = {
"application/json" = EOF
{
"TableName" : "${var.environment_id}-AccountService-NotesToDatalakeSchedule",
"Item" : {
"BusinessUnitId" : {
"N" : "$input.path('$.BusinessUnitId')"
},
"Frequency" : {
"N" : "$input.path('$.Frequency')"
}
}
}
}
}
我找不到正確的語法來指示應如何在 request_templates 中傳遞Item 。在部署期間它會拋出錯誤 -
2022-09-12T11:51:22.6623262Z ##[error][1m[31mError: [0m[0m[1mMissing attribute value[0m
2022-09-12T11:51:22.6626316Z ##[error][0m on api-gateway.tf line 47, in resource "aws_api_gateway_integration" "schedule_post_integration":
2022-09-12T11:51:22.6628770Z ##[error] 35: request_templates = {
2022-09-12T11:51:22.6630845Z ##[error] 36: "application/json" = EOF
2022-09-12T11:51:22.6632935Z ##[error] 37: {
2022-09-12T11:51:22.6636136Z ##[error] 38: "TableName" : "${var.environment_id}-AccountService-NotesToDatalakeSchedule",
2022-09-12T11:51:22.6638305Z ##[error] 39: "Item" : {
2022-09-12T11:51:22.6642274Z ##[error] 40: "BusinessUnitId" : {
2022-09-12T11:51:22.6645424Z ##[error] 41: "N" : "$input.path('$.BusinessUnitId')"
2022-09-12T11:51:22.6647529Z ##[error] 42: },
2022-09-12T11:51:22.6649461Z ##[error] 43: "Frequency" : {
2022-09-12T11:51:22.6651639Z ##[error] 44: "N" : "$input.path('$.Frequency')"
2022-09-12T11:51:22.6653642Z ##[error] 45: }
2022-09-12T11:51:22.6655505Z ##[error] 46: }
2022-09-12T11:51:22.6657282Z ##[error] 47: }
2022-09-12T11:51:22.6659045Z ##[error] 48: }
2022-09-12T11:51:22.6661277Z ##[error]Expected an attribute value, introduced by an equals sign ("=").
有人可以幫我確定這里的問題嗎?
uj5u.com熱心網友回復:
看起來您正在嘗試使用 HCL Template Expressions,但您忘記了兩個關鍵事項:
- 模板運算式以
<< MARKER
, 您選擇EOF
作為標記但忘記了<<
- 您忘記了“單獨一行”的標記。
固定版本:
resource aws_api_gateway_integration schedule_post_integration {
rest_api_id = aws_api_gateway_rest_api.schedule.id
resource_id = aws_api_gateway_resource.schedule_resource.id
http_method = aws_api_gateway_method.schedule_post_method.http_method
type = "AWS"
integration_http_method = "POST"
uri = "arn:aws:apigateway:${var.target_region}:dynamodb:action/PutItem"
credentials = aws_iam_role.schedule_api_dynamodb_role.arn
request_templates = {
"application/json" = << EOF
{
"TableName" : "${var.environment_id}-AccountService-NotesToDatalakeSchedule",
"Item" : {
"BusinessUnitId" : {
"N" : "$input.path('$.BusinessUnitId')"
},
"Frequency" : {
"N" : "$input.path('$.Frequency')"
}
}
}
EOF
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/506412.html
標籤:亚马逊网络服务 地形 terraform-provider-aws