This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.yaml
1743 lines (1698 loc) · 56.1 KB
/
app.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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label: Build Info
Parameters:
- CodePipeline
- BuildRegion
- SourceVersion
- Build
- Label: Code Location
Parameters:
- CodeBucket
- CodePrefix
- Label: EC2
Parameters:
- KeyPair
- Label: Deployment Configuration
Parameters:
- Stage
- DeploymentPreference
- Label: DNS
Parameters:
- DNSDomainName
- BaseDNSName
- HostedZoneID
- Label: VPC
Parameters:
- EnableVPC
- Label: Task Runner
Parameters:
- AccessKeyID
- SecretAccessKey
- Label: EC2 Instance
Parameters:
- EnableEC2Instance
- EC2InstanceSize
- Label: EMR Cluster
Parameters:
- EnableEMRCluster
- EMRRelease
- EMRMasterInstanceType
- EMRMasterInstanceCount
- EMRCoreInstanceType
- EMRCoreInstanceCount
- Label: Redshift
Parameters:
- EnableRedshift
- RedshiftNodeType
- RedshiftNumberOfNodes
- RedshiftDatabase
- RedshiftUsername
- RedshiftPassword
- Label: Data Pipeline
Parameters:
- EnablePipeline
ParameterLabels:
CodePipeline:
default: The CodePipeline pipeline that build this app
BuildRegion:
default: The region the app was built in
SourceVersion:
default: The source version built
Build:
default: The unique build ID
CodeBucket:
default: Bucket containing scripts
CodePrefix:
default: Prefix for scripts
KeyPair:
default: EC2 KeyPair
Stage:
default: Stage to deploy
DeploymentPreference:
default: CodeDeploy deployment preference
DNSDomainName:
default: Domain name in Route53
BaseDNSName:
default: Base DNS name for APIs
EnableVPC:
default: Creates a VPC
AccessKeyID:
default: AWS Access Key ID
SecretAccessKey:
default: AWS Secret Access Key
EnableEC2Instance:
default: Creates an EC2 instance for Data Pipeline
EC2InstanceSize:
default: Type of EC2 instance
EnableEMRCluster:
default: Create an EMR cluster for Data Pipeline
EMRVersion:
default: EMR release version
EMRMasterInstanceType:
default: Type of EMR master instances
EMRMasterInstanceCount:
default: Number of EMR master instances
EMRCoreInstanceType:
default: Type of EMR core instances
EMRCoreInstanceCount:
default: Number of EMR core instances
EnableRedshift:
default: Create a Redshift instance
RedshiftNodeType:
default: Type of Redshift instance nodes
RedshiftNumberOfNodes:
default: Number of Redshift nodes
RedshiftDatabase:
default: The default Redshift database
RedshiftUsername:
default: The Redshift username
RedshiftPassword:
default: The Redshift password
EnablePipeline:
default: The daily pipeline is enabled when non-nil
Parameters:
CodePipeline:
Type: String
Description: The CodePipeline pipeline that build this app
BuildRegion:
Type: String
Description: The region the app was built in
SourceVersion:
Type: String
Description: The source version built
Build:
Type: String
Description: The unique build ID
CodeBucket:
Type: String
Description: The S3 bucket user code is stored in.
CodePrefix:
Type: String
Description: The prefix into the S3 bucket code is stored in.
KeyPair:
Type: String
Description: The EC2 KeyPair to use
Default: ''
Stage:
Type: String
Description: The name for a project pipeline stage, such as Staging or Prod, for which resources are provisioned and deployed.
Default: Prod
DeploymentPreference:
Type: String
Description: The CodeDeploy deployment preference for safe Lambda deploys.
Default: Canary10Percent5Minutes
AllowedValues:
- Canary10Percent5Minutes
- Canary10Percent10Minutes
- Canary10Percent15Minutes
- Canary10Percent30Minutes
- Linear10PercentEvery1Minutes
- Linear10PercentEvery2Minutes
- Linear10PercentEvery3Minutes
- Linear10PercentEvery10Minutes
- AllAtOnce
DNSDomainName:
Type: String
Description: The domain name in Route53, such as example.com, this warehouse is served from.
Default: ''
BaseDNSName:
Type: String
Description: The base DNS name, such as warehouse.example.com, this warehouse is served from. Must be a the DNSDomainName or a subdomain of it.
Default: ''
HostedZoneID:
Type: String
Description: The existing Hosted Zone to use. Creates a Hosted Zone if not provided.
Default: ''
EnableVPC:
Type: String
Description: If non-empty, create a VPC. EnableEC2Instance, EnableEMRCluster, and EnableRedshift imply this option.
Default: ''
AccessKeyID:
Type: String
Description: The AWS Access Key ID to use for the Data Pipeline Task Runner
Default: ''
SecretAccessKey:
Type: String
Description: The AWS Secret Access Key to use for the Data Pipeline Task Runner
Default: ''
NoEcho: true
EnableEC2Instance:
Type: String
Description: If non-empty, create an EC2 instance for use by Data Pipeline.
Default: ''
EC2InstanceSize:
Type: String
Description: The instance size of the EC2 instance for use by Data Pipeline
Default: t2.nano
EnableEMRCluster:
Type: String
Description: If non-empty, create an EMR cluster.
Default: ''
EMRRelease:
Type: String
Description: The EMR release version to use.
Default: emr-5.23.0
EMRMasterInstanceType:
Type: String
Description: The instance type of the master instances in the EMR cluster.
AllowedPattern: "[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*"
Default: m3.xlarge
EMRMasterInstanceCount:
Type: Number
Description: The number of master instances in the EMR cluster.
MinValue: 1
MaxValue: 256
Default: 1
EMRCoreInstanceType:
Type: String
Description: The instance type of the core instances in the EMR cluster.
AllowedPattern: "[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*"
Default: m3.xlarge
EMRCoreInstanceCount:
Type: Number
Description: The number of core instances in the EMR cluster.
MinValue: 1
MaxValue: 256
Default: 1
EnableRedshift:
Type: String
Description: If non-empty, create a Redshift cluster.
Default: ''
RedshiftNodeType:
Type: String
Description: The type of instances in the Redshift cluster.
AllowedValues:
- dc2.large
- dc2.8xlarge
- ds2.xlarge
- ds2.8xlarge
Default: dc2.large
RedshiftNumberOfNodes:
Type: Number
Description: The number of nodes in the Redshift cluster.
MinValue: 1
MaxValue: 100
Default: 1
RedshiftDatabase:
Type: String
Description: The name of the default Redshift database
Default: dataless
RedshiftUsername:
Type: String
Description: The username of the default Redshift user
Default: dataless
RedshiftPassword:
Type: String
Description: The password of the default Redshift user
Default: D4ta!3s5
NoEcho: true
EnablePipeline:
Type: String
Description: |
If non-empty, the daily pipeline is enabled. Useful for deleting and
re-creating the pipeline on backwards-incompatible changes. Defaults to
enabled.
Default: yes
Conditions:
DNSEnabled: !And
- !Not [!Equals [!Ref DNSDomainName, ""]]
- !Not [!Equals [!Ref BaseDNSName, ""]]
InternalHostedZone: !And
- !Not [!Equals [!Ref DNSDomainName, ""]]
- !Not [!Equals [!Ref BaseDNSName, ""]]
- !Equals [!Ref HostedZoneID, ""]
EC2InstanceEnabled: !And
- !Not [!Equals [!Ref EnableEC2Instance, ""]]
- !Not [!Equals [!Ref AccessKeyID, ""]]
- !Not [!Equals [!Ref SecretAccessKey, ""]]
EMREnabled: !And
- !Not [!Equals [!Ref EnableEMRCluster, ""]]
- !Not [!Equals [!Ref AccessKeyID, ""]]
- !Not [!Equals [!Ref SecretAccessKey, ""]]
RedshiftEnabled: !And
- !Not [!Equals [!Ref EnableRedshift, ""]]
- !Not [!Equals [!Ref RedshiftDatabase, ""]]
- !Not [!Equals [!Ref RedshiftUsername, ""]]
- !Not [!Equals [!Ref RedshiftPassword, ""]]
RedshiftSingleNode: !Equals [!Ref RedshiftNumberOfNodes, 1]
VPCEnabled: !Or
- !Not [!Equals [!Ref EnableVPC, ""]]
- !Not [!Equals [!Ref EnableEC2Instance, ""]]
- !Not [!Equals [!Ref EnableEMRCluster, ""]]
- !Not [!Equals [!Ref EnableRedshift, ""]]
KeyPairGiven: !Not [!Equals [!Ref KeyPair, ""]]
Outputs:
BaseURL:
Value: !If
- DNSEnabled
- !Ref BaseDNSName
- !GetAtt AdvertisingService.Outputs.BaseURL
Mappings:
AMIs:
us-east-1:
PV64Instance: ami-0023040df18933030
us-west-2:
PV64Instance: ami-afe1c0d7
eu-west-1:
PV64Instance: ami-0c651f40f9861388f
ap-southeast-2:
PV64Instance: ami-0d783a243942fbe54
ap-northeast-1:
PV64Instance: ami-0f16a2ca7efacfa65
Resources:
##########
# Bucket #
##########
Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
VersioningConfiguration:
Status: Enabled
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: aws:kms
MetricsConfigurations:
- Id: raw
Prefix: data/raw/
- Id: lake
Prefix: data/lake/
- Id: temp
Prefix: data/temp/
#################
# Data Pipeline #
#################
PipelineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- !Sub "logs.${AWS::Region}.${AWS::URLSuffix}"
- !Sub "datapipeline.${AWS::URLSuffix}"
- !Sub "dynamodb.${AWS::URLSuffix}"
- !Sub "ec2.${AWS::URLSuffix}"
- !Sub "elasticmapreduce.${AWS::URLSuffix}"
- !Sub "iam.${AWS::URLSuffix}"
- !Sub "rds.${AWS::URLSuffix}"
- !Sub "redshift.${AWS::URLSuffix}"
- !Sub "s3.${AWS::URLSuffix}"
- !Sub "sns.${AWS::URLSuffix}"
- !Sub "sqs.${AWS::URLSuffix}"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSDataPipelineRole
Policies:
- PolicyName: SpectrumAccess
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- glue:*
- athena:*
Effect: Allow
Resource: "*"
- Action:
- s3:Get*
- s3:List*
Effect: Allow
Resource:
- !Sub "${Bucket.Arn}/data/raw/*"
- !Sub "${Bucket.Arn}/data/lake/*"
- !Sub "${Bucket.Arn}/data/temp/*"
PipelineResourceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- !Sub "logs.${AWS::Region}.${AWS::URLSuffix}"
- !Sub "datapipeline.${AWS::URLSuffix}"
- !Sub "dynamodb.${AWS::URLSuffix}"
- !Sub "ec2.${AWS::URLSuffix}"
- !Sub "elasticmapreduce.${AWS::URLSuffix}"
- !Sub "iam.${AWS::URLSuffix}"
- !Sub "rds.${AWS::URLSuffix}"
- !Sub "redshift.${AWS::URLSuffix}"
- !Sub "s3.${AWS::URLSuffix}"
- !Sub "sns.${AWS::URLSuffix}"
- !Sub "sqs.${AWS::URLSuffix}"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforDataPipelineRole
Policies:
- PolicyName: SpectrumAccess
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- glue:*
- athena:*
Effect: Allow
Resource: "*"
- Action:
- s3:Get*
- s3:List*
Effect: Allow
Resource:
- !Sub "${Bucket.Arn}/data/raw/*"
- !Sub "${Bucket.Arn}/data/lake/*"
- !Sub "${Bucket.Arn}/data/temp/*"
#######
# VPC #
#######
VPC:
Type: AWS::EC2::VPC
Condition: VPCEnabled
Properties:
CidrBlock: 172.31.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
InternetGateway:
Type: AWS::EC2::InternetGateway
Condition: VPCEnabled
DependsOn:
- VPC
GatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Condition: VPCEnabled
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
Subnet:
Type: AWS::EC2::Subnet
Condition: VPCEnabled
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select
- 0
- Fn::GetAZs: !Ref AWS::Region
CidrBlock: 172.31.0.0/16
MapPublicIpOnLaunch: true
RouteTable:
Type: AWS::EC2::RouteTable
Condition: VPCEnabled
Properties:
VpcId: !Ref VPC
Route:
Type: AWS::EC2::Route
Condition: VPCEnabled
DependsOn:
- GatewayAttachment
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
RouteTableId: !Ref RouteTable
Association:
Type: AWS::EC2::SubnetRouteTableAssociation
Condition: VPCEnabled
Properties:
RouteTableId: !Ref RouteTable
SubnetId: !Ref Subnet
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Condition: VPCEnabled
Properties:
GroupName: SecurityGroup
GroupDescription: Default Security Group
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 0
ToPort: 65535
CidrIp: 0.0.0.0/0
- IpProtocol: udp
FromPort: 0
ToPort: 65535
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 8443
ToPort: 8443
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
############
# Redshift #
############
RedshiftClusterSecurityGroup:
Type: AWS::Redshift::ClusterSecurityGroup
Condition: RedshiftEnabled
Properties:
Description: Redshift Cluster Security Group
RedshiftClusterSecurityGroupIngress:
Type: AWS::Redshift::ClusterSecurityGroupIngress
Condition: RedshiftEnabled
Properties:
ClusterSecurityGroupName: !Ref RedshiftClusterSecurityGroup
CIDRIP: 0.0.0.0/0
RedshiftClusterSubnetGroup:
Type: AWS::Redshift::ClusterSubnetGroup
Condition: RedshiftEnabled
Properties:
Description: Redshift Cluster Subnet Group
SubnetIds:
- !Ref Subnet
Redshift:
Type: AWS::Redshift::Cluster
Condition: RedshiftEnabled
Properties:
ClusterType: !If [RedshiftSingleNode, "single-node", "multi-node"]
ClusterIdentifier: !Sub "${AWS::StackName}-${AWS::Region}-redshift-cluster"
DBName: !Ref RedshiftDatabase
Encrypted: true
MasterUsername: !Ref RedshiftUsername
MasterUserPassword: !Ref RedshiftPassword
NodeType: !Ref RedshiftNodeType
NumberOfNodes: !If [RedshiftSingleNode, !Ref 'AWS::NoValue', !Ref RedshiftNumberOfNodes]
ClusterSubnetGroupName: !Ref RedshiftClusterSubnetGroup
VpcSecurityGroupIds:
- !Ref SecurityGroup
- !GetAtt VPC.DefaultSecurityGroup
IamRoles:
- !GetAtt PipelineRole.Arn
- !GetAtt PipelineResourceRole.Arn
PubliclyAccessible: true
AvailabilityZone: !GetAtt Subnet.AvailabilityZone
############
# Instance #
############
InstanceRole:
Type: AWS::IAM::Role
Condition: EC2InstanceEnabled
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- !Sub "ec2.${AWS::URLSuffix}"
- !Sub "elasticmapreduce.${AWS::URLSuffix}"
- !Sub "iam.${AWS::URLSuffix}"
- !Sub "s3.${AWS::URLSuffix}"
- !Sub "sqs.${AWS::URLSuffix}"
- !Sub "logs.${AWS::Region}.${AWS::URLSuffix}"
- !Sub "autoscaling.${AWS::URLSuffix}"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforDataPipelineRole
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Condition: EC2InstanceEnabled
Properties:
Roles:
- !Ref InstanceRole
Instance:
Type: AWS::EC2::Instance
Condition: EC2InstanceEnabled
Properties:
IamInstanceProfile: !Ref InstanceProfile
ImageId: !FindInMap
- AMIs
- !Ref AWS::Region
- PV64Instance
SecurityGroupIds:
- !Ref SecurityGroup
- !GetAtt VPC.DefaultSecurityGroup
SubnetId: !Ref Subnet
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
set -x -e
# Install task runner
aws s3 cp "s3://datapipeline-us-east-1/us-east-1/software/latest/TaskRunner/TaskRunner-1.0.jar" "${!HOME}/TaskRunner-1.0.jar"
echo '{"access-id": "${AccessKeyID}", "private-key": "${SecretAccessKey}"}' | jq -cr '.' > "${!HOME}/credentials.json"
nohup java -jar "${!HOME}/TaskRunner-1.0.jar" --workerGroup="${AWS::StackName}-${AWS::Region}-instance-worker-group" --region="${AWS::Region}" --logUri="s3://${Bucket}/logs/task-runner/instance/" &
#######
# EMR #
#######
EMRJobFlowRole:
Type: AWS::IAM::Role
Condition: EMREnabled
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- !Sub "ec2.${AWS::URLSuffix}"
- !Sub "elasticmapreduce.${AWS::URLSuffix}"
- !Sub "iam.${AWS::URLSuffix}"
- !Sub "s3.${AWS::URLSuffix}"
- !Sub "sqs.${AWS::URLSuffix}"
- !Sub "logs.${AWS::Region}.${AWS::URLSuffix}"
- !Sub "autoscaling.${AWS::URLSuffix}"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforEC2Role
- arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforDataPipelineRole
Policies:
- PolicyName: JobFlow
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- cloudwatch:*
- dynamodb:*
- ec2:Describe*
- elasticmapreduce:Describe*
- elasticmapreduce:ListBootstrapActions
- elasticmapreduce:ListClusters
- elasticmapreduce:ListInstanceGroups
- elasticmapreduce:ListInstances
- elasticmapreduce:ListSteps
- kinesis:CreateStream
- kinesis:DeleteStream
- kinesis:DescribeStream
- kinesis:GetRecords
- kinesis:GetShardIterator
- kinesis:MergeShards
- kinesis:PutRecord
- kinesis:SplitShard
- rds:Describe*
- s3:*
- sdb:*
- sns:*
- sqs:*
- glue:CreateDatabase
- glue:UpdateDatabase
- glue:DeleteDatabase
- glue:GetDatabase
- glue:GetDatabases
- glue:CreateTable
- glue:UpdateTable
- glue:DeleteTable
- glue:GetTable
- glue:GetTables
- glue:GetTableVersions
- glue:CreatePartition
- glue:BatchCreatePartition
- glue:UpdatePartition
- glue:DeletePartition
- glue:BatchDeletePartition
- glue:GetPartition
- glue:GetPartitions
- glue:BatchGetPartition
- glue:CreateUserDefinedFunction
- glue:UpdateUserDefinedFunction
- glue:DeleteUserDefinedFunction
- glue:GetUserDefinedFunction
- glue:GetUserDefinedFunctions
Effect: Allow
Resource: "*"
- Action:
- cloudwatch:*
- datapipeline:*
- dynamodb:*
- ec2:Describe*
- elasticmapreduce:AddJobFlowSteps
- elasticmapreduce:Describe*
- elasticmapreduce:ListInstance*
- rds:Describe*
- redshift:DescribeClusters
- redshift:DescribeClusterSecurityGroups
- s3:*
- sdb:*
- sns:*
- sqs:*
Effect: Allow
Resource: "*"
EMRProfile:
Type: AWS::IAM::InstanceProfile
Condition: EMREnabled
Properties:
Roles:
- !Ref EMRJobFlowRole
EMRServiceRole:
Type: AWS::IAM::Role
Condition: EMREnabled
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- !Sub "ec2.${AWS::URLSuffix}"
- !Sub "elasticmapreduce.${AWS::URLSuffix}"
- !Sub "iam.${AWS::URLSuffix}"
- !Sub "s3.${AWS::URLSuffix}"
- !Sub "sqs.${AWS::URLSuffix}"
- !Sub "logs.${AWS::Region}.${AWS::URLSuffix}"
- !Sub "autoscaling.${AWS::URLSuffix}"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole
Policies:
- PolicyName: Service
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- ec2:AuthorizeSecurityGroupEgress
- ec2:AuthorizeSecurityGroupIngress
- ec2:CancelSpotInstanceRequests
- ec2:CreateNetworkInterface
- ec2:CreateSecurityGroup
- ec2:CreateTags
- ec2:DeleteNetworkInterface
- ec2:DeleteSecurityGroup
- ec2:DeleteTags
- ec2:DescribeAvailabilityZones
- ec2:DescribeAccountAttributes
- ec2:DescribeDhcpOptions
- ec2:DescribeImages
- ec2:DescribeInstanceStatus
- ec2:DescribeInstances
- ec2:DescribeKeyPairs
- ec2:DescribeNetworkAcls
- ec2:DescribeNetworkInterfaces
- ec2:DescribePrefixLists
- ec2:DescribeRouteTables
- ec2:DescribeSecurityGroups
- ec2:DescribeSpotInstanceRequests
- ec2:DescribeSpotPriceHistory
- ec2:DescribeSubnets
- ec2:DescribeTags
- ec2:DescribeVpcAttribute
- ec2:DescribeVpcEndpoints
- ec2:DescribeVpcEndpointServices
- ec2:DescribeVpcs
- ec2:DetachNetworkInterface
- ec2:ModifyImageAttribute
- ec2:ModifyInstanceAttribute
- ec2:RequestSpotInstances
- ec2:RevokeSecurityGroupEgress
- ec2:RunInstances
- ec2:TerminateInstances
- ec2:DeleteVolume
- ec2:DescribeVolumeStatus
- ec2:DescribeVolumes
- ec2:DetachVolume
- iam:GetRole
- iam:GetRolePolicy
- iam:ListInstanceProfiles
- iam:ListRolePolicies
- iam:PassRole
- s3:CreateBucket
- s3:Get*
- s3:List*
- sdb:BatchPutAttributes
- sdb:Select
- sqs:CreateQueue
- sqs:Delete*
- sqs:GetQueue*
- sqs:PurgeQueue
- sqs:ReceiveMessage
- cloudwatch:PutMetricAlarm
- cloudwatch:DescribeAlarms
- cloudwatch:DeleteAlarms
- application-autoscaling:RegisterScalableTarget
- application-autoscaling:DeregisterScalableTarget
- application-autoscaling:PutScalingPolicy
- application-autoscaling:DeleteScalingPolicy
- application-autoscaling:Describe*
Effect: Allow
Resource: "*"
EMR:
Type: AWS::EMR::Cluster
Condition: EMREnabled
Properties:
Applications:
- Name: hive
- Name: pig
- Name: spark
# BootstrapActions:
# TODO: Broken :(
# - Name: Install Task Runner
# ScriptBootstrapAction:
# Path: s3://elasticmapreduce/bootstrap-actions/run-if
# Args:
# - instance.isMaster=true
# - !Sub "s3://${CodeBucket}/${CodePrefix}/scripts/emr/install_task_runner.sh"
# - !Ref AccessKeyID
# - !Ref SecretAccessKey
# - !Sub "${AWS::StackName}-${AWS::Region}-emr-worker-group"
# - !Ref AWS::Region
# - !Sub "s3://${Bucket}/logs/task-runner/emr/"
Configurations:
- Classification: hive-site
ConfigurationProperties:
hive.metastore.client.factory.class: com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory
hive.metastore.glue.catalogid: !Ref AWS::AccountId
- Classification: spark-hive-site
ConfigurationProperties:
hive.metastore.client.factory.class: com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory
hive.metastore.glue.catalogid: !Ref AWS::AccountId
Instances:
AdditionalMasterSecurityGroups:
- !Ref SecurityGroup
- !GetAtt VPC.DefaultSecurityGroup
AdditionalSlaveSecurityGroups:
- !Ref SecurityGroup
- !GetAtt VPC.DefaultSecurityGroup
Ec2KeyName: !If
- KeyPairGiven
- !Ref KeyPair
- !Ref AWS::NoValue
Ec2SubnetId: !Ref Subnet
MasterInstanceGroup:
InstanceCount: !Ref EMRMasterInstanceCount
InstanceType: !Ref EMRMasterInstanceType
CoreInstanceGroup:
InstanceCount: !Ref EMRCoreInstanceCount
InstanceType: !Ref EMRCoreInstanceType
TerminationProtected: false
JobFlowRole: !Ref EMRProfile
Name: !Sub "${AWS::StackName}-${AWS::Region}-warehouse-emr-cluster"
ReleaseLabel: !Ref EMRRelease
ServiceRole: !Ref EMRServiceRole
LogUri: !Sub "s3://${Bucket}/logs/emr"
##################
# Events Service #
##################
AdvertisingService:
Type: AWS::Serverless::Application
Properties:
Location: svc/advertising/service.yaml
Parameters:
CodePipeline: !Ref CodePipeline
BuildRegion: !Ref BuildRegion
SourceVersion: !Ref SourceVersion
Build: !Ref Build
CodeBucket: !Ref CodeBucket
CodePrefix: !Sub "${CodePrefix}/svc/advertising"
KeyPair: !Ref KeyPair
Stage: !Ref Stage
DeploymentPreference: !Ref DeploymentPreference
BucketName: !Ref Bucket
BucketARN: !GetAtt Bucket.Arn
Subnet: !If
- VPCEnabled
- !Ref Subnet
- !Ref AWS::NoValue
SecurityGroup: !If
- VPCEnabled
- !Ref SecurityGroup
- !Ref AWS::NoValue
AccessKeyID: !Ref AccessKeyID
SecretAccessKey: !Ref SecretAccessKey
EnableEC2Instance: !Ref EnableEC2Instance
EnableEMRCluster: !Ref EnableEMRCluster
RedshiftClusterId: !If
- RedshiftEnabled
- !Ref Redshift
- !Ref AWS::NoValue
RedshiftDatabase: !Ref RedshiftDatabase
RedshiftUsername: !Ref RedshiftUsername
RedshiftPassword: !Ref RedshiftPassword
EnablePipeline: !Ref EnablePipeline
PipelineRole: !Ref PipelineRole
PipelineRoleARN: !GetAtt PipelineRole.Arn
PipelineResourceRole: !Ref PipelineResourceRole
PipelineResourceRoleARN: !GetAtt PipelineResourceRole.Arn
##########
# Router #
##########
Certificate:
Type: AWS::CertificateManager::Certificate
Condition: DNSEnabled
Properties:
DomainName: !Ref BaseDNSName
DomainValidationOptions:
- DomainName: !Ref BaseDNSName
ValidationDomain: !Ref DNSDomainName
DomainName:
Type: AWS::ApiGateway::DomainName
Condition: DNSEnabled
Properties:
CertificateArn: !Ref Certificate
DomainName: !Ref BaseDNSName
BasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
Condition: DNSEnabled
Properties:
BasePath: advertising
DomainName: !Ref DomainName
RestApiId: !GetAtt AdvertisingService.Outputs.API
Stage: !GetAtt AdvertisingService.Outputs.Stage
#######
# DNS #
#######
HostedZone:
Type: AWS::Route53::HostedZone
Condition: InternalHostedZone
Properties:
Name: !Ref DNSDomainName
RecordSetGroup:
Type: AWS::Route53::RecordSetGroup
Condition: DNSEnabled
Properties:
HostedZoneId: !If [InternalHostedZone, !Ref HostedZone, !Ref HostedZoneID]
RecordSets:
- Type: A
Name: !Ref BaseDNSName
AliasTarget:
DNSName: !GetAtt DomainName.DistributionDomainName
HostedZoneId: Z2FDTNDATAQYW2
#################
# Ops Dashboard #
#################
OpsDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardBody: !Sub |
{
"start": "-PT1H",
"periodOverride": "inherit",
"widgets": [
{
"type": "text",
"width": 24,
"height": 1,
"properties": { "markdown": "# Beacon Endpoints" }
},
{
"type": "metric",
"width": 6,
"height": 4,
"properties": {
"metrics": [
[ { "expression": "SEARCH('{AWS/ApiGateway,ApiName,Resource,Method,Stage} MetricName=\"Count\" Stage=\"${Stage}\"', 'Sum', 60)" } ]
],
"region": "${AWS::Region}",
"title": "Request Rate",
"liveData": false,
"view": "timeSeries",
"stacked": false,
"legend": {
"position": "hidden"
}
}