gpt4 book ai didi

amazon-web-services - 如何引用现有资源

转载 作者:行者123 更新时间:2023-12-04 08:04:56 24 4
gpt4 key购买 nike

我使用cloudformation模板创建了MyAPIMyAPIGetMethodMyAPIDeployment

现在,我有一个单独的脚本,我将用它来创建阶段。像这样的东西。该脚本引发错误,它不知道我在 DeploymentId 和 RestApiId 中使用什么资源。确切的错误是模板验证错误:模板错误:Fn::GetAtt 的实例引用未定义的资源 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 模板中不属于其一部分的资源。由于资源 MyAPIMyAPIGetMethodMyAPIDeployment 不是创建阶段的模板的一部分,因此您无法引用它们。您只能引用参数、其他资源、条件、映射等,但不能引用在不同堆栈中创建的资源。

我的建议是在您创建了 MyAPIMyAPIGetMethodMyAPIDeployment 的示例模板上创建阶段,或者创建必要的参数以及所需信息作为 DeploymentIdRestApiId 值,然后使用 Ref

我从您的模板中注意到的另一个错误是,DeploymentIdRestApiId 的预期值是相应的 id,而不是 arn,因此请确保使用 ids 和不是您在上面的代码片段中尝试执行的 arn 操作。另请注意,函数 GetAtt 没有为 AWS::ApiGateway::RestApiAWS::ApiGateway::RestApiAWS::ApiGateway::定义。 RestApi。从该资源返回值的唯一函数是 Ref,它将返回它们的 id。

关于amazon-web-services - 如何引用现有资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42560602/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com