How to refer existing resources
up vote
2
down vote
favorite
I used cloudformation template to create MyAPI
, MyAPIGetMethod
, MyAPIDeployment
.
Now, I have a separate script which i will be using to create stages. Something like this. the script is throwing an error that it doesn't know what resource I am using in DeploymentId
and in RestApiId
. The exact error is 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
}]
}
}
}
}
amazon-web-services amazon-cloudformation
add a comment |
up vote
2
down vote
favorite
I used cloudformation template to create MyAPI
, MyAPIGetMethod
, MyAPIDeployment
.
Now, I have a separate script which i will be using to create stages. Something like this. the script is throwing an error that it doesn't know what resource I am using in DeploymentId
and in RestApiId
. The exact error is 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
}]
}
}
}
}
amazon-web-services amazon-cloudformation
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I used cloudformation template to create MyAPI
, MyAPIGetMethod
, MyAPIDeployment
.
Now, I have a separate script which i will be using to create stages. Something like this. the script is throwing an error that it doesn't know what resource I am using in DeploymentId
and in RestApiId
. The exact error is 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
}]
}
}
}
}
amazon-web-services amazon-cloudformation
I used cloudformation template to create MyAPI
, MyAPIGetMethod
, MyAPIDeployment
.
Now, I have a separate script which i will be using to create stages. Something like this. the script is throwing an error that it doesn't know what resource I am using in DeploymentId
and in RestApiId
. The exact error is 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
}]
}
}
}
}
amazon-web-services amazon-cloudformation
amazon-web-services amazon-cloudformation
asked Mar 2 '17 at 16:21
Em Ae
2,24684283
2,24684283
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
To better understand why this is not working is because you can't reference resources in a CloudFormation template that are not part of it. Since the resources MyAPI
, MyAPIGetMethod
, MyAPIDeployment
are not part of the template where the stages are being created then you can't reference them. You can only reference parameteres, other resources, conditions, mappings, etc, but not resources created in a different stack.
My recommendation is to either create the stages on the sample template you have created the MyAPI
, MyAPIGetMethod
, MyAPIDeployment
, or, to create the necessary parameters with the information needed as DeploymentId
and RestApiId
values and then use Ref
.
Another error that I noticed from your template is that the values expected from DeploymentId
and RestApiId
are the correspondent ids and not the arn's so make sure to use the ids and not the arn as you attempted to do in the snippet above. Also note that the functions GetAtt is not defined for AWS::ApiGateway::RestApi
, AWS::ApiGateway::RestApi
, nor AWS::ApiGateway::RestApi
. The only function to return values from this resourcs is Ref
and it will return their ids.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
To better understand why this is not working is because you can't reference resources in a CloudFormation template that are not part of it. Since the resources MyAPI
, MyAPIGetMethod
, MyAPIDeployment
are not part of the template where the stages are being created then you can't reference them. You can only reference parameteres, other resources, conditions, mappings, etc, but not resources created in a different stack.
My recommendation is to either create the stages on the sample template you have created the MyAPI
, MyAPIGetMethod
, MyAPIDeployment
, or, to create the necessary parameters with the information needed as DeploymentId
and RestApiId
values and then use Ref
.
Another error that I noticed from your template is that the values expected from DeploymentId
and RestApiId
are the correspondent ids and not the arn's so make sure to use the ids and not the arn as you attempted to do in the snippet above. Also note that the functions GetAtt is not defined for AWS::ApiGateway::RestApi
, AWS::ApiGateway::RestApi
, nor AWS::ApiGateway::RestApi
. The only function to return values from this resourcs is Ref
and it will return their ids.
add a comment |
up vote
0
down vote
To better understand why this is not working is because you can't reference resources in a CloudFormation template that are not part of it. Since the resources MyAPI
, MyAPIGetMethod
, MyAPIDeployment
are not part of the template where the stages are being created then you can't reference them. You can only reference parameteres, other resources, conditions, mappings, etc, but not resources created in a different stack.
My recommendation is to either create the stages on the sample template you have created the MyAPI
, MyAPIGetMethod
, MyAPIDeployment
, or, to create the necessary parameters with the information needed as DeploymentId
and RestApiId
values and then use Ref
.
Another error that I noticed from your template is that the values expected from DeploymentId
and RestApiId
are the correspondent ids and not the arn's so make sure to use the ids and not the arn as you attempted to do in the snippet above. Also note that the functions GetAtt is not defined for AWS::ApiGateway::RestApi
, AWS::ApiGateway::RestApi
, nor AWS::ApiGateway::RestApi
. The only function to return values from this resourcs is Ref
and it will return their ids.
add a comment |
up vote
0
down vote
up vote
0
down vote
To better understand why this is not working is because you can't reference resources in a CloudFormation template that are not part of it. Since the resources MyAPI
, MyAPIGetMethod
, MyAPIDeployment
are not part of the template where the stages are being created then you can't reference them. You can only reference parameteres, other resources, conditions, mappings, etc, but not resources created in a different stack.
My recommendation is to either create the stages on the sample template you have created the MyAPI
, MyAPIGetMethod
, MyAPIDeployment
, or, to create the necessary parameters with the information needed as DeploymentId
and RestApiId
values and then use Ref
.
Another error that I noticed from your template is that the values expected from DeploymentId
and RestApiId
are the correspondent ids and not the arn's so make sure to use the ids and not the arn as you attempted to do in the snippet above. Also note that the functions GetAtt is not defined for AWS::ApiGateway::RestApi
, AWS::ApiGateway::RestApi
, nor AWS::ApiGateway::RestApi
. The only function to return values from this resourcs is Ref
and it will return their ids.
To better understand why this is not working is because you can't reference resources in a CloudFormation template that are not part of it. Since the resources MyAPI
, MyAPIGetMethod
, MyAPIDeployment
are not part of the template where the stages are being created then you can't reference them. You can only reference parameteres, other resources, conditions, mappings, etc, but not resources created in a different stack.
My recommendation is to either create the stages on the sample template you have created the MyAPI
, MyAPIGetMethod
, MyAPIDeployment
, or, to create the necessary parameters with the information needed as DeploymentId
and RestApiId
values and then use Ref
.
Another error that I noticed from your template is that the values expected from DeploymentId
and RestApiId
are the correspondent ids and not the arn's so make sure to use the ids and not the arn as you attempted to do in the snippet above. Also note that the functions GetAtt is not defined for AWS::ApiGateway::RestApi
, AWS::ApiGateway::RestApi
, nor AWS::ApiGateway::RestApi
. The only function to return values from this resourcs is Ref
and it will return their ids.
answered Nov 10 at 21:54
Aura Herrera
114
114
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42560602%2fhow-to-refer-existing-resources%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown