Skip to content

Commit f060f3f

Browse files
committed
parametize connection parameters, reduce VPC stack needs, add app node
1 parent fcbc81d commit f060f3f

File tree

6 files changed

+119
-176
lines changed

6 files changed

+119
-176
lines changed

cfns3deploy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aws cloudformation deploy --template-file templates/createS3.yaml --stack-name ${PROJECT_NAME}-s3 --parameter-overrides S3BucketName=${S3_BUCKET}
1+
aws cloudformation deploy --template-file templates/createS3.yaml --stack-name ${PROJECT_NAME}-s3 --parameter-overrides S3BucketName=${S3_BUCKET} KeyPair=${KEY_PAIR}

src/main/java/com/jphaugla/redis/streams/RedisStreams101Consumer.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ public class RedisStreams101Consumer {
1414
public final static String MESSAGE_KEY = "weather_sensor:wind:message:";
1515

1616
public static void main(String[] args) {
17-
String portNumber = "12000";
18-
if (args != null && args.length != 0 ) {
19-
portNumber = args[0];
20-
}
21-
System.out.println("port number is " + portNumber);
22-
RedisClient redisClient = RedisClient.create("redis://localhost:" + portNumber); // change to reflect your environment
17+
18+
String REDIS_URI=System.getenv("REDIS_URI");
19+
System.out.println("Redis URI=" + REDIS_URI);
20+
RedisClient redisClient = RedisClient.create(REDIS_URI);
2321
StatefulRedisConnection<String, String> connection = redisClient.connect();
2422
RedisCommands<String, String> syncCommands = connection.sync();
2523

src/main/java/com/jphaugla/redis/streams/RedisStreams101ConsumerLUA.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ public class RedisStreams101ConsumerLUA {
2222
public final static String APPLICATION_NAME = "application_1";
2323

2424
public static void main(String[] args) throws JsonProcessingException {
25-
String portNumber = "12000";
26-
if (args != null && args.length != 0 ) {
27-
portNumber = args[0];
28-
}
29-
System.out.println("port number is " + portNumber);
30-
RedisClient redisClient = RedisClient.create("redis://localhost:" + portNumber); // change to reflect your environment
25+
26+
String REDIS_URI=System.getenv("REDIS_URI");
27+
System.out.println("Redis URI=" + REDIS_URI);
28+
RedisClient redisClient = RedisClient.create(REDIS_URI);
3129
StatefulRedisConnection<String, String> connection = redisClient.connect();
3230
RedisCommands<String, String> syncCommands = connection.sync();
3331
InputStream luaInputStream =

src/main/java/com/jphaugla/redis/streams/RedisStreams101ProducerSingle.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ public static void main(String[] args) {
2222
}
2323

2424
System.out.printf("\n Sending %s message(s)%n", nbOfMessageToSend);
25+
String REDIS_URI=System.getenv("REDIS_URI");
26+
System.out.println("Redis URI=" + REDIS_URI);
27+
RedisClient redisClient = RedisClient.create(REDIS_URI);
2528

26-
27-
RedisClient redisClient = RedisClient.create("redis://localhost:6379"); // change to reflect your environment
2829
StatefulRedisConnection<String, String> connection = redisClient.connect();
2930
RedisCommands<String, String> syncCommands = connection.sync();
3031

templates/MasterWithRedis.yaml

+99-42
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,39 @@ Transform: 'AWS::Serverless-2016-10-31'
33
Description: Deploy Redis Instances in a region
44

55
Mappings:
6+
67
RegionMap:
78
us-east-1: # Virginia
8-
"EC2AMI" : "ami-0d894ea5521c64557"
9+
"REDISEC2AMI" : "ami-0d894ea5521c64557"
10+
"EC2AMI" : "ami-08e4e35cccc6189f4"
911
us-east-2: # Ohio
10-
"EC2AMI" : "ami-082a25bc38620fc4d"
12+
"REDISEC2AMI" : "ami-082a25bc38620fc4d"
1113
us-east-3: # NCALIF
12-
"EC2AMI" : "ami-01773f954c3875420"
14+
"REDISEC2AMI" : "ami-01773f954c3875420"
1315
us-west-2: # Oregon
14-
"EC2AMI" : "ami-05037ab6f618ed336"
16+
"REDISEC2AMI" : "ami-05037ab6f618ed336"
1517
ap-south-1: # Mumbai
16-
"EC2AMI" : "ami-0eefc21aa52001198"
18+
"REDISEC2AMI" : "ami-0eefc21aa52001198"
1719
ap-northeast-2: # Seoul
18-
"EC2AMI" : "ami-0967b7ff9a7ba331e"
20+
"REDISEC2AMI" : "ami-0967b7ff9a7ba331e"
1921
ap-southeast-1: # Singapore
20-
"EC2AMI" : "ami-052d3e5a59fc4a877"
22+
"REDISEC2AMI" : "ami-052d3e5a59fc4a877"
2123
ap-southeast-2: # Sydney
22-
"EC2AMI" : "ami-097cbef0451a30da5"
24+
"REDISEC2AMI" : "ami-097cbef0451a30da5"
2325
ap-northeast-1: # Tokyo
24-
"EC2AMI" : "ami-0ce04ab8bcd5de2e9"
26+
"REDISEC2AMI" : "ami-0ce04ab8bcd5de2e9"
2527
eu-central-1: # Frankfurt
26-
"EC2AMI" : "ami-09304ee2fe70b3aad"
28+
"REDISEC2AMI" : "ami-09304ee2fe70b3aad"
2729
eu-west-1: # Ireland
28-
"EC2AMI" : "ami-03b7776ede7f47475"
30+
"REDISEC2AMI" : "ami-03b7776ede7f47475"
2931
eu-west-2: # London
30-
"EC2AMI" : "ami-0c2b997e5c91153e0"
32+
"REDISEC2AMI" : "ami-0c2b997e5c91153e0"
3133
eu-west-3: # Paris
32-
"EC2AMI" : "ami-0176733f200a89b17"
34+
"REDISEC2AMI" : "ami-0176733f200a89b17"
3335
eu-north-1: # Stockholm
34-
"EC2AMI" : "ami-040e6fa2d290e7b9b"
36+
"REDISEC2AMI" : "ami-040e6fa2d290e7b9b"
3537
sa-east-1: # Sao Paulo
36-
"EC2AMI" : "ami-06d197a564493b29b"
38+
"REDISEC2AMI" : "ami-06d197a564493b29b"
3739

3840
Parameters:
3941
RedisDatabasePort:
@@ -72,7 +74,7 @@ Parameters:
7274
MinValue: 1
7375
MaxValue: 3
7476
Default: 3
75-
EC2InstanceType:
77+
RedisEC2InstType:
7678
Description: Amazon EC2 Instance Type m4 and m5.xlarge 4-16 m5 has better network, 2xlarge 8-13, r4.xlarge 4 30.5, 8 61
7779
Type: String
7880
Default: r4.2xlarge
@@ -100,6 +102,37 @@ Parameters:
100102
- i3.16xlarge
101103
ConstraintDescription: Must be a valid EC2 instance type.
102104

105+
EC2InstType:
106+
Description: Amazon EC2 Instance Type for app node
107+
Type: String
108+
Default: i3.large
109+
AllowedValues:
110+
- r4.large
111+
- r4.xlarge
112+
- r4.2xlarge
113+
- r4.4xlarge
114+
- r4.8xlarge
115+
- r4.16xlarge
116+
- m4.large
117+
- m4.xlarge
118+
- m4.2xlarge
119+
- m4.4xlarge
120+
- m4.10xlarge
121+
- m4.16xlarge
122+
- c5a.large
123+
- c5a.xlarge
124+
- c5a.2xlarge
125+
- c5a.4xlarge
126+
- c5a.8xlarge
127+
- c5a.16xlarge
128+
- i3.large
129+
- i3.xlarge
130+
- i3.2xlarge
131+
- i3.4xlarge
132+
- i3.8xlarge
133+
- i3.16xlarge
134+
ConstraintDescription: Must be a valid EC2 instance type.
135+
103136
Conditions:
104137
Create-One: !Equals [ !Ref NumberInstances, 1 ]
105138
Create-Two: !Equals [ !Ref NumberInstances, 2 ]
@@ -121,7 +154,7 @@ Resources:
121154
'AWS::CloudFormation::Designer':
122155
id: 7aa57bac-380e-4523-a72b-ef898d0a0367
123156

124-
RedisEC2N1:
157+
RedisEC2VM1:
125158
Type: AWS::EC2::Instance
126159
DependsOn:
127160
- VPCStack
@@ -130,8 +163,8 @@ Resources:
130163
Fn::FindInMap:
131164
- RegionMap
132165
- !Ref AWS::Region
133-
- EC2AMI
134-
InstanceType: !Ref EC2InstanceType
166+
- REDISEC2AMI
167+
InstanceType: !Ref RedisEC2InstType
135168
SubnetId: !GetAtt VPCStack.Outputs.PublicSubnet1Id
136169
KeyName: !Ref KeyPair
137170
SecurityGroupIds:
@@ -160,19 +193,19 @@ Resources:
160193
tar xvf redislabs-6.2.8-53-rhel7-x86_64.tar
161194
./install.sh -y
162195

163-
RedisEC2N2:
196+
RedisEC2VM2:
164197
Type: AWS::EC2::Instance
165198
Condition: Do-Two
166199
DependsOn:
167200
- VPCStack
168-
- RedisEC2N1
201+
- RedisEC2VM1
169202
Properties:
170203
ImageId:
171204
Fn::FindInMap:
172205
- RegionMap
173206
- !Ref AWS::Region
174-
- EC2AMI
175-
InstanceType: !Ref EC2InstanceType
207+
- REDISEC2AMI
208+
InstanceType: !Ref RedisEC2InstType
176209
SubnetId: !GetAtt VPCStack.Outputs.PublicSubnet1Id
177210
KeyName: !Ref KeyPair
178211
SecurityGroupIds:
@@ -194,19 +227,19 @@ Resources:
194227
tar xvf redislabs-6.2.8-53-rhel7-x86_64.tar
195228
./install.sh -y
196229

197-
RedisEC2N3:
230+
RedisEC2VM3:
198231
Condition: Create-Three
199232
Type: AWS::EC2::Instance
200233
DependsOn:
201234
- VPCStack
202-
- RedisEC2N1
235+
- RedisEC2VM1
203236
Properties:
204237
ImageId:
205238
Fn::FindInMap:
206239
- RegionMap
207240
- !Ref AWS::Region
208-
- EC2AMI
209-
InstanceType: !Ref EC2InstanceType
241+
- REDISEC2AMI
242+
InstanceType: !Ref RedisEC2InstType
210243
SubnetId: !GetAtt VPCStack.Outputs.PublicSubnet1Id
211244
KeyName: !Ref KeyPair
212245
SecurityGroupIds:
@@ -228,46 +261,74 @@ Resources:
228261
tar xvf redislabs-6.2.8-53-rhel7-x86_64.tar
229262
./install.sh -y
230263

264+
AppEC2Instance:
265+
Type: AWS::EC2::Instance
266+
DependsOn:
267+
- VPCStack
268+
Properties:
269+
ImageId:
270+
Fn::FindInMap:
271+
- RegionMap
272+
- !Ref AWS::Region
273+
- EC2AMI
274+
InstanceType: !Ref EC2InstType
275+
SubnetId: !GetAtt VPCStack.Outputs.PublicSubnet1Id
276+
KeyName: !Ref KeyPair
277+
SecurityGroupIds:
278+
- !GetAtt VPCStack.Outputs.WorkshopSecurityGroup
279+
Tags:
280+
- Key: 'Name'
281+
Value: !Join ['', [!Ref AWS::StackName, 'APPEC2'] ]
282+
UserData:
283+
Fn::Base64:
284+
!Sub |
285+
#!/bin/bash -xe
286+
sudo bash -l
287+
yum -y install git wget bind-utils maven java-1.8.0-openjdk
288+
cd /home/ec2-user
289+
git clone https://github.com/jphaugla/redisSMSLuaA-A.git
290+
sudo chown -R ec2-user:ec2-user redisSMSLuaA-A
291+
231292
RedisARecord1:
232293
Type: AWS::Route53::RecordSet
233294
DependsOn:
234-
- RedisEC2N1
295+
- RedisEC2VM1
235296
Properties:
236297
HostedZoneId: !Ref HostedZoneId
237298
Comment: DNS name for my instance
238299
Name: !Join ['', ['node1.', !Ref ClusterName, ., !Ref HostedZoneName ] ]
239300
Type: A
240301
TTL: 900
241302
ResourceRecords:
242-
- !GetAtt RedisEC2N1.PublicIp
303+
- !GetAtt RedisEC2VM1.PublicIp
243304

244305
RedisARecord2:
245306
Condition: Do-Two
246307
Type: AWS::Route53::RecordSet
247308
DependsOn:
248-
- RedisEC2N2
309+
- RedisEC2VM2
249310
Properties:
250311
HostedZoneId: !Ref HostedZoneId
251312
Comment: DNS name for my instance
252313
Name: !Join ['', ['node2.', !Ref ClusterName, ., !Ref HostedZoneName ] ]
253314
Type: A
254315
TTL: 900
255316
ResourceRecords:
256-
- !GetAtt RedisEC2N2.PublicIp
317+
- !GetAtt RedisEC2VM2.PublicIp
257318

258319
RedisARecord3:
259320
Condition: Create-Three
260321
Type: AWS::Route53::RecordSet
261322
DependsOn:
262-
- RedisEC2N3
323+
- RedisEC2VM3
263324
Properties:
264325
HostedZoneId: !Ref HostedZoneId
265326
Comment: DNS name for my instance
266327
Name: !Join ['', ['node3.', !Ref ClusterName, ., !Ref HostedZoneName ] ]
267328
Type: A
268329
TTL: 900
269330
ResourceRecords:
270-
- !GetAtt RedisEC2N3.PublicIp
331+
- !GetAtt RedisEC2VM3.PublicIp
271332

272333
RedisNSRecord:
273334
Type: AWS::Route53::RecordSet
@@ -285,31 +346,27 @@ Outputs:
285346

286347
Subnets:
287348
Description: Subnets for workshop
288-
Value: !Join [',', [!GetAtt VPCStack.Outputs.PublicSubnet1Id,!GetAtt VPCStack.Outputs.PublicSubnet2Id,!GetAtt VPCStack.Outputs.PublicSubnet3Id]]
349+
Value: !Join [',', [!GetAtt VPCStack.Outputs.PublicSubnet1Id]]
289350

290351
WorkshopSecurityGroup:
291352
Description: 'Security Group'
292353
Value: !GetAtt VPCStack.Outputs.WorkshopSecurityGroup
293354

294-
EMRSecurityGroup:
295-
Description: 'Security Group'
296-
Value: !GetAtt VPCStack.Outputs.EMRSecurityGroup
297-
298355
RedisInstancePrivateDNS:
299356
Description: 'Private DNS for Redis EC2 instance'
300-
Value: !GetAtt RedisEC2N1.PrivateDnsName
357+
Value: !GetAtt RedisEC2VM1.PrivateDnsName
301358

302359
RedisInstancePublicDNS:
303360
Description: 'Public DNS for Redis EC2 instance'
304-
Value: !GetAtt RedisEC2N1.PublicDnsName
361+
Value: !GetAtt RedisEC2VM1.PublicDnsName
305362

306363
RedisInstancePrivateIP:
307364
Description: 'Private IP for Redis EC2 instance'
308-
Value: !GetAtt RedisEC2N1.PrivateIp
365+
Value: !GetAtt RedisEC2VM1.PrivateIp
309366

310367
RedisInstancePublicIP:
311368
Description: 'Public IP for Redis EC2 instance'
312-
Value: !GetAtt RedisEC2N1.PublicIp
369+
Value: !GetAtt RedisEC2VM1.PublicIp
313370

314371
RedisNSRecord:
315372
Description: 'The NS Record Name for Redis'

0 commit comments

Comments
 (0)