Skip to content

Instantly share code, notes, and snippets.

@Th0masStorm
Last active January 8, 2021 14:54
Show Gist options
  • Save Th0masStorm/a4119eddd83b2a4edce64aac2b10dfb0 to your computer and use it in GitHub Desktop.
Save Th0masStorm/a4119eddd83b2a4edce64aac2b10dfb0 to your computer and use it in GitHub Desktop.
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