Srinivasarao Daruna
Srinivasarao Daruna

Reputation: 3374

How to refer a derived variable in CloudFormation?

I am looking for small help in CloudFormation and could not find help from documentation or may be not searching the question in right way.

Here is the question.

I am getting availability zones for the environment from mappings as follows.

"AvailabilityZone": {
"Fn::Select": [
    "1",
    {
        "Fn::FindInMap": [
            "Environment",
            {
                "Ref": "EnvType"
            },
            "AvailabilityZones"
        ]
    }
]

}

I need to use the AZ name in my volume naming convention. How could refer the derived variable "AvailabilityZone" again.?

Currently i am doing this.

    {
    "Key": "Name",
    "Value": {
        "Fn::Join": [
            "-",
            [
                {
                    "Ref": "NamePrefix"
                },
                {
                    "Ref": "EnvType"
                },
                "myconstant",
                {
                    "Fn::Select": [
                        "2",
                        {
                            "Fn::Split": [
                                "-",
                                {
                                    "Fn::Select": [
                                        "1",
                                        {
                                            "Fn::FindInMap": [
                                                "Environment",
                                                {
                                                    "Ref": "EnvType"
                                                },
                                                "AvailabilityZones"
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        ]
    }
}

I am doing the same code twice. How can i re-use the derived variable here.?

Upvotes: 16

Views: 20701

Answers (1)

Paulo Schreiner
Paulo Schreiner

Reputation: 1046

Unfortunately, the short answer is you can't. Hopefully someday AWS supports variables in CloudFormation.

There are some hacks that might be of interest. Emphasis on hack!

Upvotes: 26

Related Questions