-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.yml
More file actions
164 lines (143 loc) · 4.04 KB
/
test.yml
File metadata and controls
164 lines (143 loc) · 4.04 KB
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
161
162
163
164
AWSTemplateFormatVersion: '2010-09-09'
Description: 'CloudFormation template for ElastiCache with EC2 bastion host'
Parameters:
VpcCIDR:
Type: String
Default: 10.0.0.0/16
Description: CIDR block for VPC
PublicSubnetCIDR:
Type: String
Default: 10.0.1.0/24
Description: CIDR block for public subnet
PrivateSubnetCIDR:
Type: String
Default: 10.0.2.0/24
Description: CIDR block for private subnet
KeyPairName:
Type: AWS::EC2::KeyPair::KeyName
Description: Name of existing EC2 KeyPair for SSH access
YourIP:
Type: String
Description: Your local IP address in CIDR notation (e.g., 1.2.3.4/32)
Resources:
# VPC Configuration
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCIDR
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value: Elasticache-VPC
# Internet Gateway
InternetGateway:
Type: AWS::EC2::InternetGateway
AttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
# Public Subnet
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref PublicSubnetCIDR
AvailabilityZone: !Select [0, !GetAZs '']
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: Public Subnet
# Private Subnet
PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref PrivateSubnetCIDR
AvailabilityZone: !Select [0, !GetAZs '']
Tags:
- Key: Name
Value: Private Subnet
# Route Tables
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: Public Route Table
PublicRoute:
Type: AWS::EC2::Route
DependsOn: AttachGateway
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnet
RouteTableId: !Ref PublicRouteTable
# Security Groups
BastionSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for bastion host
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref YourIP
ElastiCacheSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for ElastiCache
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 6379
ToPort: 6379
SourceSecurityGroupId: !Ref BastionSecurityGroup
# ElastiCache Subnet Group
ElastiCacheSubnetGroup:
Type: AWS::ElastiCache::SubnetGroup
Properties:
Description: Subnet group for ElastiCache
SubnetIds:
- !Ref PrivateSubnet
# ElastiCache Cluster
ElastiCacheCluster:
Type: AWS::ElastiCache::CacheCluster
Properties:
Engine: redis
CacheNodeType: cache.t3.micro
NumCacheNodes: 1
Port: 6379
CacheSubnetGroupName: !Ref ElastiCacheSubnetGroup
VpcSecurityGroupIds:
- !Ref ElastiCacheSecurityGroup
# EC2 Instance (Bastion Host)
BastionHost:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-0440d3b780d96b29d # Amazon Linux 2 AMI ID (us-east-1)
KeyName: !Ref KeyPairName
SubnetId: !Ref PublicSubnet
SecurityGroupIds:
- !Ref BastionSecurityGroup
Tags:
- Key: Name
Value: Bastion Host
Outputs:
BastionPublicIP:
Description: Public IP of the bastion host
Value: !GetAtt BastionHost.PublicIp
ElastiCacheEndpoint:
Description: ElastiCache endpoint
Value: !GetAtt ElastiCacheCluster.RedisEndpoint.Address
SSHCommand:
Description: Command to SSH into bastion host
Value: !Sub "ssh -i ${KeyPairName}.pem ec2-user@${BastionHost.PublicIp}"