How to refer existing resources











up vote
3
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
}]
}
}
}
}









share|improve this question


























    up vote
    3
    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
    }]
    }
    }
    }
    }









    share|improve this question
























      up vote
      3
      down vote

      favorite









      up vote
      3
      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
      }]
      }
      }
      }
      }









      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 2 '17 at 16:21









      Em Ae

      2,25684383




      2,25684383
























          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.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            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

























            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.






            share|improve this answer

























              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.






              share|improve this answer























                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 21:54









                Aura Herrera

                215




                215






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Full-time equivalent

                    さくらももこ

                    13 indicted, 8 arrested in Calif. drug cartel investigation