[英]How to refer existing resources
我使用了cloudformation模板來創建MyAPI
, MyAPIGetMethod
, MyAPIDeployment
。
現在,我有一個單獨的腳本,我將用它來創建階段。 像這樣的東西。 該腳本拋出一個錯誤,它不知道我在DeploymentId
和RestApiId
使用了什么資源。 確切的錯誤是Template validation error: Template error: instance of Fn::GetAtt references undefined resource MyAPIDeployment
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters" : {
"EnvType": {
"Type": "String",
"Default": "test",
"AllowedValues": ["test", "prod"],
"Description": "Select what stage need to be created"
}
},
"Conditions":{
"CreateProdStage" : {"Fn::Equals": [{"Ref":"EnvType"}, "prod"]},
"CreateTestStage" : {"Fn::Equals": [{"Ref":"EnvType"}, "test"]}
},
"Resources": {
"TestStage" : {
"Type" : "AWS::ApiGateway::Stage",
"Condition":"CreateTestStage",
"Properties" : {
"DeploymentId" : {"Fn::GetAtt" : ["MyAPIDeployment", "Arn"]},
"Description" : "Test Stage",
"RestApiId" : {"Fn::GetAtt" : ["MyAPI", "Arn"]},
"StageName" : "test"
}
},
"ProdStage" : {
"Type" : "AWS::ApiGateway::Stage",
"Condition":"CreateProdStage",
"Properties" : {
"DeploymentId" : {"Fn::GetAtt" : ["MyAPIDeployment", "Arn"]},
"Description" : "Prod Stage",
"RestApiId" : {"Fn::GetAtt" : ["MyAPI", "Arn"]},
"StageName" : "prod",
"MethodSettings":[{
"CachingEnabled":"true",
"HttpMethod":"GET",
"ResourcePath":"/",
"CacheTtlInSeconds":300,
"ThrottlingBurstLimit" : 2000,
"ThrottlingRateLimit" : 1000
}]
}
}
}
}
為了更好地理解為什么這不起作用是因為您無法在CloudFormation模板中引用不屬於它的資源。 由於資源MyAPI
, MyAPIGetMethod
, MyAPIDeployment
不是創建階段的模板的一部分,因此您無法引用它們。 您只能引用參數,其他資源,條件,映射等,但不能參考在不同堆棧中創建的資源。
我的建議是在您創建MyAPI
, MyAPIGetMethod
, MyAPIDeployment
的示例模板上創建階段,或者使用DeploymentId
和RestApiId
值所需的信息創建必要的參數,然后使用Ref
。
我從你的模板中注意到的另一個錯誤是DeploymentId
和RestApiId
所期望的值是對應的id而不是arn的,所以請確保使用id而不是你在上面的代碼片段中嘗試的arn。 另請注意,沒有為AWS::ApiGateway::RestApi
, AWS::ApiGateway::RestApi
和AWS::ApiGateway::RestApi
。 從這個資源中返回值的唯一函數是Ref
,它將返回它們的id。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.