Skip to content

Instantly share code, notes, and snippets.

@Th0masStorm
Last active Jan 8, 2021
Embed
What would you like to do?
DAX cluster creation with CloudFormation
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
TableName:
Type: String
ClusterSize:
Type: Number
Subnets:
Type: List<AWS::EC2::Subnet::Id>
Resources:
# This role provides DAX cluster nodes with access to DynamoDB
DaxRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service: "dax.amazonaws.com"
Action: "sts:AssumeRole"
Policies:
- PolicyName: DAX
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: "Allow"
Action: "dynamodb:*"
Resource:
- !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${TableName}"
# DAX Subnet Group is a set of VPC Subnets where the nodes are provisioned
DaxSubnetGroup:
Type: AWS::DAX::SubnetGroup
Properties:
SubnetIds: !Ref "Subnets"
# DAX Cluster
DaxCluster:
Type: AWS::DAX::Cluster
Properties:
IAMRoleARN: !GetAtt "DaxRole.Arn"
# usually it is a best practice to place instance types
# outside of resource definition... But I'm too lazy
NodeType: "dax.t2.small"
ReplicationFactor: !Ref "ClusterSize"
SubnetGroupName: !Ref "DaxSubnetGroup"
Outputs:
DaxClusterEndpoint:
Value: !GetAtt "DaxCluster.ClusterDiscoveryEndpoint"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment