forked from wso2/aws-apim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apim-ha.yaml
1181 lines (1173 loc) · 39.4 KB
/
apim-ha.yaml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
AWSTemplateFormatVersion: 2010-09-09
Description: >-
WSO2 API Manager deployment
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: Basic Configuration
Parameters:
- AWSAccessKeyId
- AWSAccessKeySecret
- KeyPairName
- WSO2InstanceType
- CertificateName
- DBUsername
- DBPassword
- WUMUsername
- WUMPassword
- Label:
default: Advanced Configuration (Defaults will be used, if not set)
Parameters:
- OperatingSystem
- ProductVersion
- DB
- DBAllocationStorage
- DBInstanceType
- CustomUserData
- ElasticSearchEndpoint
ParameterLabels:
AWSAccessKeyId:
default: AWS Access Key
AWSAccessKeySecret:
default: AWS Secret Key
OperatingSystem:
default: Operating System
CertificateName:
default: SSL Certificate Name
KeyPairName:
default: Key Pair
DBUsername:
default: Database Username
DBPassword:
default: Database Password
DBAllocationStorage:
default: Database Storage Allocation
DBInstanceType:
default: Database Instance Type
CustomUserData:
default: Custom User Data
WUMUsername:
default: WSO2 Username
WUMPassword:
default: WSO2 Password
WSO2InstanceType:
default: Instance Type
DB:
default: Database Engine and Version
ElasticSearchEndpoint:
default: ElasticSearch Endpoint
Resources:
# networking configurations
WSO2APIMVPC:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
WSO2APIMPublicSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref WSO2APIMVPC
CidrBlock: 10.0.254.0/24
AvailabilityZone: !Select
- '0'
- !GetAZs ''
WSO2APIMPublicSubnet2:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref WSO2APIMVPC
CidrBlock: 10.0.252.0/24
AvailabilityZone: !Select
- '1'
- !GetAZs ''
WSO2APIMPublicInternetGateway:
Type: 'AWS::EC2::InternetGateway'
WSO2APIMPublicRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref WSO2APIMVPC
WSO2APIMPublicSubnet1RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref WSO2APIMPublicRouteTable
SubnetId: !Ref WSO2APIMPublicSubnet1
WSO2APIMPublicSubnet2RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref WSO2APIMPublicRouteTable
SubnetId: !Ref WSO2APIMPublicSubnet2
WSO2APIMPublicRoute:
Type: 'AWS::EC2::Route'
Properties:
RouteTableId: !Ref WSO2APIMPublicRouteTable
GatewayId: !Ref WSO2APIMPublicInternetGateway
DestinationCidrBlock: 0.0.0.0/0
DependsOn: WSO2APIMVPCInternetGatewayAttachment
WSO2APIMVPCInternetGatewayAttachment:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
InternetGatewayId: !Ref WSO2APIMPublicInternetGateway
VpcId: !Ref WSO2APIMVPC
WSO2APIMPrivateSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref WSO2APIMVPC
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Select
- '0'
- !GetAZs ''
WSO2APIMPrivateSubnet2:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref WSO2APIMVPC
CidrBlock: 10.0.2.0/24
AvailabilityZone: !Select
- '1'
- !GetAZs ''
WSO2APIMPrivateSubnetRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref WSO2APIMVPC
WSO2APIMPrivateRoute:
Type: 'AWS::EC2::Route'
Properties:
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref WSO2APIMNATGateway
RouteTableId: !Ref WSO2APIMPrivateSubnetRouteTable
WSO2APIMPrivateSubnet1RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref WSO2APIMPrivateSubnetRouteTable
SubnetId: !Ref WSO2APIMPrivateSubnet1
WSO2APIMPrivateSubnet2RouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref WSO2APIMPrivateSubnetRouteTable
SubnetId: !Ref WSO2APIMPrivateSubnet2
WSO2APIMNATGateway:
Type: 'AWS::EC2::NatGateway'
Properties:
AllocationId: !GetAtt
- WSO2APIMEIP
- AllocationId
SubnetId: !Ref WSO2APIMPublicSubnet1
WSO2BastionEIPAssociation:
Type: 'AWS::EC2::EIPAssociation'
Properties:
AllocationId: !GetAtt WSO2BastionEIP.AllocationId
InstanceId: !Ref WSO2BastionInstance
WSO2APIMEIP:
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
WSO2BastionEIP:
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
# database configurations
WSO2APIMDBInstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref WSO2APIMVPC
GroupDescription: DB Security Group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '3306'
ToPort: '3306'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '5432'
ToPort: '5432'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '1521'
ToPort: '1521'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '1433'
ToPort: '1433'
CidrIp: 0.0.0.0/0
WSO2APIMDBInstance:
Type: 'AWS::RDS::DBInstance'
DeletionPolicy: Delete
Properties:
VPCSecurityGroups:
- !Ref WSO2APIMDBInstanceSecurityGroup
DBInstanceClass: !Ref DBInstanceType
AllocatedStorage: !Ref DBAllocationStorage
BackupRetentionPeriod: '0'
DBInstanceIdentifier: WSO2APIMDBInstance
DBName: !If [UseSQLServerDB, "", WSO2AMDB]
LicenseModel: !If [UseLicensedVersion, license-included, !Ref 'AWS::NoValue']
EngineVersion: !Select [1, !Split ["_", !FindInMap [ DBEngineMap, !Ref DB, DBEngine]]]
Engine: !Select [0, !Split ["_", !FindInMap [ DBEngineMap, !Ref DB, DBEngine]]]
MasterUsername: !Ref DBUsername
MasterUserPassword: !Ref DBPassword
MultiAZ: 'false'
StorageType: gp2
DBSubnetGroupName: !Ref WSO2APIMDBSubnetGroup
WSO2APIMDBSubnetGroup:
Type: 'AWS::RDS::DBSubnetGroup'
Properties:
DBSubnetGroupDescription: DB Subnet Group
SubnetIds:
- !Ref WSO2APIMPrivateSubnet1
- !Ref WSO2APIMPrivateSubnet2
# File system configurations
WSO2APIMEFSSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref WSO2APIMVPC
GroupDescription: EFS Security Group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '2049'
ToPort: '2049'
CidrIp: 0.0.0.0/0
WSO2APIMEFSFileSystem:
Type: 'AWS::EFS::FileSystem'
Properties:
PerformanceMode: generalPurpose
WSO2APIMPrivateSubnet1EFSMountTarget:
Type: 'AWS::EFS::MountTarget'
Properties:
SubnetId: !Ref WSO2APIMPrivateSubnet1
FileSystemId: !Ref WSO2APIMEFSFileSystem
SecurityGroups:
- !Ref WSO2APIMEFSSecurityGroup
WSO2APIMPrivateSubnet2EFSMountTarget:
Type: 'AWS::EFS::MountTarget'
Properties:
SubnetId: !Ref WSO2APIMPrivateSubnet2
FileSystemId: !Ref WSO2APIMEFSFileSystem
SecurityGroups:
- !Ref WSO2APIMEFSSecurityGroup
# Product configurations
BastionSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref WSO2APIMVPC
GroupDescription: WSO2 API Manager Security Group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
WSO2APIMSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref WSO2APIMVPC
GroupDescription: WSO2 API Manager Security Group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '8280'
ToPort: '8280'
SourceSecurityGroupId: !Ref WSO2APIMLoadBalancerSecurityGroup
- IpProtocol: tcp
FromPort: '9763'
ToPort: '9763'
SourceSecurityGroupId: !Ref WSO2APIMLoadBalancerSecurityGroup
- IpProtocol: tcp
FromPort: '9443'
ToPort: '9443'
SourceSecurityGroupId: !Ref WSO2APIMLoadBalancerSecurityGroup
- IpProtocol: tcp
FromPort: '8243'
ToPort: '8243'
SourceSecurityGroupId: !Ref WSO2APIMLoadBalancerSecurityGroup
- IpProtocol: tcp
FromPort: '5672'
ToPort: '5672'
SourceSecurityGroupId: !Ref WSO2APIMLoadBalancerSecurityGroup
- IpProtocol: tcp
FromPort: '8140'
ToPort: '8140'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '4000'
ToPort: '4000'
CidrIp: 0.0.0.0/0
WSO2BastionInstance:
Type: 'AWS::EC2::Instance'
Properties:
DisableApiTermination: 'false'
InstanceInitiatedShutdownBehavior: stop
ImageId: !FindInMap
- WSO2APIMAMIRegionMap
- !Ref 'AWS::Region'
- Ubuntu1804
InstanceType: t2.micro
KeyName: !Ref KeyPairName
Monitoring: 'false'
Tags:
- Key: Name
Value: WSO2BastionInstance
NetworkInterfaces:
- DeleteOnTermination: 'true'
Description: Primary network interface
DeviceIndex: 0
SubnetId: !Ref WSO2APIMPublicSubnet1
GroupSet:
- !Ref BastionSecurityGroup
PuppetMaster:
Type: 'AWS::EC2::Instance'
Properties:
DisableApiTermination: 'false'
InstanceInitiatedShutdownBehavior: stop
ImageId: !FindInMap
- WSO2PuppetMasterRegionMap
- !Ref 'AWS::Region'
- Ubuntu1804
InstanceType: !Ref WSO2InstanceType
KeyName: !Ref KeyPairName
Monitoring: 'false'
Tags:
- Key: Name
Value: PuppetMasterInstance
NetworkInterfaces:
- DeleteOnTermination: 'true'
Description: Primary network interface
DeviceIndex: 0
SubnetId: !Ref WSO2APIMPrivateSubnet1
GroupSet:
- !Ref PuppetMasterSecurityGroup
UserData: !Base64
'Fn::Join':
- |+
- - '#!/bin/bash'
- 'export PATH=~/.local/bin:$PATH'
- echo "> Set hostname to puppetmaster"
- hostname puppetmaster
- echo $(hostname) >> /etc/hostname
- echo "127.0.0.1 $(hostname)" >> /etc/hosts
- sed -i '/\[main\]/a dns_alt_names=puppetmaster,puppet' /etc/puppet/puppet.conf
- sed -i '/\[master\]/a autosign=true' /etc/puppet/puppet.conf
- service puppetmaster restart
- !Sub "./home/ubuntu/wso2-init.sh ${WUMUsername} ${WUMPassword} wso2am-2.6.0 False"
- !Join
- ''
- - sed -i "s/access-key/
- !Ref AWSAccessKeyId
- /g" /etc/puppet/code/environments/production/modules/apim260/manifests/params.pp
- !Join
- ''
- - sed -i "s/REGION_NAME/
- !Ref "AWS::Region"
- /g" /etc/puppet/code/environments/production/modules/apim260/manifests/params.pp
- !Join
- ''
- - sed -i "s^secretkey^
- !Ref AWSAccessKeySecret
- ^g" /etc/puppet/code/environments/production/modules/apim260/manifests/params.pp
- !Join
- ''
- - sed -i "s/CF_ELB_DNS_NAME/
- !GetAtt
- WSO2APIMLoadBalancer
- DNSName
- >-
/g"
/etc/puppet/code/environments/production/modules/apim260/manifests/params.pp
- !Join
- ''
- - sed -i "s/CF_DB_USERNAME/
- !Ref DBUsername
- /g" /etc/puppet/code/environments/production/modules/apim260/manifests/params.pp
- !Join
- ''
- - sed -i "s/CF_DB_PASSWORD/
- !Ref DBPassword
- /g" /etc/puppet/code/environments/production/modules/apim260/manifests/params.pp
- !Join
- ''
- - sed -i "s/CF_DBMS/
- !Select [0, !Split ["_", !FindInMap [ DBEngineMap, !Ref DB, DBEngine]]]
- /g" /etc/puppet/code/environments/production/modules/apim260/manifests/params.pp
- !Join
- ''
- - sed -i "s/CF_RDS_URL/
- !GetAtt
- WSO2APIMDBInstance
- Endpoint.Address
- /g" /etc/puppet/code/environments/production/modules/apim260/manifests/params.pp
- export DB_NAME=WSO2AMDB
- !Join
- ''
- - export DB_HOSTNAME=
- !GetAtt
- WSO2APIMDBInstance
- Endpoint.Address
- !Join
- ''
- - export DB_PORT=
- !GetAtt
- WSO2APIMDBInstance
- Endpoint.Port
- !Join
- ''
- - export DB_USERNAME=
- !Ref DBUsername
- !Join
- ''
- - export DB_PASSWORD=
- !Ref DBPassword
- !Join
- ''
- - sed -i "s/CF_DB_USERNAME/
- !Ref DBUsername
- /g" /usr/local/bin/provision_db_apim.sh
- !Join
- ''
- - sed -i "s/CF_DB_PASSWORD/
- !Ref DBPassword
- /g" /usr/local/bin/provision_db_apim.sh
- !Join
- ''
- - sed -i "s/CF_DB_HOST/
- !GetAtt
- WSO2APIMDBInstance
- Endpoint.Address
- /g" /usr/local/bin/provision_db_apim.sh
- !Join
- ''
- - sed -i "s/CF_DB_PORT/
- !GetAtt
- WSO2APIMDBInstance
- Endpoint.Port
- /g" /usr/local/bin/provision_db_apim.sh
- !Join
- ''
- - sed -i "s/CF_DBMS_NAME/
- !Select [0, !Split ["_", !FindInMap [ DBEngineMap, !Ref DB, DBEngine]]]
- /g" /usr/local/bin/provision_db_apim.sh
- !Join
- ''
- - sed -i "s/CF_DBMS_VERSION/
- !Select [1, !Split ["_", !FindInMap [ DBEngineMap, !Ref DB, DBEngine]]]
- /g" /usr/local/bin/provision_db_apim.sh
- !Join
- ''
- - sed -i "s/CF_PRODUCT_VERSION/
- 2.6.0
- /g" /usr/local/bin/provision_db_apim.sh
- bash /usr/local/bin/provision_db_apim.sh
PuppetMasterSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref WSO2APIMVPC
GroupDescription: WSO2 API Manager Security Group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '8140'
ToPort: '8140'
CidrIp: 0.0.0.0/0
WSO2APIMNode1LaunchConfiguration:
Type: 'AWS::AutoScaling::LaunchConfiguration'
Properties:
ImageId: !FindInMap
- WSO2APIMAMIRegionMap
- !Ref 'AWS::Region'
- !Ref OperatingSystem
InstanceType: !Ref WSO2InstanceType
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: '20'
VolumeType: gp2
DeleteOnTermination: 'true'
KeyName: !Ref KeyPairName
SecurityGroups:
- !Ref WSO2APIMSecurityGroup
UserData: !Base64
'Fn::Sub': |
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
export PATH=~/.local/bin:$PATH
if [[ ${OperatingSystem} == "Ubuntu1804" ]]; then
apt-get update
apt install -y puppet nfs-common
apt install -y python-pip
sed -i '/\[main\]/a server=puppet' /etc/puppet/puppet.conf
fi
if [[ ${OperatingSystem} == "CentOS7" ]]; then
yum install -y epel-release unzip nfs-utils
yum install -y python-pip
rpm -Uvh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
yum install -y puppet-agent
echo $'[main]\nserver = puppet\ncertname = agent1\nenvironment = production\n\runinterval = 1h' > /etc/puppetlabs/puppet/puppet.conf
fi
pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
sed -i '/\[main\]/a server=puppet' /etc/puppet/puppet.conf
export ProductVersion=2.6.0
sed -i "s/Product_Version/2.6.0/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s^secret-key^${AWSAccessKeySecret}^g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s/access-key/${AWSAccessKeyId}/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s^ELASTICSEARCH_ENDPOINT^${ElasticSearchEndpoint}^g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
export INSTANCEID=$(ec2metadata | grep -m 1 'instance-id:' | awk '{print $2}')
sed -i "s/INSTANCE_ID/$INSTANCEID/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s/STACK_NAME/${AWS::StackName}/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s/REGION_NAME/${AWS::Region}/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
nohup /home/ubuntu/logstash-6.5.1/bin/logstash -f /home/ubuntu/logstash-6.5.1/logstash-APIM.conf &
export PuppetmasterIP=${PuppetMaster.PrivateIp}
echo "$PuppetmasterIP puppet puppetmaster" >> /etc/hosts
service puppet restart
mkdir -p /mnt/efs
mount -t nfs4 -o nfsvers=4.1 ${WSO2APIMEFSFileSystem}.efs.${AWS::Region}.amazonaws.com:/ /mnt/efs
sleep 180
export FACTER_profile=apim260
if [[ ${OperatingSystem} == "Ubuntu1804" ]]; then
puppet agent -vt
fi
if [[ ${OperatingSystem} == "CentOS7" ]]; then
/opt/puppetlabs/bin/puppet agent -vt
fi
sleep 30
if [ ! -d "/mnt/efs/server" ]; then
mkdir -p /mnt/efs/server
cp -r /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/deployment/server /mnt/efs
fi
rm -rf /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/deployment/server
ln -s /mnt/efs/server /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/deployment/server
if [ ! -d "/mnt/efs/tenants" ]; then
mkdir -p /mnt/efs/tenants
cp -r /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/tenants /mnt/efs
fi
rm -rf /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/tenants
ln -s /mnt/efs/tenants /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/tenants
echo "${WSO2APIMEFSFileSystem}:/ /mnt/efs efs defaults,_netdev 0 0" >> /etc/fstab
/usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/bin/wso2server.sh start
${CustomUserData}
sleep 30
if [[ ${OperatingSystem} == "Ubuntu1804" ]]; then
end=$((SECONDS+1200))
while [ $SECONDS -lt $end ] ; do
sleep 10
wget --delete-after --server-response --no-check-certificate "https://localhost:9443/carbon/admin/login.jsp"
if [ $? -eq "0" ] ; then
/usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WSO2APIMNode1AutoScalingGroup --region ${AWS::Region}
break
fi
done
fi
if [[ ${OperatingSystem} == "CentOS7" ]]; then
end=$((SECONDS+1200))
while [ $SECONDS -lt $end ] ; do
sleep 10
wget --delete-after --server-response --no-check-certificate "https://localhost:9443/carbon/admin/login.jsp"
if [ $? -eq "0" ] ; then
/usr/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WSO2APIMNode1AutoScalingGroup --region ${AWS::Region}
break
fi
done
fi
echo 'export HISTTIMEFORMAT="%F %T "' >> /etc/profile.d/history.sh
cat /dev/null > ~/.bash_history && history -c
DependsOn:
- WSO2APIMSecurityGroup
- WSO2APIMLoadBalancer
- WSO2APIMVPCInternetGatewayAttachment
- PuppetMaster
WSO2APIMNode1AutoScalingGroup:
Type: 'AWS::AutoScaling::AutoScalingGroup'
Properties:
LaunchConfigurationName: !Ref WSO2APIMNode1LaunchConfiguration
DesiredCapacity: 1
MinSize: 1
MaxSize: 1
TargetGroupARNs:
- !Ref WSO2APIMALBTargetGroup
- !Ref WSO2APIMALB8243TargetGroup
VPCZoneIdentifier:
- !Ref WSO2APIMPrivateSubnet1
Tags:
- Key: Name
Value: WSO2APIMInstance1
PropagateAtLaunch: 'true'
- Key: cluster
Value: apim
PropagateAtLaunch: 'true'
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: PT30M
UpdatePolicy:
AutoScalingRollingUpdate:
MaxBatchSize: '2'
MinInstancesInService: '1'
PauseTime: PT10M
SuspendProcesses:
- AlarmNotification
WaitOnResourceSignals: true
DependsOn:
- WSO2APIMLoadBalancer
WSO2APIMNode2LaunchConfiguration:
Type: 'AWS::AutoScaling::LaunchConfiguration'
Properties:
ImageId: !FindInMap
- WSO2APIMAMIRegionMap
- !Ref 'AWS::Region'
- !Ref OperatingSystem
InstanceType: !Ref WSO2InstanceType
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: '20'
VolumeType: gp2
DeleteOnTermination: 'true'
KeyName: !Ref KeyPairName
SecurityGroups:
- !Ref WSO2APIMSecurityGroup
UserData: !Base64
'Fn::Sub': |
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
export PATH=~/.local/bin:$PATH
if [[ ${OperatingSystem} == "Ubuntu1804" ]]; then
apt-get update
apt install -y puppet nfs-common
apt install -y python-pip
sed -i '/\[main\]/a server=puppet' /etc/puppet/puppet.conf
fi
if [[ ${OperatingSystem} == "CentOS7" ]]; then
yum install -y epel-release unzip nfs-utils
yum install -y python-pip
rpm -Uvh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
yum install -y puppet-agent
echo $'[main]\nserver = puppet\ncertname = agent2\nenvironment = production\n\runinterval = 1h' > /etc/puppetlabs/puppet/puppet.conf
fi
pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
sed -i '/\[main\]/a server=puppet' /etc/puppet/puppet.conf
export ProductVersion=2.6.0
sed -i "s/Product_Version/2.6.0/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s^secret-key^${AWSAccessKeySecret}^g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s/access-key/${AWSAccessKeyId}/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s^ELASTICSEARCH_ENDPOINT^${ElasticSearchEndpoint}^g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
export INSTANCEID=$(ec2metadata | grep -m 1 'instance-id:' | awk '{print $2}')
sed -i "s/INSTANCE_ID/$INSTANCEID/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s/STACK_NAME/${AWS::StackName}/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
sed -i "s/REGION_NAME/${AWS::Region}/g" /home/ubuntu/logstash-6.5.1/logstash-APIM.conf
nohup /home/ubuntu/logstash-6.5.1/bin/logstash -f /home/ubuntu/logstash-6.5.1/logstash-APIM.conf &
export PuppetmasterIP=${PuppetMaster.PrivateIp}
echo "$PuppetmasterIP puppet puppetmaster" >> /etc/hosts
service puppet restart
mkdir -p /mnt/efs
mount -t nfs4 -o nfsvers=4.1 ${WSO2APIMEFSFileSystem}.efs.${AWS::Region}.amazonaws.com:/ /mnt/efs
sleep 300
export FACTER_profile=apim260
if [[ ${OperatingSystem} == "Ubuntu1804" ]]; then
puppet agent -vt
fi
if [[ ${OperatingSystem} == "CentOS7" ]]; then
/opt/puppetlabs/bin/puppet agent -vt
fi
sleep 30
if [ ! -d "/mnt/efs/server" ]; then
mkdir -p /mnt/efs/server
cp -r /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/deployment/server /mnt/efs
fi
rm -rf /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/deployment/server
ln -s /mnt/efs/server /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/deployment/server
if [ ! -d "/mnt/efs/tenants" ]; then
mkdir -p /mnt/efs/tenants
cp -r /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/tenants /mnt/efs
fi
rm -rf /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/tenants
ln -s /mnt/efs/tenants /usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/repository/tenants
echo "${WSO2APIMEFSFileSystem}:/ /mnt/efs efs defaults,_netdev 0 0" >> /etc/fstab
/usr/lib/wso2/wso2am/2.6.0/wso2am-2.6.0/bin/wso2server.sh start
${CustomUserData}
sleep 30
if [[ ${OperatingSystem} == "Ubuntu1804" ]]; then
end=$((SECONDS+1200))
while [ $SECONDS -lt $end ] ; do
sleep 10
wget --delete-after --server-response --no-check-certificate "https://localhost:9443/carbon/admin/login.jsp"
if [ $? -eq "0" ] ; then
/usr/local/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WSO2APIMNode2AutoScalingGroup --region ${AWS::Region}
break
fi
done
fi
if [[ ${OperatingSystem} == "CentOS7" ]]; then
end=$((SECONDS+1200))
while [ $SECONDS -lt $end ] ; do
sleep 10
wget --delete-after --server-response --no-check-certificate "https://localhost:9443/carbon/admin/login.jsp"
if [ $? -eq "0" ] ; then
/usr/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WSO2APIMNode2AutoScalingGroup --region ${AWS::Region}
break
fi
done
fi
echo 'export HISTTIMEFORMAT="%F %T "' >> /etc/profile.d/history.sh
cat /dev/null > ~/.bash_history && history -c
DependsOn:
- WSO2APIMSecurityGroup
- WSO2APIMLoadBalancer
- WSO2APIMVPCInternetGatewayAttachment
- PuppetMaster
WSO2APIMNode2AutoScalingGroup:
Type: 'AWS::AutoScaling::AutoScalingGroup'
Properties:
LaunchConfigurationName: !Ref WSO2APIMNode2LaunchConfiguration
DesiredCapacity: 1
MinSize: 1
MaxSize: 1
TargetGroupARNs:
- !Ref WSO2APIMALBTargetGroup
- !Ref WSO2APIMALB8243TargetGroup
VPCZoneIdentifier:
- !Ref WSO2APIMPrivateSubnet2
Tags:
- Key: Name
Value: WSO2APIMInstance2
PropagateAtLaunch: 'true'
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: PT30M
UpdatePolicy:
AutoScalingRollingUpdate:
MaxBatchSize: '2'
MinInstancesInService: '1'
PauseTime: PT10M
SuspendProcesses:
- AlarmNotification
WaitOnResourceSignals: true
DependsOn:
- WSO2APIMLoadBalancer
WSO2APIMLoadBalancerSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref WSO2APIMVPC
GroupDescription: WSO2 APIM ELB Security Group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '9763'
ToPort: '9763'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '9443'
ToPort: '9443'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '8243'
ToPort: '8243'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '8280'
ToPort: '8280'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '4000'
ToPort: '4000'
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: '9763'
ToPort: '9763'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '9443'
ToPort: '9443'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '8243'
ToPort: '8243'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '8280'
ToPort: '8280'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '4000'
ToPort: '4000'
CidrIp: 0.0.0.0/0
WSO2APIMLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: APIM
Scheme: internet-facing
Subnets:
- !Ref WSO2APIMPublicSubnet1
- !Ref WSO2APIMPublicSubnet2
SecurityGroups:
- !Ref WSO2APIMLoadBalancerSecurityGroup
WSO2APIMALBTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 10
HealthCheckProtocol: HTTPS
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 4
HealthCheckPath: /carbon/admin/login.jsp
HealthCheckPort: 9443
Matcher:
HttpCode: 200
Name: apim-carbon-9443
Port: 9443
Protocol: HTTPS
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: '20'
- Key: stickiness.enabled
Value: 'true'
UnhealthyThresholdCount: 3
VpcId:
Ref: WSO2APIMVPC
Tags:
- Key: Name
Value: apim
WSO2APIMALB8243TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 10
HealthCheckProtocol: HTTPS
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 4
HealthCheckPath: /services/Version
HealthCheckPort: 8243
Matcher:
HttpCode: 200
Name: apim-carbon-8243
Port: 8243
Protocol: HTTPS
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: '20'
- Key: stickiness.enabled
Value: 'true'
UnhealthyThresholdCount: 3
VpcId:
Ref: WSO2APIMVPC
Tags:
- Key: Name
Value: apim
WSO2APIMALB443Listener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WSO2APIMALBTargetGroup
Certificates:
- CertificateArn: !Join
- ''
- - 'arn:aws:iam::'
- !Ref 'AWS::AccountId'
- ':server-certificate'
- /
- !Ref CertificateName
LoadBalancerArn: !Ref WSO2APIMLoadBalancer
Port: 443
Protocol: HTTPS
SslPolicy: ELBSecurityPolicy-TLS-1-1-2017-01
DependsOn:
- WSO2APIMLoadBalancerSecurityGroup
WSO2APIMALB8243Listener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WSO2APIMALB8243TargetGroup
Certificates:
- CertificateArn: !Join
- ''
- - 'arn:aws:iam::'
- !Ref 'AWS::AccountId'
- ':server-certificate'
- /
- !Ref CertificateName
LoadBalancerArn: !Ref WSO2APIMLoadBalancer
Port: 8243
Protocol: HTTPS
SslPolicy: ELBSecurityPolicy-TLS-1-1-2017-01
DependsOn:
- WSO2APIMLoadBalancerSecurityGroup
WSO2APIMALB9443Listener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WSO2APIMALBTargetGroup
Certificates:
- CertificateArn: !Join
- ''
- - 'arn:aws:iam::'
- !Ref 'AWS::AccountId'
- ':server-certificate'
- /
- !Ref CertificateName
LoadBalancerArn: !Ref WSO2APIMLoadBalancer
Port: 9443
Protocol: HTTPS
SslPolicy: ELBSecurityPolicy-TLS-1-1-2017-01
DependsOn:
- WSO2APIMLoadBalancerSecurityGroup
Outputs:
CarbonServerUrl:
Value: !Join
- ''
- - 'https://'
- !GetAtt
- WSO2APIMLoadBalancer
- DNSName
- '/services/'
Description: APIM service carbon URL
MgtConsoleUrl:
Value: !Join
- ''
- - 'https://'
- !GetAtt
- WSO2APIMLoadBalancer
- DNSName
- '/carbon'
Description: APIM service carbon URL
PublisherUrl:
Value: !Join
- ''
- - 'https://'
- !GetAtt
- WSO2APIMLoadBalancer
- DNSName
- '/publisher'
Description: APIM service publisher URL
StoreUrl: