Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chandra-prakash-meghwal/fdf7e47fc1df5c23e93d403f2db61e7f to your computer and use it in GitHub Desktop.
Save chandra-prakash-meghwal/fdf7e47fc1df5c23e93d403f2db61e7f to your computer and use it in GitHub Desktop.
AWS Cloudformation template to create customizable ElastiCache Redis instance
AWSTemplateFormatVersion: '2010-09-09'
Description: Creates customizable ElastiCache Redis instance.
Parameters:
RedisCacheNodeType:
Type: String
Default: cache.t3.micro
Description: The compute and memory capacity of the nodes in the node group.
SecurityGroup:
Type: AWS::EC2::SecurityGroup::Id
Description: The ID of the VPC security group.
SubnetId1:
Type: AWS::EC2::Subnet::Id
Description: The ID of the first subnet.
SubnetId2:
Type: AWS::EC2::Subnet::Id
Description: The ID of the second subnet.
ResourceNamePrefix:
Type: String
Description: The environment name, used to determine the secret name.
Resources:
ElastiCacheCluster:
Type: AWS::ElastiCache::CacheCluster
Properties:
CacheNodeType: !Ref RedisCacheNodeType
Engine: redis
NumCacheNodes: 1
CacheSubnetGroupName: !Ref CacheSubnetGroup
VpcSecurityGroupIds:
- !Ref SecurityGroup
CacheSubnetGroup:
Type: AWS::ElastiCache::SubnetGroup
Properties:
Description: cache subnet group
SubnetIds:
- !Ref SubnetId1
- !Ref SubnetId2
RedisHostSecret:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Sub "${ResourceNamePrefix}-redis-host"
Description: Redis host for the environment
SecretString: !Sub '{"REDIS_HOST": "${ElastiCacheCluster.RedisEndpoint.Address}"}'
Outputs:
CacheClusterId:
Description: The ElastiCache Cluster ID
Value: !Ref ElastiCacheCluster
RedisHostSecretName:
Description: The name of the Redis Host Secret
Value: !Ref RedisHostSecret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment