Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CloudFormation conditional template validation

I have a template to create a CloudFormation with DynamoDB and DAX for multiple regions, for example, us-east-1 and ap-southeast-1. While working for us-east-1, this template would not work for ap-southeast-1 since DAX is not yet available for that region.

I expected that this could be done using Conditions, so that for one region (us-east-1) I would have both DynamoDB and DAX and for another one (ap-southeast-1) - only DynamoDB:

Conditions: 
  isDAXAvailable: !Not [!Equals [ !Ref "AWS::Region", ap-southeast-1 ]]

Resources:
  DynamoDBTable:
    Type: AWS::DynamoDB::Table
    Properties:
    .....

  DaxCluster:
    Type: AWS::DAX::Cluster
    Condition: isDAXAvailable
    Properties:
    .....

But unfortunately I receive an error:

An error occurred (ValidationError) when calling the ValidateTemplate operation: Template format error: Unrecognized resource types: [AWS::DAX::Cluster]

Is it possible to configure such template anyhow or a separate one should be created?

like image 508
Enigo Avatar asked Nov 08 '22 12:11

Enigo


1 Answers

Template validation is done against the resources available in a region. Since DAX is not currently available in ap-southeast-1, the AWS::DAX::Cluster resource will fail validation there. I have a couple of suggestions for how to make this work:

  • Preprocess your template to strip out the DAX resources in not-currently-supported regions
  • Split your template into three separate templates, which I’ll call DAX, NoDAX, and Other:
    • In regions that support DAX, create a stack with the DAX template that includes your cluster, and export the cluster’s name as the value of ClusterName.
    • In regions that don’t support DAX, create a stack with the NoDAX template, and export none as the value of ClusterName. Since every template needs a resource, include an AWS::CloudFormation::WaitConditionHandle as this template’s only resource.
    • In all regions, create a stack with Other template that imports DaxClusterName, and creates a conditional based on Fn:Equals: [“DaxClusterName”, “none”]. Then use the conditional to determine whether the resources in this template can depend on the cluster.
like image 196
Kevin Christen Avatar answered Nov 15 '22 05:11

Kevin Christen