5
votes

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?

2
For anyone with the same problem: unfortunately, I could not find any other solution but to create a separate template for that other region.Enigo

2 Answers

1
votes

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.
0
votes

Currently, there is a workaround of adding a transform like Transform: AWS::Serverless-2016-10-31 to your template

While this might require adding a CAPABILITY_AUTO_EXPAND capability, "there is no charge incurred when using this transform" and it shouldn't affect your template if you don't have any AWS::Serverless resources, and you should already be using this transform if you do have AWS::Serverless resources