![](/img/trans.png)
[英]Creating a completely serverless solution using AWS API Gateway integrated with a Lambda function that talks to a serverless database
[英]AWS Serverless ApiKey UsagePlan cannot find gateway api reference
我正在嘗試構建一個使用 ApiKey 調用 lambda function 的無服務器 API。 Visual Studio 中的 AWS SDK 給我一個錯誤,指出引用是無效類型。
我已經將我的無服務器模板與其他幾個工作示例進行了比較,但我必須忽略一些特定的細節。
有任何想法嗎?
這是我的無服務器模板......我錯過了什么?
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "An AWS Serverless Application.",
"Resources": {
"SendEmailFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "ServerlessTest3::ServerlessTest3.Functions::SendEmail",
"Runtime": "dotnetcore3.1",
"CodeUri": "",
"MemorySize": 12,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambdaBasicExecutionRole"
],
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/{proxy+}",
"Method": "POST",
"RestApiId": {
"Ref": "ApiGatewayApi"
}
}
},
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/",
"Method": "POST",
"RestApiId": {
"Ref": "ApiGatewayApi"
}
}
}
}
}
},
"ApiUsagePlan": {
"Type": "AWS::ApiGateway::UsagePlan",
"Properties": {
"ApiStages": [
{
"ApiId": {
"Ref": "ApiGatewayApi"
},
"Stage": "Prod"
}
]
}
},
"ApiUsagePlanKey": {
"Type": "AWS::ApiGateway::UsagePlanKey",
"Properties": {
"KeyId": {
"Ref": "ApiKey"
},
"KeyType": "API_KEY",
"UsagePlanId": {
"Ref": "ApiUsagePlan"
}
}
},
"ApiKey": {
"Type": "AWS::ApiGateway::ApiKey",
"Properties": {
"Name": "my-api-key-name",
"Enabled": "true",
"StageKeys": [{
"RestApiId": {
"Ref": "ApiGatewayApi"
},
"StageName": "Prod"
}
]
}
},
"ApiGatewayApi": {
"Type": "AWS::Serverless::Api",
"Properties": {
"StageName": "Prod",
"Auth": {
"ApiKeyRequired": "true"
}
}
}
},
"Outputs": {
"ApiURL": {
"Description": "API endpoint URL for Prod environment",
"Value": {
"Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
}
}
}
}
ApiId 是一個字符串,而不是 object。
您只需將“ApiGatewayApi”放在那里即可修復
{
"ApiId": "ApiGatewayApi"
}
您正在為您的 ApiId 引用AWS::Serverless::Api資源,並且模板需要AWS::ApiGateway::RestApi資源。 這就是該錯誤背后的原因。
更新ApiGatewayApi
的類型后,錯誤就會消失
"ApiGatewayApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Body": {
"OpenAPI specification": null
},
"Description": "A test API",
"Name": "MyRestAPI"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.