-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
845 lines (773 loc) · 27 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
AWS SAM Template for common resources between NVA stacks
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Backup configuration
Parameters:
- DaysToRetainHourlyBackup
- DaysToRetainDailyBackup
- DaysToRetainWeeklyBackup
- DaysToRetainQuarterlyBackup
- SharedBackupVaultArn
- SharedBackupAccountId
- UseBackup
Parameters:
BackendDomainCertificateArn:
Type: String
Description: ARN for the certificate covering the API host/domain/API Gateway Custom Domain. The value is stored in Region us-east-1.
FrontendDomainCertificateArn:
Type: String
Description: ARN for the certificate covering the API host/domain/API Gateway Custom Domain. The value is stored in Region us-east-1.
CustomDomain:
Type: String
Description: The domain of the NVA related services. This part of the domain is common to both backend and frontend services. Eg. dev.nva.aws.unit.no or nva.unit.no.
AlmaApiUri:
Type: String
Description: URI to Alma API.
Default: 'https://bibsys.alma.exlibrisgroup.com/view/sru/47BIBSYS_NETWORK'
DataCiteMdsEndpoint:
Type: String
Description: URI to Datacite MDS endpoint.
DataCiteRestEndpoint:
Type: String
Description: URI to Datacite Rest endpoint.
OrcidBaseUrl:
Type: String
Description: URL for communicating with ORCID
ApiGatewayEndpointType:
Type: String
Default: EDGE
Description: The ApiGateway Endpoint Type
SlackChannelId:
Type: String
Description: ID of slack channel. Used for monitoring/alerts. Example CXXXXXXXXXX
SlackWorkspaceId:
Type: String
Description: ID of slack workspace. Used for monitoring/alerts. Example TXXXXXXXX
Suffix:
Type: String
Default: ''
Description: Suffix used for naming resources for feature branches to avoid conflicts.
EnvironmentName:
Type: String
Description: Environment name. Must be unique accross all NVA environments as it will be part of the cognito uri and potentially other resources like S3.
VpcCIDR:
Description: IP range (CIDR notation) for this VPC
Type: String
Default: 10.192.0.0/16
PublicSubnetCIDR:
Description: IP range (CIDR notation) for the public subnet
Type: String
Default: 10.192.10.0/24
PrivateSubnetCIDR:
Description: IP range (CIDR notation) for the private subnet
Type: String
Default: 10.192.20.0/24
AppConfigName:
Type: String
Description: Name of the AppConfig application
Default: ApplicationConfig
ApplicationConfigurationProfileName:
Type: String
Description: Name of the AppConfig application configuration profile
Default: ApplicationConfigurationProfile
ApplicationEnvironmentName:
Type: String
Description: Name of the AppConfig application environment
Default: Live
# Backup configuration
DaysToRetainHourlyBackup:
Type: Number
Default: 2
Description: Number of days to retain hourly backups
DaysToRetainDailyBackup:
Type: Number
Default: 7
Description: Number of days to retain daily backups
DaysToRetainWeeklyBackup:
Type: Number
Default: 28
Description: Number of days to retain weekly backups
DaysToRetainQuarterlyBackup:
Type: Number
Default: 365
Description: Number of days to retain quarterly backups
SharedBackupVaultArn:
Type: String
Description: ARN of the shared backup vault for this environment. Backups are copied to this vault.
SharedBackupAccountId:
Type: String
Description: Account ID of the shared backup account
UseBackup:
Type: String
Default: 'false'
AllowedValues:
- 'true'
- 'false'
Description: Enable or disable backups for this environment
Conditions:
WithSuffix: !Not [ !Equals [ !Ref Suffix, '' ] ]
CreateBackups:
Fn::Equals:
- !Ref UseBackup
- 'true'
Resources:
NvaEventsBus:
Type: AWS::Events::EventBus
Properties:
Name: !If
- WithSuffix
- !Sub 'nva-events-default-bus-${AWS::AccountId}-${Suffix}'
- !Sub 'nva-events-default-bus-${AWS::AccountId}'
EventBusArn:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the default EventBridge bus used in NVA so that other services can be aware of the name of the bus.
Name: /NVA/Events/EventsBusArn
Type: String
Value: !GetAtt NvaEventsBus.Arn
EventBusName:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the default EventBridge bus used in NVA so that other services can be aware of the name of the bus.
Name: /NVA/Events/EventsBusName
Type: String
Value: !GetAtt NvaEventsBus.Name
EventsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !If
- WithSuffix
- !Sub 'eventbridge-event-bodies-${AWS::AccountId}-${Suffix}'
- !Sub 'eventbridge-event-bodies-${AWS::AccountId}'
AccessControl: Private
LifecycleConfiguration:
Rules:
- Id: "ExpiryPolicy"
ExpirationInDays: 14
Status: Enabled
VersioningConfiguration:
Status: Suspended
ChatbotRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "chatbot.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonSNSReadOnlyAccess
- arn:aws:iam::aws:policy/AWSSupportAccess
- arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess
SlackSNSTopic:
Type: AWS::SNS::Topic
NvaSlackChannel:
Type: AWS::Chatbot::SlackChannelConfiguration
Properties:
ConfigurationName: nva-monitoring
IamRoleArn: !GetAtt ChatbotRole.Arn
LoggingLevel: INFO
SlackChannelId: !Ref SlackChannelId
SlackWorkspaceId: !Ref SlackWorkspaceId
SnsTopicArns:
- !Ref SlackSNSTopic
# This bucket could belong to the NVA Resources service but being there would
# prevent us from being able to create and destroy the stack. Also, this bucket is read
# by the search service, so it is a common resource by definition. The deletion of
# the NVA Resources service stack should not necessarily break the NVA search service
ExpandedResourcesBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !If
- WithSuffix
- !Sub 'persisted-resources-${AWS::AccountId}-${Suffix}'
- !Sub 'persisted-resources-${AWS::AccountId}'
"NotificationConfiguration": {
"EventBridgeConfiguration": {
"EventBridgeEnabled": true
}
}
AccessControl: Private
VersioningConfiguration:
Status: Suspended
# Bucket for storing API responses that are too large to pass through Lambda
LargeApiResponsesBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !If
- WithSuffix
- !Sub 'large-api-responses-${AWS::AccountId}-${Suffix}'
- !Sub 'large-api-responses-${AWS::AccountId}'
AccessControl: Private
LifecycleConfiguration:
Rules:
- Status: Enabled
ExpirationInDays: 1
DeletionPolicy: Retain
ResourceStorageBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
BucketName: !If
- WithSuffix
- !Sub 'nva-resource-storage-${AWS::AccountId}-${Suffix}'
- !Sub 'nva-resource-storage-${AWS::AccountId}'
CorsConfiguration:
CorsRules:
- AllowedHeaders: [ '*' ]
AllowedMethods: [ GET, PUT, POST, HEAD ]
AllowedOrigins: [ '*' ]
ExposedHeaders: [ ETag ]
LifecycleConfiguration:
Rules:
- Id: RemoveFailedUploads
Status: Enabled
AbortIncompleteMultipartUpload:
DaysAfterInitiation: 7
VersioningConfiguration:
Status: Enabled
NVAStorageBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref ResourceStorageBucket
PolicyDocument:
Statement:
- Action:
- "s3:GetObject"
- "s3:PutObject"
- "s3:AbortMultipartUpload"
- "s3:ListMultipartUploadParts"
- "s3:ListBucketMultipartUploads"
Effect: "Allow"
Resource:
- !Sub 'arn:aws:s3:::${ResourceStorageBucket}'
- !Sub 'arn:aws:s3:::${ResourceStorageBucket}/*'
Principal:
Service:
- lambda.amazonaws.com
NvaAthenaQueriesBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
BucketName: !Sub 'nva-athena-queries-${AWS::AccountId}'
AccessControl: Private
VersioningConfiguration:
Status: Suspended
BackendDomainName:
Type: AWS::ApiGateway::DomainName
Properties:
CertificateArn: !Ref BackendDomainCertificateArn
DomainName: !Sub 'api.${CustomDomain}'
EndpointConfiguration:
Types:
- !Ref ApiGatewayEndpointType
CristinImportNviQueue:
Type: AWS::SQS::Queue
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCIDR
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Sub nva-${EnvironmentName}-static-ip-vpc
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Sub nva-${EnvironmentName}-static-ip-igw
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref PublicSubnetCIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub nva-${EnvironmentName}-static-ip-public-subnet
PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !Ref PrivateSubnetCIDR
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub nva-${EnvironmentName}-static-ip-private-subnet
NatGatewayEIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
NatGateway:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatGatewayEIP.AllocationId
SubnetId: !Ref PublicSubnet
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub nva-${EnvironmentName}-static-ip-public-routes
DefaultPublicRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet
PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub nva-${EnvironmentName}-static-ip-private-routes
DefaultPrivateRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway
PrivateSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable
SubnetId: !Ref PrivateSubnet
StaticIpSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub nva-${EnvironmentName}-static-ip-sg
GroupDescription: "Security group with no ingress rule for static IP"
VpcId: !Ref VPC
#================================= Parameters ============================================================
EventsBucketName:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the bucket name of EventsBucket so that other services can be aware of the name of the bucket.
Name: /NVA/Events/EventsBucketName
Type: String
Value: !Ref EventsBucket
EventsBucketArn:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the bucket ARN of EventsBucket so that other services can be aware of the name of the bucket.
Name: /NVA/Events/EventsBucketArn
Type: String
Value: !GetAtt EventsBucket.Arn
ResourcesStorageBucketName:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Name: /NVA/PublicationData
Description: The actual published data. E.g. Journal papers, Datasets etc.
Type: String
Value: !Ref ResourceStorageBucket
ExpandedResourcesBucketName:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the bucket name of EventsBucket so that other services can be aware of the name of the bucket.
Name: /NVA/Events/PersistedEntriesBucketName
Type: String
Value: !Ref ExpandedResourcesBucket
ExpandedResourcesBucketArn:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the bucket ARN of EventsBucket so that other services can be aware of the name of the bucket.
Name: /NVA/Events/PersistedEntriesBucketArn
Type: String
Value: !GetAtt ExpandedResourcesBucket.Arn
LargeApiResponsesBucketName:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the bucket name of LargeApiResponses so that other services can be aware of the name of the bucket.
Name: /NVA/LargeApiResponsesBucketName
Type: String
Value: !Ref LargeApiResponsesBucket
LargeApiResponsesBucketArn:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the bucket ARN of LargeApiResponses so that other services can be aware of the name of the bucket.
Name: /NVA/LargeApiResponsesBucketArn
Type: String
Value: !GetAtt LargeApiResponsesBucket.Arn
AlmaApiUriParameter:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the ALMA API URI
Name: AlmaApiUri
Type: String
Value: !Ref AlmaApiUri
BackendDomainCertificateArnParameter:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: ARN for the certificate covering the API host/domain/API Gateway Custom Domain
Name: /NVA/BackendDomainCertificate
Type: String
Value: !Ref BackendDomainCertificateArn
FrontendDomainCertificateArnParameter:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: ARN for the certificate covering the API host/domain/API Gateway Custom Domain
Name: /NVA/FrontendDomainCertificate
Type: String
Value: !Ref FrontendDomainCertificateArn
LegacyCustomDomainParameter:
Type: AWS::SSM::Parameter
Properties:
Description: Legacy Parameter Value for Custom Domain.
Name: CustomDomain
Type: String
Value: !Ref CustomDomain
DataCiteMdsEndpointParameter:
Type: AWS::SSM::Parameter
Properties:
Description: URI to Datacite MDS endpoint
Name: dataCiteMdsHost
Type: String
Value: !Ref DataCiteMdsEndpoint
DataCiteRestEndpointParameter:
Type: AWS::SSM::Parameter
Properties:
Description: URI to Datacite MDS endpoint
Name: dataCiteRestHost
Type: String
Value: !Ref DataCiteRestEndpoint
OrcidBaseUrlParameter:
Type: AWS::SSM::Parameter
Properties:
Description: URL to OrcId service
Name: OrcidBaseUrl
Type: String
Value: !Ref OrcidBaseUrl
NvaAthenaQueriesBucketName:
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: Parameter containing the bucket name of NvaAthenaQueriesBucket so that other services can be aware of the name of the bucket.
Name: /NVA/Athena/QueriesBucketName
Type: String
Value: !Ref NvaAthenaQueriesBucket
SlackSnsArnParameter:
Type: AWS::SSM::Parameter
Properties:
Description: |-
Common Amazon Simple Notification Service topic ARN for posting service notifications from all the different NVA stacks. Referenced with \{\{resolve:ssm:/NVA/Monitoring/SlackSnsArn\}\} in other templates
Name: /NVA/Monitoring/SlackSnsArn
Type: String
Value: !Ref SlackSNSTopic
SlackSnsNameParameter:
Type: AWS::SSM::Parameter
Properties:
Description: |-
Common Amazon Simple Notification Service topic name for posting service notifications from all the different NVA stacks. Referenced with \{\{resolve:ssm:/NVA/Monitoring/SlackSnsName\}\} in other templates
Name: /NVA/Monitoring/SlackSnsName
Type: String
Value: !GetAtt SlackSNSTopic.TopicName
CristinImportNviQueueParameterArn:
Type: AWS::SSM::Parameter
Properties:
Description: Amazon SQS Queue for cristin-import nvi entries
Name: /NVA/Queues/CristinImportNviQueueArn
Type: String
Value: !GetAtt CristinImportNviQueue.Arn
CristinImportNviQueueParameterUrl:
Type: AWS::SSM::Parameter
Properties:
Description: Amazon SQS Queue for cristin-import nvi entries
Name: /NVA/Queues/CristinImportNviQueueUrl
Type: String
Value: !GetAtt CristinImportNviQueue.QueueUrl
VPCParam:
Type: AWS::SSM::Parameter
Properties:
Description: VPC ID for workloads where we need a static IP
Name: "/NVA/EIP/VPC/id"
Type: String
Value: !Ref VPC
PrivateSubnetParam:
Type: AWS::SSM::Parameter
Properties:
Description: Private Subnet ID for workloads where we need a static IP
Name: "/NVA/EIP/PrivateSubnet/id"
Type: String
Value: !Ref PrivateSubnet
NatGatewayEIPParam:
Type: AWS::SSM::Parameter
Properties:
Description: Elastic IP for NAT Gateway for workloads where we need a static IP
Name: "/NVA/EIP/PublicIp"
Type: String
Value: !GetAtt NatGatewayEIP.PublicIp
StaticIpSecurityGroupParam:
Type: AWS::SSM::Parameter
Properties:
Description: Security Group ID for workloads where we need a static IP
Name: "/NVA/EIP/SecurityGroup/GroupId"
Type: String
Value: !GetAtt StaticIpSecurityGroup.GroupId
#============================== ApplicationConfig ========================
ApplicationConfig:
Type: 'AWS::AppConfig::Application'
Properties:
Description: Application Configuration for whole NVA application
Name: !Ref AppConfigName
ApplicationConfigurationProfile:
Type: 'AWS::AppConfig::ConfigurationProfile'
Properties:
ApplicationId: !Ref ApplicationConfig
Description: Application Configuration Profile for ApplicationConfig
Name: !Ref ApplicationConfigurationProfileName
LocationUri: !Sub 'arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/ApplicationConfigurationParameter'
RetrievalRoleArn: !GetAtt ApplicationConfigRole.Arn
ApplicationEnvironment:
Type: 'AWS::AppConfig::Environment'
Properties:
ApplicationId: !Ref ApplicationConfig
Description: Environment for application configuration
Name: !Ref ApplicationEnvironmentName
ApplicationConfigurationVersion:
Type: AWS::AppConfig::HostedConfigurationVersion
Properties:
ApplicationId: !Ref ApplicationConfig
ConfigurationProfileId: !Ref ApplicationConfigurationProfile
ContentType: application/json
Content: '{}'
ApplicationConfigRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: appconfig.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: ConfigurationProfileSSMPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- ssm:GetParameter
Resource: !Sub 'arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/ApplicationConfigurationParameter'
ApplicationConfigId:
Type: AWS::SSM::Parameter
Properties:
Name: /NVA/AppConfig/ApplicationConfigId
Type: String
Value: !Ref ApplicationConfig
ApplicationConfigName:
Type: AWS::SSM::Parameter
Properties:
Name: /NVA/AppConfig/ApplicationConfigName
Type: String
Value: !Ref AppConfigName
ConfigurationProfileNameParameter:
Type: AWS::SSM::Parameter
Properties:
Name: /NVA/AppConfig/ApplicationConfigProfileName
Type: String
Value: !Ref ApplicationConfigurationProfileName
EnvironmentNameParameter:
Type: AWS::SSM::Parameter
Properties:
Name: /NVA/AppConfig/ApplicationEnvironmentName
Type: String
Value: !Ref ApplicationEnvironmentName
#============================== Backup plan ==============================
NvaBackupPlan:
Type: AWS::Backup::BackupPlan
Properties:
BackupPlan:
BackupPlanName: NvaBackupPlan
BackupPlanRule:
- RuleName: HourlyBackupRule
TargetBackupVault: !Ref NvaBackupVault
ScheduleExpression: 'cron(0 */2 * * ? *)' # Every other hour
StartWindowMinutes: 60
CompletionWindowMinutes: 120
EnableContinuousBackup: true
Lifecycle:
DeleteAfterDays: !Ref DaysToRetainHourlyBackup
RecoveryPointTags:
BackupType: Hourly
CopyActions:
- DestinationBackupVaultArn: !Ref SharedBackupVaultArn
Lifecycle:
DeleteAfterDays: !Ref DaysToRetainHourlyBackup
- RuleName: DailyBackupRule
TargetBackupVault: !Ref NvaBackupVault
ScheduleExpression: 'cron(0 22 * * ? *)' # Every day at 22:00
StartWindowMinutes: 60
CompletionWindowMinutes: 120
EnableContinuousBackup: true
Lifecycle:
DeleteAfterDays: !Ref DaysToRetainDailyBackup
RecoveryPointTags:
BackupType: Daily
CopyActions:
- DestinationBackupVaultArn: !Ref SharedBackupVaultArn
Lifecycle:
DeleteAfterDays: !Ref DaysToRetainDailyBackup
- RuleName: WeeklyBackupRule
TargetBackupVault: !Ref NvaBackupVault
ScheduleExpression: 'cron(0 12 ? * 1 *)' # Every Sunday at 12:00
StartWindowMinutes: 60
CompletionWindowMinutes: 120
EnableContinuousBackup: false # PITR limits retention to 35 days
Lifecycle:
DeleteAfterDays: !Ref DaysToRetainWeeklyBackup
RecoveryPointTags:
BackupType: Weekly
CopyActions:
- DestinationBackupVaultArn: !Ref SharedBackupVaultArn
Lifecycle:
DeleteAfterDays: !Ref DaysToRetainWeeklyBackup
- RuleName: QuarterlyBackupRule
TargetBackupVault: !Ref NvaBackupVault
ScheduleExpression: 'cron(0 0 1 1,4,7,10 ? *)' # At start of every quarter
StartWindowMinutes: 60
CompletionWindowMinutes: 120
EnableContinuousBackup: false # PITR limits retention to 35 days
Lifecycle:
DeleteAfterDays: !Ref DaysToRetainQuarterlyBackup
RecoveryPointTags:
BackupType: Quarterly
CopyActions:
- DestinationBackupVaultArn: !Ref SharedBackupVaultArn
Lifecycle:
DeleteAfterDays: !Ref DaysToRetainQuarterlyBackup
NvaBackupVault:
Type: AWS::Backup::BackupVault
Properties:
BackupVaultName: NvaBackupVault
AccessPolicy:
Version: "2012-10-17"
Statement:
# Allow the cross-account vault to copy snapshots into this vault,
# necessary for cross-region restores.
- Sid: AllowCopyFromSharedVault
Effect: Allow
Principal:
AWS: !Ref SharedBackupAccountId
Action:
- backup:CopyIntoBackupVault
Resource: '*'
NvaBackupSelection:
Type: AWS::Backup::BackupSelection
Condition: CreateBackups
Properties:
BackupPlanId: !Ref NvaBackupPlan
BackupSelection:
SelectionName: NvaBackupSelection
IamRoleArn: !GetAtt BackupRole.Arn
Conditions:
StringEquals:
- ConditionKey: 'aws:ResourceTag/IncludedInBackup'
ConditionValue: 'true'
Resources:
- arn:aws:dynamodb:*:*:table/*
- arn:aws:s3:::*
BackupRole:
Type: AWS::IAM::Role
Properties:
RoleName: BackupServiceRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: backup.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup"
- !Sub "arn:${AWS::Partition}:iam::aws:policy/AWSBackupServiceRolePolicyForS3Backup"
LambdaVersionCleanupFunctionAccessLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub '/aws/lambda/${LambdaVersionCleanupFunction}'
RetentionInDays: 90
LambdaVersionCleanupFunction:
Type: AWS::Serverless::Function
Properties:
Description: 'Lambda function to delete old version of all lambda functions'
Handler: delete_old_lambda_versions.lambda_handler
Runtime: python3.11
Timeout: 900
MemorySize: 128
Role: !GetAtt LambdaVersionCleanupRole.Arn
CodeUri: .
Events:
ScheduledEvent:
Type: Schedule
Properties:
Description: 'Schedule to trigger deletion of old versions of lambda functions'
Schedule: rate(7 days)
Name: CleanupLambdaVersionSchedule
LambdaVersionCleanupRole:
Type: AWS::IAM::Role
Properties:
Description: 'IAM role for the lamda that deletes old versions of all lambda functions'
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: LambdaVersionCleanupPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- lambda:ListAliases
- lambda:ListFunctions
- lambda:ListVersionsByFunction
- lambda:DeleteFunction
Resource: "*"
Outputs:
LambdaVersionCleanupFunction:
Description: "ARN of the version cleanup Lambda function"
Value: !GetAtt LambdaVersionCleanupFunction.Arn