forked from snyk/snyk-iac-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 3
/
elasticache.yml
160 lines (138 loc) · 4.83 KB
/
elasticache.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
AWSTemplateFormatVersion: 2010-09-09
# A CloudFormation template to create/configure an AWS ElastiCache Cluster based on parameters,
# along with an associated security group and subnet group.
#
# You can specify either redis or memcached as an engine, the node (aka instance) type, and
# the number of nodes.
#
# From the Startup Kit Templates, this template requires the name of an existing vpc.cfn.yml stack as
# a parameter.
#
# This template is released under Apache Version 2.0, and can be forked, copied, modified,
# customized, etc. to match your application/system requirements.
Description: ElastiCache and related resources
Parameters:
# ElastiCache stack creation prerequisite: First create a VPC stack - see README for more info
NetworkStackName:
Description: Active CloudFormation stack containing VPC resources
Type: String
MinLength: 1
MaxLength: 255
AllowedPattern: "^[a-zA-Z][-a-zA-Z0-9]*$"
ClusterName:
Description: Custom name of the cluster. Auto generated if you don't supply your own.
Type: String
AllowedPattern: "^[a-zA-Z][-a-zA-Z0-9]*$"
CacheNodeType:
Description: Cache node instance class, e.g. cache.t2.micro(free tier). See https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheNodes.SelectSize.html
Type: String
Default: cache.t2.micro
ConstraintDescription: Node instance class not supported
AllowedValues:
- cache.t2.micro
- cache.t2.small
- cache.t2.medium
- cache.m4.large
- cache.m4.xlarge
- cache.m4.2xlarge
- cache.m4.4xlarge
- cache.m4.10xlarge
- cache.r4.large
- cache.r4.xlarge
- cache.r4.2xlarge
- cache.r4.4xlarge
- cache.r4.8xlarge
- cache.r4.16xlarge
CacheEngine:
Description: The underlying cache engine, either Redis or Memcached
Type: String
Default: redis
ConstraintDescription: Node instance class not supported
AllowedValues:
- redis
- memcached
CacheNodeCount:
Description: Number of nodes in the cluster. Only used with memcached engine, for redis this value will be set to 1.
Type: Number
MinValue: 1
MaxValue: 15
ConstraintDescription: Node count must be between 1 and 15
Default: 1
AutoMinorVersionUpgrade:
Description: Whether or not minor version upgrades to the cache engine should be applied automatically during the maintenance window.
Type: String
Default: true
AllowedValues:
- true
- false
Conditions:
IsRedis: !Equals [ !Ref CacheEngine, redis]
Resources:
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: ElastiCache Security Group
VpcId:
Fn::ImportValue: !Sub ${NetworkStackName}-VpcID
SecurityGroupIngress:
-
IpProtocol: tcp
FromPort: !If [ IsRedis, 6379, 11211]
ToPort: !If [ IsRedis, 6379, 11211]
Tags:
-
Key: Name
Value: !Sub "${AWS::StackName}-ElastiCacheSecurityGroup"
SubnetGroup:
Type: AWS::ElastiCache::SubnetGroup
Properties:
Description: Cache Subnet Group
SubnetIds:
- Fn::ImportValue: !Sub ${NetworkStackName}-PrivateSubnet1ID
- Fn::ImportValue: !Sub ${NetworkStackName}-PrivateSubnet2ID
ElastiCacheCluster:
Type: AWS::ElastiCache::CacheCluster
Properties:
AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade
Engine: !Ref CacheEngine
CacheNodeType: !Ref CacheNodeType
ClusterName : !Ref ClusterName
NumCacheNodes: !If [ IsRedis, 1, !Ref CacheNodeCount]
CacheSubnetGroupName: !Ref SubnetGroup
VpcSecurityGroupIds:
- !GetAtt SecurityGroup.GroupId
Tags:
- Key: Name
Value: !Ref AWS::StackName
Outputs:
ElastiCacheStackName:
Description: ElastiCache Stack Name
Value: !Ref AWS::StackName
Export:
Name: !Sub ${AWS::StackName}-ElastiCacheName
ElastiCacheClusterArn:
Description: ElastiCache Cluster Arn
Value: !Sub arn:aws:elasticache:${AWS::Region}:${AWS::AccountId}:cluster/${ElastiCacheCluster}
Export:
Name: !Sub ${AWS::StackName}-ElastiCacheClusterArn
ElastiCacheClusterId:
Description: ElastiCache Cluster ID
Value: !Ref ElastiCacheCluster
Export:
Name: !Sub ${AWS::StackName}-ElastiCacheClusterID
ElastiCacheEngine:
Description: ElastiCache engine
Value: !Ref CacheEngine
Export:
Name: !Sub ${AWS::StackName}-ElastiCacheEngine
ElastiCacheAddress:
Description: ElastiCache endpoint address
Value: !If [ IsRedis, !GetAtt ElastiCacheCluster.RedisEndpoint.Address, !GetAtt ElastiCacheCluster.ConfigurationEndpoint.Address]
Export:
Name: !Sub ${AWS::StackName}-ElastiCacheAddress
ElastiCachePort:
Description: ElastiCache port
Value: !If [ IsRedis, 6379, 11211]
Export:
Name: !Sub ${AWS::StackName}-ElastiCachePort