aws-cdk-constructs 2.22.2__tar.gz → 2.24.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/PKG-INFO +1 -1
  2. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/__init__.py +2 -1
  3. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/bucket/bucket.py +68 -1
  4. aws_cdk_constructs-2.24.0/aws_cdk_constructs/database/__init__.py +2 -0
  5. aws_cdk_constructs-2.24.0/aws_cdk_constructs/database/_types/__init__.py +1 -0
  6. aws_cdk_constructs-2.24.0/aws_cdk_constructs/database/_types/graph.py +185 -0
  7. aws_cdk_constructs-2.24.0/aws_cdk_constructs/database/_types/relational.py +467 -0
  8. aws_cdk_constructs-2.24.0/aws_cdk_constructs/database/database.py +452 -0
  9. aws_cdk_constructs-2.24.0/aws_cdk_constructs/database/types.py +6 -0
  10. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/load_balancer/alb.py +130 -58
  11. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/microservice/microservice.py +29 -4
  12. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs.egg-info/PKG-INFO +1 -1
  13. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs.egg-info/SOURCES.txt +4 -0
  14. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs.egg-info/requires.txt +2 -1
  15. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/setup.py +3 -2
  16. aws_cdk_constructs-2.22.2/aws_cdk_constructs/database/__init__.py +0 -1
  17. aws_cdk_constructs-2.22.2/aws_cdk_constructs/database/database.py +0 -798
  18. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/LICENSE.txt +0 -0
  19. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/MANIFEST.in +0 -0
  20. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/README.md +0 -0
  21. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/api/__init__.py +0 -0
  22. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/api/api.py +0 -0
  23. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/bucket/__init__.py +0 -0
  24. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/ecs/__init__.py +0 -0
  25. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/ecs/cluster.py +0 -0
  26. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/ecs/microservice.py +0 -0
  27. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/efs/__init__.py +0 -0
  28. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/efs/volume.py +0 -0
  29. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/load_balancer/__init__.py +0 -0
  30. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/load_balancer/nlb.py +0 -0
  31. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/microservice/__init__.py +0 -0
  32. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/microservice/base_user_data.sh +0 -0
  33. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/microservice/manage_connection_to_nlb_instance_security_group_ingress/lambda_function.js +0 -0
  34. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/security_group/__init__.py +0 -0
  35. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/security_group/security_group.py +0 -0
  36. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/service_user_for_iac/__init__.py +0 -0
  37. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/service_user_for_iac/service_user_for_iac.py +0 -0
  38. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/service_user_for_static_assets/__init__.py +0 -0
  39. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/service_user_for_static_assets/service_user_for_static_assets.py +0 -0
  40. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/utils.py +0 -0
  41. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/windows_server/__init__.py +0 -0
  42. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/windows_server/user_data.ps1 +0 -0
  43. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs/windows_server/windows_server.py +0 -0
  44. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs.egg-info/dependency_links.txt +0 -0
  45. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/aws_cdk_constructs.egg-info/top_level.txt +0 -0
  46. {aws_cdk_constructs-2.22.2 → aws_cdk_constructs-2.24.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aws_cdk_constructs
3
- Version: 2.22.2
3
+ Version: 2.24.0
4
4
  Summary: AWS CDK constructs
5
5
  Home-page: https://bitbucket.org/cioapps/aws-cdk-constructs
6
6
  Author: author
@@ -1,6 +1,7 @@
1
1
  """aws_cdk_constructs package."""
2
2
  from .microservice import Microservice
3
3
  from .database import Database
4
+ from .database import DatabaseType
4
5
  from .bucket import Bucket
5
6
  from .ecs.cluster import ECSCluster
6
7
  from .ecs.microservice import ECSMicroservice
@@ -12,4 +13,4 @@ from .load_balancer import Alb, Nlb
12
13
  from .security_group import SecurityGroup
13
14
  from .windows_server import WindowsServer
14
15
 
15
- __version__ = '2.22.2'
16
+ __version__ = '2.24.0'
@@ -8,6 +8,9 @@ from aws_cdk import (
8
8
  aws_kms as _kms,
9
9
  aws_route53 as route53,
10
10
  aws_route53_targets as route53_targets,
11
+ aws_cloudfront as _cloudfront,
12
+ aws_cloudfront_origins as _cloudfront_origins,
13
+ aws_certificatemanager as _certificate,
11
14
  )
12
15
  import boto3
13
16
  from aws_cdk_constructs.utils import (
@@ -93,6 +96,13 @@ class Bucket(Construct):
93
96
  bucket_enforces_ssl(str): Whether to enforce SSL for the CloudFront distribution. Default: false
94
97
 
95
98
  omit_cloudformation_template_outputs(bool): Omit the generation of CloudFormation template outputs. Default: false
99
+
100
+ will_implement_cdn (str): Whether or not a CloudFront distribution should be deployed in front of the load balancer. Only applicable when an Application Load Balancer is in use
101
+
102
+ cdn_domain_names ([str]): If "will_implement_cdn" is "True", it specifies the domain names to associate to the CloudFront distribution. Please make sure that tha provided domain names match the SSL certificate in use
103
+
104
+ cdn_ssl_certificate_arn (str): If "will_implement_cdn" is "True" and you want to enable HTTPS for your CloudFront distribution, specify the SSL certificate ARN to use. NB: this certificate must be in North Virginia
105
+
96
106
  """
97
107
 
98
108
  @property
@@ -104,6 +114,17 @@ class Bucket(Construct):
104
114
  """
105
115
  return self.bucket
106
116
 
117
+ @property
118
+ def cloudfront_distribution(
119
+ self,
120
+ ) -> Union[_cloudfront.IDistribution, None]:
121
+ """Returns the CloudFront distribution, if available
122
+
123
+ Returns:
124
+ aws_cloudfront.IDistribution: the Cloudfront distribution
125
+ """
126
+ return self._cloudfront_distribution
127
+
107
128
  def create_bucket(
108
129
  self,
109
130
  logic_id: str,
@@ -116,7 +137,7 @@ class Bucket(Construct):
116
137
  removal_policy: aws_cdk.RemovalPolicy = None,
117
138
  versioned: bool = False,
118
139
  is_encrypted: bool = False,
119
- encryption_allowed_principals_arns: Union[str, List[str]] = None,
140
+ encryption_allowed_principals_arns: [str, List[str]] = None,
120
141
  enforce_ssl: bool = False,
121
142
  **kwargs,
122
143
  ):
@@ -138,6 +159,9 @@ class Bucket(Construct):
138
159
  is_encrypted: bool = False,
139
160
  encryption_allowed_principals_arns: Union[str, List[str]] = None,
140
161
  enforce_ssl: bool = False,
162
+ will_implement_cdn: str = 'false',
163
+ cdn_domain_names: [str] = [],
164
+ cdn_ssl_certificate_arn: str = None,
141
165
  **kwargs,
142
166
  ) -> aws_cdk.aws_s3.Bucket:
143
167
  """Create an S3 bucket
@@ -168,6 +192,12 @@ class Bucket(Construct):
168
192
 
169
193
  enforce_ssl(Bool): Whether to enforce SSL for the CloudFront distribution. Default: false
170
194
 
195
+ will_implement_cdn (str): Whether or not a CloudFront distribution should be deployed in front of the load balancer. Only applicable when an Application Load Balancer is in use
196
+
197
+ cdn_domain_names ([str]): If "will_implement_cdn" is "True", it specifies the domain names to associate to the CloudFront distribution. Please make sure that tha provided domain names match the SSL certificate in use
198
+
199
+ cdn_ssl_certificate_arn (str): If "will_implement_cdn" is "True" and you want to enable HTTPS for your CloudFront distribution, specify the SSL certificate ARN to use. NB: this certificate must be in North Virginia
200
+
171
201
  Returns:
172
202
  aws_s3.Bucket: the S3 bucket
173
203
  """
@@ -262,6 +292,37 @@ class Bucket(Construct):
262
292
  record_name=f'{dns_record}.{domain_name}',
263
293
  )
264
294
 
295
+ create_cloudfront_distribution = (
296
+ will_implement_cdn
297
+ and isinstance(will_implement_cdn, str)
298
+ and will_implement_cdn.lower() == 'true'
299
+ )
300
+ # Create CloudFront distribution
301
+ if create_cloudfront_distribution:
302
+ self._cloudfront_distribution = _cloudfront.Distribution(
303
+ self,
304
+ f'distribution_{bucket_name}',
305
+ default_behavior=_cloudfront.BehaviorOptions(
306
+ origin=_cloudfront_origins.S3Origin(s3_bucket),
307
+ compress=True,
308
+ viewer_protocol_policy=_cloudfront.ViewerProtocolPolicy.HTTPS_ONLY,
309
+ allowed_methods=_cloudfront.AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
310
+ cache_policy=_cloudfront.CachePolicy.CACHING_DISABLED,
311
+ origin_request_policy=_cloudfront.OriginRequestPolicy.ALL_VIEWER,
312
+ ),
313
+ certificate=_certificate.Certificate.from_certificate_arn(
314
+ self,
315
+ 'https_certificate_cdn',
316
+ certificate_arn=cdn_ssl_certificate_arn
317
+ if cdn_ssl_certificate_arn
318
+ else self.aws_account[
319
+ 'ssl_certificate_star_fao_org_arn_north_virginia'
320
+ ],
321
+ ),
322
+ price_class=_cloudfront.PriceClass.PRICE_CLASS_100,
323
+ domain_names=cdn_domain_names,
324
+ )
325
+
265
326
  return s3_bucket
266
327
 
267
328
  def __init__(
@@ -285,6 +346,9 @@ class Bucket(Construct):
285
346
  cdn_http_headers: Dict[str, str] = None,
286
347
  bucket_enforces_ssl: bool = False,
287
348
  omit_cloudformation_template_outputs: bool = False,
349
+ will_implement_cdn: str = 'false',
350
+ cdn_domain_names: [str] = [],
351
+ cdn_ssl_certificate_arn: str = None,
288
352
  **kwargs,
289
353
  ) -> None:
290
354
  super().__init__(scope, id, **kwargs)
@@ -411,6 +475,9 @@ class Bucket(Construct):
411
475
  is_encrypted=is_encrypted,
412
476
  encryption_allowed_principals_arns=encryption_allowed_principals_arns,
413
477
  enforce_ssl=enforce_ssl,
478
+ will_implement_cdn=will_implement_cdn,
479
+ cdn_domain_names=cdn_domain_names,
480
+ cdn_ssl_certificate_arn=cdn_ssl_certificate_arn,
414
481
  )
415
482
 
416
483
  if bucket_is_privately_accessed_from_vpc_over_http:
@@ -0,0 +1,2 @@
1
+ from .database import Database
2
+ from .database import DatabaseType
@@ -0,0 +1 @@
1
+ from .relational import RelationalDatabase
@@ -0,0 +1,185 @@
1
+ from aws_cdk import (
2
+ aws_neptune_alpha as _neptune,
3
+ aws_ec2 as _ec2,
4
+ aws_kms as _kms,
5
+ aws_route53 as route53,
6
+ RemovalPolicy as removal_policy,
7
+ aws_logs as _logs,
8
+ )
9
+ import aws_cdk as cdk
10
+ from typing import Union, List
11
+
12
+
13
+ def GraphDatabase(
14
+ scope,
15
+ app_name: str,
16
+ environment: str,
17
+ environments_parameters: dict,
18
+ vpc: _ec2.Vpc,
19
+ security_groups: List[_ec2.SecurityGroup],
20
+ database_instance_type: str,
21
+ database_identifier: str,
22
+ is_production: bool,
23
+ is_ha: bool,
24
+ parameter_group: _neptune.ParameterGroup = None,
25
+ database_engine_version: Union[str, _neptune.EngineVersion] = None,
26
+ database_cluster_parameters_group_name: str = None,
27
+ database_identifier_postfix: str = '',
28
+ create_dns: str = 'True',
29
+ tag_scheduler_uptime: str = '',
30
+ tag_scheduler_uptime_days: str = '',
31
+ tag_scheduler_uptime_skip: str = '',
32
+ cloudwatch_audit_log: str = None,
33
+ dns_record: str = None,
34
+ ):
35
+ environment = environment.lower()
36
+ aws_account = environments_parameters['accounts'][environment]
37
+ account_id = aws_account['id']
38
+
39
+ is_not_production = not is_production
40
+
41
+ _cluster = None
42
+
43
+ # ~~~~~~~~~~~~~~~~
44
+ # RDS Instance type
45
+ # ~~~~~~~~~~~~~~~~
46
+ instance_type = _neptune.InstanceType.of(database_instance_type)
47
+
48
+ # ~~~~~~~~~~~~~~~~
49
+ # KMS Encryption key
50
+ # ~~~~~~~~~~~~~~~~
51
+ key_arn = (
52
+ 'arn:aws:kms:eu-west-1:'
53
+ + account_id
54
+ + ':key/'
55
+ + aws_account['kms_neptune_key']
56
+ )
57
+ encryption_key = _kms.Key.from_key_arn(scope, 'encryption_key', key_arn)
58
+
59
+ # ~~~~~~~~~~~~~~~~
60
+ # Neptune Logs
61
+ # ~~~~~~~~~~~~~~~~
62
+ # Default Neptune cloudwatch logs export in NONE
63
+ cloudwatch_logs_exports = None
64
+ should_be_cloudwatch_audit_log = (
65
+ cloudwatch_audit_log
66
+ and isinstance(cloudwatch_audit_log, str)
67
+ and cloudwatch_audit_log.lower() == 'true'
68
+ )
69
+
70
+ if should_be_cloudwatch_audit_log:
71
+ # If user specified change to cloud watch log setting
72
+ cloudwatch_logs_exports = [_neptune.LogType.AUDIT]
73
+
74
+ # ~~~~~~~~~~~~~~~~
75
+ # Neptune Parameter group
76
+ # ~~~~~~~~~~~~~~~~
77
+ default_cluster_params = {}
78
+ if should_be_cloudwatch_audit_log:
79
+ default_cluster_params.update({'neptune_enable_audit_log': '1'})
80
+
81
+ my_parameter_group = parameter_group or _neptune.ClusterParameterGroup(
82
+ scope,
83
+ f'{app_name}cluster_params',
84
+ description=f'{app_name} - Cluster parameter group',
85
+ parameters=default_cluster_params,
86
+ family=_neptune.ParameterGroupFamily.NEPTUNE_1_2,
87
+ )
88
+
89
+ my_engine_version = (
90
+ database_engine_version
91
+ if database_engine_version
92
+ else _neptune.EngineVersion.V1_2_1_0
93
+ )
94
+
95
+ # ~~~~~~~~~~~~~~~~
96
+ # Neptune Cluster
97
+ # ~~~~~~~~~~~~~~~~
98
+ _cluster = _neptune.DatabaseCluster(
99
+ scope,
100
+ 'cluster',
101
+ instance_type=instance_type,
102
+ vpc=vpc,
103
+ # associated_roles=None,
104
+ auto_minor_version_upgrade=False,
105
+ backup_retention=cdk.Duration.days(30),
106
+ cloudwatch_logs_exports=cloudwatch_logs_exports,
107
+ cloudwatch_logs_retention=_logs.RetentionDays.ONE_MONTH,
108
+ # cloudwatch_logs_retention_role=None, # Create a new role
109
+ cluster_parameter_group=my_parameter_group,
110
+ db_cluster_name=database_identifier + 'cluster',
111
+ deletion_protection=is_production,
112
+ engine_version=my_engine_version,
113
+ # iam_authentication=None
114
+ instance_identifier_base=database_identifier,
115
+ instances=2 if is_ha else 1,
116
+ kms_key=encryption_key,
117
+ # parameter_group=None TODO: implement when this will be needed
118
+ preferred_backup_window='01:00-02:00',
119
+ preferred_maintenance_window='mon:03:00-mon:04:00',
120
+ removal_policy=removal_policy.RETAIN
121
+ if is_production
122
+ else removal_policy.DESTROY,
123
+ security_groups=security_groups,
124
+ storage_encrypted=True,
125
+ # subnet_group=None, # Use default value, create a new subnet group
126
+ # vpc_subnets=None, # Do not specify to host the db in the private subnets
127
+ )
128
+
129
+ if not is_production and create_dns.lower() == 'true':
130
+ # Create DNS record
131
+ cluster_hostname = str(_cluster.cluster_endpoint)
132
+ cluster_hostname = ''.join(cluster_hostname.split())
133
+
134
+ hosted_zone_id = aws_account['route53_hosted_zone_id']
135
+ domain_name = aws_account['route53_domain_name']
136
+
137
+ dns_record = 'db.' + app_name if app_name else dns_record
138
+ dns_record = (
139
+ dns_record + '-' + database_identifier_postfix
140
+ if database_identifier_postfix
141
+ else dns_record
142
+ )
143
+ route53_zone = route53.PrivateHostedZone.from_hosted_zone_attributes(
144
+ scope,
145
+ f'RDSPrivateHostedZone{dns_record}',
146
+ hosted_zone_id=hosted_zone_id,
147
+ zone_name=domain_name,
148
+ )
149
+ route53.CnameRecord(
150
+ scope,
151
+ f'RDSAliasRecord{dns_record}',
152
+ zone=route53_zone,
153
+ # target=cdk.Token.as_string(self._cluster.cluster_endpoint), # << Not working here
154
+ # target=route53.RecordTarget.from_values(self._cluster.cluster_endpoint.hostname),
155
+ domain_name=cluster_hostname,
156
+ record_name=f'{dns_record}.{domain_name}',
157
+ )
158
+
159
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FAO AWS Scheduler tags
160
+ if is_not_production:
161
+ clus = _cluster.node.find_child('Resource')
162
+ instance = _cluster.node.find_child('Instance1')
163
+
164
+ if tag_scheduler_uptime_skip:
165
+ cdk.Tags.of(clus).add('SchedulerSkip', tag_scheduler_uptime_skip)
166
+ cdk.Tags.of(instance).add(
167
+ 'SchedulerSkip', tag_scheduler_uptime_skip
168
+ )
169
+
170
+ if tag_scheduler_uptime:
171
+ cdk.Tags.of(clus).add('SchedulerUptime', tag_scheduler_uptime)
172
+ cdk.Tags.of(instance).add('SchedulerUptime', tag_scheduler_uptime)
173
+
174
+ if tag_scheduler_uptime_days:
175
+ cdk.Tags.of(clus).add(
176
+ 'SchedulerUptimeDays', tag_scheduler_uptime_days
177
+ )
178
+ cdk.Tags.of(instance).add(
179
+ 'SchedulerUptimeDays', tag_scheduler_uptime_days
180
+ )
181
+
182
+ # ~~~~~~~~~~~~~~~~
183
+ # Return
184
+ # ~~~~~~~~~~~~~~~~
185
+ return _cluster