aws-cdk-constructs 2.26.3__tar.gz → 2.28.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 (48) hide show
  1. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/PKG-INFO +1 -1
  2. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/__init__.py +2 -2
  3. aws_cdk_constructs-2.28.0/aws_cdk_constructs/api/__init__.py +1 -0
  4. aws_cdk_constructs-2.28.0/aws_cdk_constructs/api/api.py +131 -0
  5. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/bucket/bucket.py +73 -83
  6. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/microservice/microservice.py +21 -5
  7. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs.egg-info/PKG-INFO +1 -1
  8. aws_cdk_constructs-2.26.3/aws_cdk_constructs/api/__init__.py +0 -1
  9. aws_cdk_constructs-2.26.3/aws_cdk_constructs/api/api.py +0 -82
  10. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/LICENSE.txt +0 -0
  11. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/MANIFEST.in +0 -0
  12. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/README.md +0 -0
  13. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/bucket/__init__.py +0 -0
  14. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/database/__init__.py +0 -0
  15. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/database/_types/__init__.py +0 -0
  16. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/database/_types/document.py +0 -0
  17. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/database/_types/graph.py +0 -0
  18. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/database/_types/relational.py +0 -0
  19. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/database/database.py +0 -0
  20. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/database/types.py +0 -0
  21. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/ecs/__init__.py +0 -0
  22. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/ecs/cluster.py +0 -0
  23. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/ecs/fargate_validator.py +0 -0
  24. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/ecs/microservice.py +0 -0
  25. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/efs/__init__.py +0 -0
  26. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/efs/volume.py +0 -0
  27. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/load_balancer/__init__.py +0 -0
  28. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/load_balancer/alb.py +0 -0
  29. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/load_balancer/nlb.py +0 -0
  30. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/microservice/__init__.py +0 -0
  31. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/microservice/base_user_data.sh +0 -0
  32. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/microservice/manage_connection_to_nlb_instance_security_group_ingress/lambda_function.js +0 -0
  33. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/security_group/__init__.py +0 -0
  34. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/security_group/security_group.py +0 -0
  35. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/service_user_for_iac/__init__.py +0 -0
  36. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/service_user_for_iac/service_user_for_iac.py +0 -0
  37. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/service_user_for_static_assets/__init__.py +0 -0
  38. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/service_user_for_static_assets/service_user_for_static_assets.py +0 -0
  39. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/utils.py +0 -0
  40. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/windows_server/__init__.py +0 -0
  41. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/windows_server/user_data.ps1 +0 -0
  42. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs/windows_server/windows_server.py +0 -0
  43. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs.egg-info/SOURCES.txt +0 -0
  44. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs.egg-info/dependency_links.txt +0 -0
  45. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs.egg-info/requires.txt +0 -0
  46. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/aws_cdk_constructs.egg-info/top_level.txt +0 -0
  47. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/setup.cfg +0 -0
  48. {aws_cdk_constructs-2.26.3 → aws_cdk_constructs-2.28.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aws_cdk_constructs
3
- Version: 2.26.3
3
+ Version: 2.28.0
4
4
  Summary: AWS CDK constructs
5
5
  Home-page: https://bitbucket.org/cioapps/aws-cdk-constructs
6
6
  Author: author
@@ -7,11 +7,11 @@ from .bucket import Bucket
7
7
  from .ecs.cluster import ECSCluster
8
8
  from .ecs.microservice import ECSMicroservice
9
9
  from .efs.volume import EFSVolume
10
- from .api import API
10
+ from .api import Api
11
11
  from .service_user_for_iac import ServiceUserForIAC
12
12
  from .service_user_for_static_assets import ServiceUserForStaticAssets
13
13
  from .load_balancer import Alb, Nlb
14
14
  from .security_group import SecurityGroup
15
15
  from .windows_server import WindowsServer
16
16
 
17
- __version__ = '2.26.3'
17
+ __version__ = '2.28.0'
@@ -0,0 +1 @@
1
+ from .api import Api
@@ -0,0 +1,131 @@
1
+ import aws_cdk as cdk
2
+ from constructs import Construct
3
+ from aws_cdk import aws_apigateway as _apigateway
4
+
5
+ from aws_cdk_constructs.utils import (
6
+ normalize_environment_parameter,
7
+ get_version,
8
+ )
9
+ from typing import Union
10
+
11
+
12
+ class Api(Construct):
13
+ @property
14
+ def api(
15
+ self,
16
+ ) -> _apigateway.SpecRestApi:
17
+ """Returns the API Gateway construct
18
+
19
+ Returns:
20
+ _apigateway.SpecRestApi: API Gateway construct
21
+ """
22
+ return self._api
23
+
24
+ @property
25
+ def key(
26
+ self,
27
+ ) -> _apigateway.ApiKey:
28
+ """Returns the API Gateway key
29
+
30
+ bReturns:
31
+ _apigateway.ApiKey: API Gateway key
32
+ """
33
+ return self._key
34
+
35
+ @property
36
+ def usage_plan(
37
+ self,
38
+ ) -> _apigateway.UsagePlan:
39
+ """Returns the API Gateway usage plan associated to the key
40
+
41
+ bReturns:
42
+ _apigateway.UsagePlan: Returns the API Gateway usage plan associated to the key
43
+ """
44
+ return self._usage_plan
45
+
46
+ """
47
+
48
+ The FAO CDK Api Construct creates an AWS Api Gateway REST Api, providing a Swagger JSON file.
49
+
50
+ Every resource created by the construct will be tagged according to the FAO AWS tagging strategy described at https://aws.fao.org
51
+
52
+ Args:
53
+
54
+ id (str): the logical id of the newly created resource
55
+
56
+ app_name (str): The application name. This will be used to generate the 'ApplicationName' tag for CSI compliancy. The ID of the application. This must be unique for each system, as it will be used to calculate the AWS costs of the system
57
+
58
+ environment (str): Specify the environment in which you want to deploy you system. Allowed values: Development, QA, Production, SharedServices
59
+
60
+ environments_parameters (dict): The dictionary containing the references to CSI AWS environments. This will simplify the environment promotions and enable a parametric development of the infrastructures.
61
+
62
+ api_definition_path (str): The path to the OpenAI definition (or compatible) to use to auto-generate Api Gateway
63
+
64
+ """
65
+
66
+ def __init__(
67
+ self,
68
+ scope: Construct,
69
+ id: str,
70
+ app_name: str,
71
+ environment: str,
72
+ environments_parameters: dict,
73
+ api_definition_path: str,
74
+ quota: Union[_apigateway.QuotaSettings, None] = None,
75
+ throttle: Union[_apigateway.ThrottleSettings, None] = None,
76
+ stage_options: Union[_apigateway.StageOptions, None] = None,
77
+ **kwargs,
78
+ ) -> None:
79
+ super().__init__(scope, id, **kwargs)
80
+ environment = normalize_environment_parameter(environment)
81
+
82
+ # Apply mandatory tags
83
+ cdk.Tags.of(self).add('ApplicationName', app_name.lower().strip())
84
+ cdk.Tags.of(self).add('Environment', environment)
85
+
86
+ # Apply FAO CDK tags
87
+ cdk.Tags.of(self).add('fao-cdk-construct', 'api')
88
+ cdk.Tags.of(cdk.Stack.of(self)).add('fao-cdk-version', get_version())
89
+ cdk.Tags.of(cdk.Stack.of(self)).add('fao-cdk', 'true')
90
+
91
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create conditions
92
+ api_definition_path = api_definition_path.strip()
93
+
94
+ environment_lower = environment.lower()
95
+ aws_account = environments_parameters['accounts'][environment_lower]
96
+
97
+ self._api = _apigateway.SpecRestApi(
98
+ self,
99
+ f'{id}-{environment_lower}',
100
+ api_definition=_apigateway.ApiDefinition.from_asset(
101
+ api_definition_path
102
+ ),
103
+ deploy_options=(
104
+ stage_options
105
+ if stage_options
106
+ else _apigateway.StageOptions(
107
+ cache_data_encrypted=False,
108
+ caching_enabled=False,
109
+ data_trace_enabled=False,
110
+ description=f'[{app_name}] {id} {environment_lower}',
111
+ stage_name=environment_lower,
112
+ )
113
+ ),
114
+ )
115
+
116
+ self._usage_plan = self._api.add_usage_plan(
117
+ f'{id}-{environment_lower}-usage-plan',
118
+ name=f'{id}-{environment_lower}-usage-plan',
119
+ quota=quota,
120
+ throttle=throttle,
121
+ )
122
+
123
+ self._usage_plan.add_api_stage(
124
+ stage=self._api.deployment_stage,
125
+ )
126
+
127
+ self._key = self._api.add_api_key(
128
+ f'{id}-{environment_lower}-key',
129
+ api_key_name=f'{id}-{environment_lower}-key',
130
+ )
131
+ self._usage_plan.add_api_key(self._key)
@@ -107,13 +107,25 @@ class Bucket(Construct):
107
107
  """
108
108
 
109
109
  @property
110
- def get_s3_bucket(self) -> aws_cdk.aws_s3.Bucket:
110
+ def bucket(self) -> aws_cdk.aws_s3.Bucket:
111
+ """DEPRECATED: Returns the S3 bucket
112
+
113
+ Returns:
114
+ aws_s3.Bucket: the S3 bucket
115
+ """
116
+ return self._bucket
117
+
118
+ @property
119
+ def get_s3_bucket(self):
111
120
  """Returns the S3 bucket
112
121
 
113
122
  Returns:
114
123
  aws_s3.Bucket: the S3 bucket
115
124
  """
116
- return self.bucket
125
+
126
+ raise DeprecationWarning(
127
+ 'This is a deprecated method, please do not use it. use Bucket.bucket attribute instead.'
128
+ )
117
129
 
118
130
  @property
119
131
  def cloudfront_distribution(
@@ -146,12 +158,61 @@ class Bucket(Construct):
146
158
  'This is a deprecated method, please do not use it. Instantiate a new FAI CDK Bucket construct instead.'
147
159
  )
148
160
 
161
+ def update_distribution_origin_access(self):
162
+ ## clean-up the OAI reference and associate the OAC with the cloudfront distribution
163
+ # query the site bucket policy as a document
164
+ bucket_policy = self.bucket.policy
165
+ bucket_policy_document = bucket_policy.document
166
+
167
+ # remove the CloudFront Origin Access Identity permission from the bucket policy
168
+ if isinstance(bucket_policy_document, _iam.PolicyDocument):
169
+ bucket_policy_document_json = bucket_policy_document.to_json()
170
+ # create an updated policy without the OAI reference
171
+ bucket_policy_updated_json = {
172
+ 'Version': '2012-10-17',
173
+ 'Statement': [],
174
+ }
175
+ for statement in bucket_policy_document_json['Statement']:
176
+ if 'CanonicalUser' not in statement['Principal']:
177
+ bucket_policy_updated_json['Statement'].append(statement)
178
+
179
+ # apply the updated bucket policy to the bucket
180
+ bucket_policy_override = self.bucket.node.find_child(
181
+ 'Policy'
182
+ ).node.default_child
183
+ bucket_policy_override.add_override(
184
+ 'Properties.PolicyDocument', bucket_policy_updated_json
185
+ )
186
+
187
+ # remove the created OAI reference (S3 Origin property) for the distribution
188
+ all_distribution_props = self._cloudfront_distribution.node.find_all()
189
+ for child in all_distribution_props:
190
+ if child.node.id == 'S3Origin':
191
+ child.node.try_remove_child('Resource')
192
+
193
+ # associate the created OAC with the distribution
194
+ distribution_props = self._cloudfront_distribution.node.default_child
195
+
196
+ # The amount of the distribution origins is equal to the number of direct CDK object
197
+ # of the distribution construct - 1 (the Resource object)
198
+ origins_amount = len(self._cloudfront_distribution.node.children) - 1
199
+
200
+ for index in range(0, origins_amount):
201
+ distribution_props.add_override(
202
+ f'Properties.DistributionConfig.Origins.{index}.S3OriginConfig.OriginAccessIdentity',
203
+ '',
204
+ )
205
+ distribution_props.add_property_override(
206
+ f'DistributionConfig.Origins.{index}.OriginAccessControlId',
207
+ self._origin_access_control.ref,
208
+ )
209
+
149
210
  def _create_bucket(
150
211
  self,
151
212
  logic_id: str,
152
213
  bucket_name: str,
153
214
  app_name: str,
154
- access_control: aws_cdk.aws_s3.BucketAccessControl = None,
215
+ access_control: Union[aws_cdk.aws_s3.BucketAccessControl, None] = None,
155
216
  public_read_access: bool = False,
156
217
  website_index_document: str = None,
157
218
  website_error_document: str = None,
@@ -363,71 +424,6 @@ class Bucket(Construct):
363
424
  for statement in bucket_policy_statements:
364
425
  s3_bucket.add_to_resource_policy(statement)
365
426
 
366
- ## clean-up the OAI reference and associate the OAC with the cloudfront distribution
367
- # query the site bucket policy as a document
368
- bucket_policy = s3_bucket.policy
369
- bucket_policy_document = bucket_policy.document
370
-
371
- # remove the CloudFront Origin Access Identity permission from the bucket policy
372
- if isinstance(bucket_policy_document, _iam.PolicyDocument):
373
- bucket_policy_document_json = bucket_policy_document.to_json()
374
- # create an updated policy without the OAI reference
375
- bucket_policy_updated_json = {
376
- 'Version': '2012-10-17',
377
- 'Statement': [],
378
- }
379
- for statement in bucket_policy_document_json['Statement']:
380
- if 'CanonicalUser' not in statement['Principal']:
381
- bucket_policy_updated_json['Statement'].append(
382
- statement
383
- )
384
-
385
- # apply the updated bucket policy to the bucket
386
- bucket_policy_override = s3_bucket.node.find_child(
387
- 'Policy'
388
- ).node.default_child
389
- bucket_policy_override.add_override(
390
- 'Properties.PolicyDocument', bucket_policy_updated_json
391
- )
392
-
393
- # remove the created OAI reference (S3 Origin property) for the distribution
394
- all_distribution_props = (
395
- self._cloudfront_distribution.node.find_all()
396
- )
397
- for child in all_distribution_props:
398
- if child.node.id == 'S3Origin':
399
- child.node.try_remove_child('Resource')
400
-
401
- # associate the created OAC with the distribution
402
- distribution_props = (
403
- self._cloudfront_distribution.node.default_child
404
- )
405
- distribution_props.add_override(
406
- 'Properties.DistributionConfig.Origins.0.S3OriginConfig.OriginAccessIdentity',
407
- '',
408
- )
409
- distribution_props.add_property_override(
410
- 'DistributionConfig.Origins.0.OriginAccessControlId',
411
- self._origin_access_control.ref,
412
- )
413
-
414
- # Assign Origin Access Control
415
- # indexes = ["0"]
416
- # for index in indexes:
417
- # self._cloudfront_distribution.node.find_child(
418
- # "Resource"
419
- # ).add_property_override(
420
- # f"DistributionConfig.Origins.{index}.OriginAccessControlId",
421
- # self._origin_access_control.get_att("Id"),
422
- # )
423
-
424
- # self._cloudfront_distribution.node.find_child(
425
- # "Resource"
426
- # ).add_property_override(
427
- # f"DistributionConfig.Origins.{index}.S3OriginConfig.OriginAccessIdentity",
428
- # {},
429
- # )
430
-
431
427
  return s3_bucket
432
428
 
433
429
  def __init__(
@@ -471,18 +467,12 @@ class Bucket(Construct):
471
467
  cdk.Tags.of(cdk.Stack.of(self)).add('fao-cdk', 'true')
472
468
 
473
469
  # Declare variables
474
- self.bucket = None
475
-
476
470
  environment = environment.lower()
477
471
  self.environment = environment
478
472
  self.aws_account = environments_parameters['accounts'][environment]
479
473
  logic_id = bucket_logic_id if bucket_logic_id else 'S3'
480
474
 
481
475
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create conditions
482
- # bucket_name_was_provided = bucket_name.strip()
483
- # bucket_already_exist = check_if_bucket_exist(
484
- # s3_bucket_name=bucket_name
485
- # )
486
476
 
487
477
  # Check if bucket has to be public
488
478
  public_read_access = (
@@ -558,7 +548,7 @@ class Bucket(Construct):
558
548
  removal_policy = cdk.RemovalPolicy.RETAIN
559
549
 
560
550
  # Default access level: PRIVATE
561
- self.bucket = self._create_bucket(
551
+ self._bucket = self._create_bucket(
562
552
  logic_id=logic_id,
563
553
  app_name=app_name,
564
554
  bucket_name=bucket_name,
@@ -596,7 +586,7 @@ class Bucket(Construct):
596
586
  public_read_access = False
597
587
  bucket_has_cdn = False
598
588
 
599
- self.bucket.add_to_resource_policy(
589
+ self._bucket.add_to_resource_policy(
600
590
  _iam.PolicyStatement(
601
591
  principals=[_iam.AnyPrincipal()],
602
592
  actions=['s3:GetObject'],
@@ -614,17 +604,17 @@ class Bucket(Construct):
614
604
 
615
605
  if public_read_access:
616
606
  # Grant access to anyone
617
- self.bucket.grant_public_access()
607
+ self._bucket.grant_public_access()
618
608
 
619
609
  # Temporary fix for:
620
610
  # https://github.com/aws/aws-cdk/issues/25358
621
- s3_resource = self.bucket.node.default_child
611
+ s3_resource = self._bucket.node.default_child
622
612
  s3_resource.add_override(
623
613
  'Properties.PublicAccessBlockConfiguration.BlockPublicPolicy',
624
614
  'False',
625
615
  )
626
616
 
627
- self.bucket.add_cors_rule(
617
+ self._bucket.add_cors_rule(
628
618
  allowed_methods=[
629
619
  _s3.HttpMethods.GET,
630
620
  _s3.HttpMethods.POST,
@@ -665,7 +655,7 @@ class Bucket(Construct):
665
655
  ]
666
656
 
667
657
  # Only allow access from Cloudflare IPs
668
- self.bucket.add_to_resource_policy(
658
+ self._bucket.add_to_resource_policy(
669
659
  _iam.PolicyStatement(
670
660
  effect=_iam.Effect.DENY,
671
661
  principals=[_iam.AnyPrincipal()],
@@ -678,7 +668,7 @@ class Bucket(Construct):
678
668
  },
679
669
  )
680
670
  )
681
- self.bucket.add_to_resource_policy(
671
+ self._bucket.add_to_resource_policy(
682
672
  _iam.PolicyStatement(
683
673
  effect=_iam.Effect.ALLOW,
684
674
  principals=[_iam.AnyPrincipal()],
@@ -695,7 +685,7 @@ class Bucket(Construct):
695
685
  # If the CORS configuration is applied twice the following error will be raised
696
686
  # "Properties validation failed for resource XYZBucket with message: #/CorsConfiguration/CorsRules: array items are not unique"
697
687
  if not public_read_access:
698
- self.bucket.add_cors_rule(
688
+ self._bucket.add_cors_rule(
699
689
  allowed_methods=[
700
690
  _s3.HttpMethods.GET,
701
691
  _s3.HttpMethods.POST,
@@ -729,7 +719,7 @@ class Bucket(Construct):
729
719
  self,
730
720
  'Distribution',
731
721
  authorization=authorization,
732
- origin=origins.S3Origin(self.bucket),
722
+ origin=origins.S3Origin(self._bucket),
733
723
  domain_names=[bucket_name],
734
724
  )
735
725
 
@@ -485,6 +485,7 @@ class Microservice(Construct):
485
485
  network_load_balancer_source_autoscaling_group: aws_cdk.aws_autoscaling.AutoScalingGroup = None,
486
486
  stickiness_cookie_duration_in_hours: str = None,
487
487
  load_balancer_idle_timeout_in_seconds: str = None,
488
+ load_balancer_name_postfix: str = '',
488
489
  rubrik_backup: str = 'True',
489
490
  efs_backup: str = 'True',
490
491
  dns_record: str = None,
@@ -784,7 +785,15 @@ class Microservice(Construct):
784
785
  network_load_balancer_subnet_2=network_load_balancer_subnet_2,
785
786
  ec2_traffic_port=ec2_traffic_port,
786
787
  load_balancer_name='-'.join(
787
- [app_name, main_component_name, 'nlb']
788
+ filter(
789
+ None,
790
+ [
791
+ app_name,
792
+ main_component_name,
793
+ 'nlb',
794
+ load_balancer_name_postfix,
795
+ ],
796
+ )
788
797
  ),
789
798
  dns_record=dns_record,
790
799
  create_dns=create_dns,
@@ -801,7 +810,15 @@ class Microservice(Construct):
801
810
  environments_parameters=environments_parameters,
802
811
  internet_facing=is_public,
803
812
  load_balancer_name='-'.join(
804
- [app_name, main_component_name, 'alb']
813
+ filter(
814
+ None,
815
+ [
816
+ app_name,
817
+ main_component_name,
818
+ 'alb',
819
+ load_balancer_name_postfix,
820
+ ],
821
+ )
805
822
  ),
806
823
  use_cdn=use_cdn,
807
824
  will_implement_cdn=will_implement_cdn,
@@ -826,9 +843,8 @@ class Microservice(Construct):
826
843
  client_secret=client_secret,
827
844
  user_info_endpoint=user_info_endpoint,
828
845
  upstream_security_group=upstream_security_group,
829
- allow_ingress_from_everyone=True
830
- if allow_ingress_from_everyone.lower() == 'true'
831
- else False,
846
+ allow_ingress_from_everyone=allow_ingress_from_everyone.lower()
847
+ == 'true',
832
848
  )
833
849
  self.alb = alb.alb
834
850
  self.alb_construct = alb
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aws-cdk-constructs
3
- Version: 2.26.3
3
+ Version: 2.28.0
4
4
  Summary: AWS CDK constructs
5
5
  Home-page: https://bitbucket.org/cioapps/aws-cdk-constructs
6
6
  Author: author
@@ -1 +0,0 @@
1
- from .api import API
@@ -1,82 +0,0 @@
1
- import aws_cdk as cdk
2
- from constructs import Construct
3
- from aws_cdk import aws_apigateway as _apigateway
4
-
5
- from aws_cdk_constructs.utils import (
6
- normalize_environment_parameter,
7
- get_version,
8
- )
9
-
10
-
11
- class API(Construct):
12
- """
13
-
14
- The FAO CDK API Construct creates an AWS API Gateway REST API, providing a Swagger JSON file.
15
-
16
- Every resource created by the construct will be tagged according to the FAO AWS tagging strategy described at https://aws.fao.org
17
-
18
- Args:
19
-
20
- id (str): the logical id of the newly created resource
21
-
22
- app_name (str): The application name. This will be used to generate the 'ApplicationName' tag for CSI compliancy. The ID of the application. This must be unique for each system, as it will be used to calculate the AWS costs of the system
23
-
24
- environment (str): Specify the environment in which you want to deploy you system. Allowed values: Development, QA, Production, SharedServices
25
-
26
- environments_parameters (dict): The dictionary containing the references to CSI AWS environments. This will simplify the environment promotions and enable a parametric development of the infrastructures.
27
-
28
- swagger_path (str): The path to the Swagger file (or OpenAPI compatibile) to use to auto-generate API Gateway
29
-
30
- """
31
-
32
- def __init__(
33
- self,
34
- scope: Construct,
35
- id: str,
36
- app_name: str,
37
- environment: str,
38
- environments_parameters: dict,
39
- swagger_path: str = None,
40
- **kwargs
41
- ) -> None:
42
- super().__init__(scope, id, **kwargs)
43
- environment = normalize_environment_parameter(environment)
44
-
45
- # Apply mandatory tags
46
- cdk.Tags.of(self).add('ApplicationName', app_name.lower().strip())
47
- cdk.Tags.of(self).add('Environment', environment)
48
-
49
- # Apply FAO CDK tags
50
- cdk.Tags.of(self).add('fao-cdk-construct', 'api')
51
- cdk.Tags.of(cdk.Stack.of(self)).add('fao-cdk-version', get_version())
52
- cdk.Tags.of(cdk.Stack.of(self)).add('fao-cdk', 'true')
53
-
54
- # Declare variables
55
- self.api = None
56
-
57
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create conditions
58
- swagger_path = swagger_path.strip()
59
- swagger_was_provided = swagger_path
60
-
61
- environment = environment.lower()
62
- aws_account = environments_parameters['accounts'][environment]
63
-
64
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Conditionally create resources
65
-
66
- if swagger_was_provided:
67
- # Read the base user data from file
68
- with open(swagger_path) as swagger_content:
69
- pws_swagger = swagger_content.read()
70
- swagger_content.close()
71
-
72
- api = _apigateway.CfnRestApi(
73
- self,
74
- app_name + '-api',
75
- body=None,
76
- body_s3_location=_apigateway.CfnRestApi.S3LocationProperty(
77
- bucket=aws_account['s3_config_bucket'],
78
- key=app_name + '/' + environment + '/swagger.json',
79
- ),
80
- description=app_name + '/' + environment + ' API',
81
- name=app_name + '/' + environment,
82
- )