localstack-core 4.11.2.dev14__py3-none-any.whl → 4.12.1.dev18__py3-none-any.whl

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.

Potentially problematic release.


This version of localstack-core might be problematic. Click here for more details.

Files changed (77) hide show
  1. localstack/aws/api/ec2/__init__.py +13 -0
  2. localstack/aws/api/iam/__init__.py +1 -0
  3. localstack/aws/api/lambda_/__init__.py +616 -0
  4. localstack/aws/api/logs/__init__.py +188 -0
  5. localstack/aws/api/opensearch/__init__.py +11 -0
  6. localstack/aws/api/route53/__init__.py +3 -0
  7. localstack/aws/api/s3/__init__.py +2 -0
  8. localstack/aws/api/s3control/__init__.py +19 -0
  9. localstack/aws/api/secretsmanager/__init__.py +9 -0
  10. localstack/aws/connect.py +35 -15
  11. localstack/config.py +8 -0
  12. localstack/constants.py +3 -0
  13. localstack/dev/kubernetes/__main__.py +39 -14
  14. localstack/runtime/analytics.py +11 -0
  15. localstack/services/acm/provider.py +13 -1
  16. localstack/services/cloudformation/engine/v2/change_set_model.py +9 -0
  17. localstack/services/cloudformation/engine/v2/change_set_model_preproc.py +3 -1
  18. localstack/services/cloudformation/engine/v2/change_set_resource_support_checker.py +114 -0
  19. localstack/services/cloudformation/provider.py +26 -1
  20. localstack/services/cloudformation/provider_utils.py +20 -0
  21. localstack/services/cloudformation/resource_provider.py +5 -4
  22. localstack/services/cloudformation/scaffolding/__main__.py +94 -22
  23. localstack/services/cloudformation/v2/provider.py +41 -0
  24. localstack/services/kinesis/packages.py +1 -1
  25. localstack/services/kms/models.py +6 -2
  26. localstack/services/lambda_/analytics.py +11 -2
  27. localstack/services/lambda_/invocation/event_manager.py +15 -11
  28. localstack/services/lambda_/invocation/lambda_models.py +4 -0
  29. localstack/services/lambda_/invocation/lambda_service.py +11 -0
  30. localstack/services/lambda_/provider.py +70 -13
  31. localstack/services/opensearch/packages.py +34 -20
  32. localstack/services/route53/provider.py +7 -0
  33. localstack/services/route53resolver/provider.py +5 -0
  34. localstack/services/s3/constants.py +5 -0
  35. localstack/services/s3/exceptions.py +9 -0
  36. localstack/services/s3/models.py +9 -1
  37. localstack/services/s3/provider.py +25 -30
  38. localstack/services/s3/utils.py +46 -1
  39. localstack/services/s3control/provider.py +6 -0
  40. localstack/services/scheduler/provider.py +4 -2
  41. localstack/services/secretsmanager/provider.py +4 -0
  42. localstack/services/ses/provider.py +4 -0
  43. localstack/services/sns/constants.py +13 -0
  44. localstack/services/sns/provider.py +5 -0
  45. localstack/services/sns/v2/models.py +3 -0
  46. localstack/services/sns/v2/provider.py +100 -0
  47. localstack/services/sqs/constants.py +6 -0
  48. localstack/services/sqs/provider.py +9 -1
  49. localstack/services/sqs/resource_providers/aws_sqs_queue.py +61 -46
  50. localstack/services/ssm/provider.py +6 -0
  51. localstack/services/stepfunctions/asl/static_analyser/test_state/test_state_analyser.py +193 -107
  52. localstack/services/stepfunctions/backend/execution.py +4 -5
  53. localstack/services/stepfunctions/provider.py +21 -14
  54. localstack/services/sts/provider.py +7 -0
  55. localstack/services/support/provider.py +5 -1
  56. localstack/services/swf/provider.py +5 -1
  57. localstack/services/transcribe/provider.py +7 -0
  58. localstack/testing/aws/lambda_utils.py +1 -1
  59. localstack/testing/aws/util.py +2 -1
  60. localstack/testing/config.py +1 -0
  61. localstack/utils/aws/client_types.py +2 -4
  62. localstack/utils/bootstrap.py +2 -2
  63. localstack/utils/catalog/catalog.py +3 -2
  64. localstack/utils/container_utils/container_client.py +22 -13
  65. localstack/utils/container_utils/docker_cmd_client.py +6 -6
  66. localstack/version.py +2 -2
  67. {localstack_core-4.11.2.dev14.dist-info → localstack_core-4.12.1.dev18.dist-info}/METADATA +6 -6
  68. {localstack_core-4.11.2.dev14.dist-info → localstack_core-4.12.1.dev18.dist-info}/RECORD +76 -75
  69. localstack_core-4.12.1.dev18.dist-info/plux.json +1 -0
  70. localstack_core-4.11.2.dev14.dist-info/plux.json +0 -1
  71. {localstack_core-4.11.2.dev14.data → localstack_core-4.12.1.dev18.data}/scripts/localstack +0 -0
  72. {localstack_core-4.11.2.dev14.data → localstack_core-4.12.1.dev18.data}/scripts/localstack-supervisor +0 -0
  73. {localstack_core-4.11.2.dev14.data → localstack_core-4.12.1.dev18.data}/scripts/localstack.bat +0 -0
  74. {localstack_core-4.11.2.dev14.dist-info → localstack_core-4.12.1.dev18.dist-info}/WHEEL +0 -0
  75. {localstack_core-4.11.2.dev14.dist-info → localstack_core-4.12.1.dev18.dist-info}/entry_points.txt +0 -0
  76. {localstack_core-4.11.2.dev14.dist-info → localstack_core-4.12.1.dev18.dist-info}/licenses/LICENSE.txt +0 -0
  77. {localstack_core-4.11.2.dev14.dist-info → localstack_core-4.12.1.dev18.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,7 @@
1
1
  import dataclasses
2
2
  import os
3
+ import shlex
4
+ import subprocess as sp
3
5
  from typing import Literal
4
6
 
5
7
  import click
@@ -315,12 +317,11 @@ def generate_k8s_helm_overrides(
315
317
  return overrides
316
318
 
317
319
 
318
- def write_file(content: dict, output_path: str, file_name: str):
319
- path = os.path.join(output_path, file_name)
320
- with open(path, "w") as f:
320
+ def write_file(content: dict, output_path: str):
321
+ with open(output_path, "w") as f:
321
322
  f.write(yaml.dump(content))
322
323
  f.close()
323
- print(f"Generated file at {path}")
324
+ print(f"Generated file at {output_path}")
324
325
 
325
326
 
326
327
  def print_file(content: dict, file_name: str):
@@ -330,6 +331,22 @@ def print_file(content: dict, file_name: str):
330
331
  print("=====================================")
331
332
 
332
333
 
334
+ def generate_k3d_command(config_file_path: str) -> str:
335
+ return f"k3d cluster create --config {config_file_path}"
336
+
337
+
338
+ def generate_helm_command(overrides_file_path: str) -> str:
339
+ return f"helm upgrade --install localstack localstack/localstack -f {overrides_file_path}"
340
+
341
+
342
+ def execute_deployment(config_file_path: str, overrides_file_path: str):
343
+ """
344
+ Use the k3d and helm commands to create a cluster and deploy LocalStack in one command
345
+ """
346
+ sp.check_call(shlex.split(generate_k3d_command(config_file_path)))
347
+ sp.check_call(shlex.split(generate_helm_command(overrides_file_path)))
348
+
349
+
333
350
  @click.command("run")
334
351
  @click.option(
335
352
  "--pro", is_flag=True, default=None, help="Mount the localstack-pro code into the cluster."
@@ -386,6 +403,13 @@ def print_file(content: dict, file_name: str):
386
403
  help="DNS port to expose from the kubernetes node. It is applied only if --expose-dns is set.",
387
404
  type=click.IntRange(0, 65535),
388
405
  )
406
+ @click.option(
407
+ "--execute",
408
+ "-x",
409
+ is_flag=True,
410
+ default=False,
411
+ help="Execute deployment from generated config files. Implies -w/--write.",
412
+ )
389
413
  @click.argument("command", nargs=-1, required=False)
390
414
  def run(
391
415
  pro: bool = None,
@@ -400,6 +424,7 @@ def run(
400
424
  port: int = None,
401
425
  expose_dns: bool = False,
402
426
  dns_port: int = 53,
427
+ execute: bool = False,
403
428
  ):
404
429
  """
405
430
  A tool for localstack developers to generate the kubernetes cluster configuration file and the overrides to mount the localstack code into the cluster.
@@ -416,25 +441,25 @@ def run(
416
441
  overrides_file = overrides_file or "overrides.yml"
417
442
  config_file = config_file or "configuration.yml"
418
443
 
419
- if write:
420
- write_file(config, output_dir, config_file)
421
- write_file(overrides, output_dir, overrides_file)
444
+ overrides_file_path = os.path.join(output_dir, overrides_file)
445
+ config_file_path = os.path.join(output_dir, config_file)
446
+
447
+ if write or execute:
448
+ write_file(config, config_file_path)
449
+ write_file(overrides, overrides_file_path)
450
+ if execute:
451
+ execute_deployment(config_file, overrides_file)
422
452
  else:
423
453
  print_file(config, config_file)
424
454
  print_file(overrides, overrides_file)
425
455
 
426
- overrides_file_path = os.path.join(output_dir, overrides_file)
427
- config_file_path = os.path.join(output_dir, config_file)
428
-
429
456
  print("\nTo create a k3d cluster with the generated configuration, follow these steps:")
430
457
  print("1. Run the following command to create the cluster:")
431
- print(f"\n k3d cluster create --config {config_file_path}\n")
458
+ print(f"\n {generate_k3d_command(config_file_path)}\n")
432
459
 
433
460
  print("2. Once the cluster is created, start LocalStack with the generated overrides:")
434
461
  print("\n helm repo add localstack https://localstack.github.io/helm-charts # (if required)")
435
- print(
436
- f"\n helm upgrade --install localstack localstack/localstack -f {overrides_file_path}\n"
437
- )
462
+ print(f"\n {generate_helm_command(overrides_file_path)}\n")
438
463
 
439
464
 
440
465
  def main():
@@ -7,10 +7,14 @@ from localstack.utils.analytics import log
7
7
 
8
8
  LOG = logging.getLogger(__name__)
9
9
 
10
+ # Config options for which both usage and values are reported in analytics.
11
+ # Important: This list must only contain options whose values do not contain PII or sensitive data.
10
12
  TRACKED_ENV_VAR = [
11
13
  "ACTIVATE_PRO",
12
14
  "ALLOW_NONSTANDARD_REGIONS",
13
15
  "BEDROCK_PREWARM",
16
+ "CFN_IGNORE_UNSUPPORTED_TYPE_CREATE",
17
+ "CFN_IGNORE_UNSUPPORTED_TYPE_UPDATE",
14
18
  "CFN_IGNORE_UNSUPPORTED_RESOURCE_TYPES",
15
19
  "CLOUDFRONT_LAMBDA_EDGE",
16
20
  "CONTAINER_RUNTIME",
@@ -26,6 +30,7 @@ TRACKED_ENV_VAR = [
26
30
  "DYNAMODB_IN_MEMORY",
27
31
  "DYNAMODB_REMOVE_EXPIRED_ITEMS",
28
32
  "EAGER_SERVICE_LOADING",
33
+ "EC2_DOCKER_INIT",
29
34
  "EC2_VM_MANAGER",
30
35
  "ECS_TASK_EXECUTOR",
31
36
  "EDGE_PORT",
@@ -71,9 +76,15 @@ TRACKED_ENV_VAR = [
71
76
  "USE_SSL",
72
77
  ]
73
78
 
79
+ # Config options for which only the usage is reported in analytics.
80
+ # Use this for options which may hold sensitive data or PII.
74
81
  PRESENCE_ENV_VAR = [
75
82
  "DATA_DIR",
76
83
  "EDGE_FORWARD_URL", # Not functional; deprecated in 1.4.0, removed in 3.0.0
84
+ "EC2_HYPERVISOR_URI",
85
+ "EC2_REFERENCE_DOMAIN",
86
+ "EC2_LIBVIRT_NETWORK",
87
+ "EC2_LIBVIRT_POOL",
77
88
  "GATEWAY_LISTEN",
78
89
  "HOSTNAME",
79
90
  "HOSTNAME_EXTERNAL",
@@ -17,6 +17,16 @@ from localstack.utils.patch import patch
17
17
  moto_settings.ACM_VALIDATION_WAIT = min(10, moto_settings.ACM_VALIDATION_WAIT)
18
18
 
19
19
 
20
+ @patch(acm_models.AWSCertificateManagerBackend.list_certificates)
21
+ def list_certificates(list_certificates_orig, self, statuses, includes):
22
+ # Normalize keyTypes filter to match our describe() output format (hyphens)
23
+ if includes and "keyTypes" in includes:
24
+ includes["keyTypes"] = [
25
+ kt.replace("RSA_", "RSA-").replace("EC_", "EC-") for kt in includes["keyTypes"]
26
+ ]
27
+ return list_certificates_orig(self, statuses, includes)
28
+
29
+
20
30
  @patch(acm_models.CertBundle.describe)
21
31
  def describe(describe_orig, self):
22
32
  # TODO fix! Terrible hack (for parity). Moto adds certain required fields only if status is PENDING_VALIDATION.
@@ -71,8 +81,10 @@ def describe(describe_orig, self):
71
81
  cert[key] = value
72
82
  cert["Serial"] = str(cert.get("Serial") or "")
73
83
 
74
- if cert.get("KeyAlgorithm") in ["RSA_1024", "RSA_2048"]:
84
+ if cert.get("KeyAlgorithm") in ["RSA_1024", "RSA_2048", "RSA_3072", "RSA_4096"]:
75
85
  cert["KeyAlgorithm"] = cert["KeyAlgorithm"].replace("RSA_", "RSA-")
86
+ if cert.get("KeyAlgorithm") in ["EC_prime256v1", "EC_secp384r1", "EC_secp521r1"]:
87
+ cert["KeyAlgorithm"] = cert["KeyAlgorithm"].replace("EC_", "EC-")
76
88
 
77
89
  # add subject alternative names
78
90
  if cert["DomainName"] not in sans:
@@ -1169,6 +1169,15 @@ class ChangeSetModel:
1169
1169
  fn_transform,
1170
1170
  ],
1171
1171
  )
1172
+
1173
+ # special case of where either the before or after state does not specify properties but
1174
+ # the resource was in the previous template
1175
+ if (
1176
+ terminal_value_type.change_type == ChangeType.UNCHANGED
1177
+ and properties.change_type != ChangeType.UNCHANGED
1178
+ ):
1179
+ change_type = ChangeType.MODIFIED
1180
+
1172
1181
  requires_replacement = self._resolve_requires_replacement(
1173
1182
  node_properties=properties, resource_type=terminal_value_type
1174
1183
  )
@@ -1069,7 +1069,9 @@ class ChangeSetModelPreproc(ChangeSetModelVisitor):
1069
1069
 
1070
1070
  def _resolve_parameter_type(value: str, type_: str) -> Any:
1071
1071
  match type_:
1072
- case "List<String>" | "CommaDelimitedList":
1072
+ case s if re.match(r"List<[^>]+>", s):
1073
+ return [item.strip() for item in value.split(",")]
1074
+ case "CommaDelimitedList":
1073
1075
  return [item.strip() for item in value.split(",")]
1074
1076
  case "Number":
1075
1077
  # TODO: validate the parameter type at template parse time (or whatever is in parity with AWS) so we know this cannot fail
@@ -0,0 +1,114 @@
1
+ from localstack.services.cloudformation.engine.v2.change_set_model import (
2
+ NodeResource,
3
+ )
4
+ from localstack.services.cloudformation.engine.v2.change_set_model_visitor import (
5
+ ChangeSetModelVisitor,
6
+ )
7
+ from localstack.services.cloudformation.resources import AWS_AVAILABLE_CFN_RESOURCES
8
+ from localstack.utils.catalog.catalog import (
9
+ AwsServicesSupportStatus,
10
+ CatalogPlugin,
11
+ CfnResourceSupportStatus,
12
+ )
13
+ from localstack.utils.catalog.common import (
14
+ AwsServicesSupportInLatest,
15
+ AwsServiceSupportAtRuntime,
16
+ CloudFormationResourcesSupportAtRuntime,
17
+ CloudFormationResourcesSupportInLatest,
18
+ )
19
+ from localstack.utils.catalog.plugins import get_aws_catalog
20
+
21
+
22
+ # TODO handle all available resource types
23
+ def _get_service_name(resource_type: str) -> str | None:
24
+ parts = resource_type.split("::")
25
+ if len(parts) == 1:
26
+ return None
27
+
28
+ match parts:
29
+ case _ if "Cognito::IdentityPool" in resource_type:
30
+ return "cognito-identity"
31
+ case [*_, "Cognito", "UserPool"]:
32
+ return "cognito-idp"
33
+ case [*_, "Cognito", _]:
34
+ return "cognito-idp"
35
+ case [*_, "Elasticsearch", _]:
36
+ return "es"
37
+ case [*_, "OpenSearchService", _]:
38
+ return "opensearch"
39
+ case [*_, "KinesisFirehose", _]:
40
+ return "firehose"
41
+ case [*_, "ResourceGroups", _]:
42
+ return "resource-groups"
43
+ case [*_, "CertificateManager", _]:
44
+ return "acm"
45
+ case _ if "ElasticLoadBalancing::" in resource_type:
46
+ return "elb"
47
+ case _ if "ElasticLoadBalancingV2::" in resource_type:
48
+ return "elbv2"
49
+ case _ if "ApplicationAutoScaling::" in resource_type:
50
+ return "application-autoscaling"
51
+ case _ if "MSK::" in resource_type:
52
+ return "kafka"
53
+ case _ if "Timestream::" in resource_type:
54
+ return "timestream-write"
55
+ case [_, service, *_]:
56
+ return service.lower()
57
+
58
+
59
+ def _build_resource_failure_message(
60
+ resource_type: str, status: AwsServicesSupportStatus | CfnResourceSupportStatus
61
+ ) -> str:
62
+ service_name = _get_service_name(resource_type) or "malformed"
63
+ template = "Sorry, the {resource} resource in the {service} service is not supported."
64
+ match status:
65
+ case CloudFormationResourcesSupportAtRuntime.NOT_IMPLEMENTED:
66
+ template = "Sorry, the {resource} resource (from the {service} service) is not supported by this version of LocalStack, but is available in the latest version."
67
+ case CloudFormationResourcesSupportInLatest.NOT_SUPPORTED:
68
+ template = "Sorry, the {resource} resource (from the {service} service) is not currently supported by LocalStack."
69
+ case AwsServiceSupportAtRuntime.AVAILABLE_WITH_LICENSE_UPGRADE:
70
+ template = "Sorry, the {service} service (for the {resource} resource) is not included within your LocalStack license, but is available in an upgraded license."
71
+ case AwsServiceSupportAtRuntime.NOT_IMPLEMENTED:
72
+ template = "The API for service {service} (for the {resource} resource) is either not included in your current license plan or has not yet been emulated by LocalStack."
73
+ case AwsServicesSupportInLatest.NOT_SUPPORTED:
74
+ template = "Sorry, the {service} (for the {resource} resource) service is not currently supported by LocalStack."
75
+ case AwsServicesSupportInLatest.SUPPORTED_WITH_LICENSE_UPGRADE:
76
+ template = "Sorry, the {service} service (for the {resource} resource) is not supported by this version of LocalStack, but is available in the latest version if you upgrade to the latest stable version."
77
+ return template.format(
78
+ resource=resource_type,
79
+ service=service_name,
80
+ )
81
+
82
+
83
+ class ChangeSetResourceSupportChecker(ChangeSetModelVisitor):
84
+ catalog: CatalogPlugin
85
+
86
+ TITLE_MESSAGE = "Unsupported resources detected:"
87
+
88
+ def __init__(self):
89
+ self._resource_failure_messages: dict[str, str] = {}
90
+ self.catalog = get_aws_catalog()
91
+
92
+ def visit_node_resource(self, node_resource: NodeResource):
93
+ resource_type = node_resource.type_.value
94
+ if resource_type not in self._resource_failure_messages:
95
+ if resource_type not in AWS_AVAILABLE_CFN_RESOURCES:
96
+ # Ignore non-AWS resources
97
+ pass
98
+ support_status = self._resource_support_status(resource_type)
99
+ if support_status == CloudFormationResourcesSupportAtRuntime.AVAILABLE:
100
+ pass
101
+ else:
102
+ failure_message = _build_resource_failure_message(resource_type, support_status)
103
+ self._resource_failure_messages[resource_type] = failure_message
104
+ super().visit_node_resource(node_resource)
105
+
106
+ def _resource_support_status(
107
+ self, resource_type: str
108
+ ) -> AwsServicesSupportStatus | CfnResourceSupportStatus:
109
+ service_name = _get_service_name(resource_type)
110
+ return self.catalog.get_cloudformation_resource_status(resource_type, service_name, True)
111
+
112
+ @property
113
+ def failure_messages(self) -> list[str]:
114
+ return list(self._resource_failure_messages.values())
@@ -5,6 +5,7 @@ import re
5
5
  from collections import defaultdict
6
6
  from copy import deepcopy
7
7
 
8
+ from localstack import config
8
9
  from localstack.aws.api import CommonServiceException, RequestContext, handler
9
10
  from localstack.aws.api.cloudformation import (
10
11
  AlreadyExistsException,
@@ -120,6 +121,7 @@ from localstack.services.cloudformation.stores import (
120
121
  find_stack_by_id,
121
122
  get_cloudformation_store,
122
123
  )
124
+ from localstack.services.plugins import ServiceLifecycleHook
123
125
  from localstack.state import StateVisitor
124
126
  from localstack.utils.collections import (
125
127
  remove_attributes,
@@ -177,7 +179,30 @@ class InternalFailure(CommonServiceException):
177
179
  super().__init__("InternalFailure", status_code=500, message=message, sender_fault=False)
178
180
 
179
181
 
180
- class CloudformationProvider(CloudformationApi):
182
+ class CloudformationProvider(CloudformationApi, ServiceLifecycleHook):
183
+ def on_before_start(self):
184
+ self._validate_config()
185
+
186
+ def _validate_config(self):
187
+ no_wait_value: int = 5
188
+ try:
189
+ no_wait_value = int(config.CFN_NO_WAIT_ITERATIONS or 5)
190
+ except (TypeError, ValueError):
191
+ LOG.warning(
192
+ "You have set CFN_NO_WAIT_ITERATIONS to an invalid value: '%s'. It must be an integer greater or equal to 0. Using the default of 5",
193
+ config.CFN_NO_WAIT_ITERATIONS,
194
+ )
195
+
196
+ if no_wait_value < 0:
197
+ LOG.warning(
198
+ "You have set CFN_NO_WAIT_ITERATIONS to an invalid value: '%s'. It must be an integer greater or equal to 0. Using the default of 5",
199
+ config.CFN_NO_WAIT_ITERATIONS,
200
+ )
201
+ no_wait_value = 5
202
+
203
+ # Set the configuration back
204
+ config.CFN_NO_WAIT_ITERATIONS = no_wait_value
205
+
181
206
  def _stack_status_is_active(self, stack_status: str) -> bool:
182
207
  return stack_status not in [StackStatus.DELETE_COMPLETE]
183
208
 
@@ -275,6 +275,26 @@ def convert_values_to_numbers(input_dict: dict, keys_to_skip: list[str] | None =
275
275
  return recursive_convert(input_dict)
276
276
 
277
277
 
278
+ def resource_tags_to_remove_or_update(
279
+ prev_tags: list[dict], new_tags: list[dict]
280
+ ) -> tuple[list[str], dict[str, str]]:
281
+ """
282
+ When updating resources that have tags, we need to determine which tags to remove and which to add/update,
283
+ as these are typically done in separate API calls. The format of prev_tags and new_tags is expected to
284
+ be [{ "Key": tagName, "Value": tagValue }, ...]. The return value will be a tuple of (tags_to_remove, tags_to_update),
285
+ where:
286
+ - tags_to_remove is a list of tag keys that are present in prev_tags but not in new_tags.
287
+ - tags_to_update is a dict of tags to add or update, with the format: { tagName: tagValue, ... }.
288
+ """
289
+ prev_tag_keys = [tag["Key"] for tag in prev_tags]
290
+ new_tag_keys = [tag["Key"] for tag in new_tags]
291
+ tags_to_remove = list(set(prev_tag_keys) - set(new_tag_keys))
292
+
293
+ # convert from list of dicts, to a single dict because that's what tag_queue APIs expect.
294
+ tags_to_update = {tag["Key"]: tag["Value"] for tag in new_tags}
295
+ return (tags_to_remove, tags_to_update)
296
+
297
+
278
298
  # LocalStack specific utilities
279
299
  def get_schema_path(file_path: Path) -> dict:
280
300
  file_name_base = file_path.name.removesuffix(".py").removesuffix(".py.enc")
@@ -436,11 +436,11 @@ class ResourceProviderExecutor:
436
436
  resource: dict,
437
437
  raw_payload: ResourceProviderPayload,
438
438
  max_timeout: int = config.CFN_PER_RESOURCE_TIMEOUT,
439
- sleep_time: float = 5,
439
+ sleep_time: float = 1,
440
440
  ) -> ProgressEvent[Properties]:
441
441
  payload = copy.deepcopy(raw_payload)
442
442
 
443
- max_iterations = max(ceil(max_timeout / sleep_time), 2)
443
+ max_iterations = max(ceil(max_timeout / sleep_time), 10)
444
444
 
445
445
  for current_iteration in range(max_iterations):
446
446
  resource_type = get_resource_type({"Type": raw_payload["resourceType"]})
@@ -486,10 +486,11 @@ class ResourceProviderExecutor:
486
486
  payload["requestData"]["resourceProperties"] = event.resource_model
487
487
  resource["Properties"] = event.resource_model
488
488
 
489
- if current_iteration == 0:
490
- time.sleep(0)
489
+ if current_iteration < config.CFN_NO_WAIT_ITERATIONS:
490
+ pass
491
491
  else:
492
492
  time.sleep(sleep_time)
493
+
493
494
  case OperationStatus.PENDING:
494
495
  # come back to this resource in another iteration
495
496
  return event
@@ -10,6 +10,7 @@ from functools import reduce
10
10
  from pathlib import Path
11
11
  from typing import Any, Literal, TypedDict, TypeVar
12
12
 
13
+ import boto3
13
14
  import click
14
15
  from jinja2 import Environment, FileSystemLoader
15
16
  from yaml import safe_dump
@@ -140,14 +141,76 @@ class SchemaProvider:
140
141
  ) from e
141
142
 
142
143
 
144
+ class LiveSchemaProvider:
145
+ """
146
+ Provides CloudFormation resource schemas by fetching them from the live AWS CloudFormation service, rather than
147
+ a local zip file.
148
+ """
149
+
150
+ def __init__(self, cfn_client):
151
+ self.cfn_client = cfn_client
152
+
153
+ def available_schemas(self, pattern: str) -> list[str]:
154
+ """
155
+ Return the names of available CloudFormation resource types. `pattern` should be something like
156
+ AWS::S3::Bucket or AWS::S3::*, depending on whether you want all resources for a service or a specific one.
157
+ The result is a list of matching resource type names (e.g. [AWS::S3::Bucket, AWS::S3::Object, ...])
158
+ """
159
+
160
+ is_wildcard = pattern.endswith("*")
161
+ pattern = pattern[:-1] if is_wildcard else pattern
162
+ matching_names = []
163
+
164
+ params = {
165
+ "Visibility": "PUBLIC",
166
+ "Type": "RESOURCE",
167
+ "DeprecatedStatus": "LIVE",
168
+ "Filters": {"Category": "AWS_TYPES", "TypeNamePrefix": pattern},
169
+ }
170
+ next_token: str | None = None
171
+
172
+ # Note: pagination is necessary since list_types requires multiple calls even to get a single result.
173
+ while True:
174
+ if next_token:
175
+ params["NextToken"] = next_token
176
+ response = self.cfn_client.list_types(**params)
177
+
178
+ # collect any matching type names (if wildcard, all; else exact match only)
179
+ matching_names.extend(
180
+ [
181
+ type_summary["TypeName"]
182
+ for type_summary in response.get("TypeSummaries", [])
183
+ if (is_wildcard or type_summary["TypeName"] == pattern)
184
+ ]
185
+ )
186
+
187
+ next_token = response.get("NextToken")
188
+ if not next_token:
189
+ break
190
+
191
+ return matching_names
192
+
193
+ def schema(self, type_name: ResourceName) -> ResourceSchema:
194
+ """
195
+ Given a CloudFormation ResourceName (representing something like "AWS::S3::Bucket"), return the resource
196
+ schema as dict.
197
+ """
198
+ response = self.cfn_client.describe_type(
199
+ Type="RESOURCE",
200
+ TypeName=type_name.full_name,
201
+ )
202
+ schema_str = response.get("Schema")
203
+ if not schema_str:
204
+ raise click.ClickException(
205
+ f"Could not fetch schema for CloudFormation resource type: {type_name}"
206
+ )
207
+ return json.loads(schema_str)
208
+
209
+
143
210
  LOCALSTACK_ROOT_DIR = Path(__file__).parent.joinpath("../../../../..").resolve()
144
211
  LOCALSTACK_PRO_ROOT_DIR = LOCALSTACK_ROOT_DIR.joinpath("../localstack-pro").resolve()
145
- TESTS_ROOT_DIR = LOCALSTACK_ROOT_DIR.joinpath(
146
- "tests/aws/services/cloudformation/resource_providers"
147
- )
148
- TESTS_PRO_ROOT_DIR = LOCALSTACK_PRO_ROOT_DIR.joinpath(
149
- "localstack-pro-core/tests/aws/services/cloudformation/resource_providers"
150
- )
212
+ TESTS_ROOT_DIR = LOCALSTACK_ROOT_DIR.joinpath("tests/aws/services")
213
+ TESTS_PRO_ROOT_DIR = LOCALSTACK_PRO_ROOT_DIR.joinpath("localstack-pro-core/tests/aws/services")
151
214
 
152
215
  assert LOCALSTACK_ROOT_DIR.is_dir(), f"{LOCALSTACK_ROOT_DIR} does not exist"
153
216
  assert LOCALSTACK_PRO_ROOT_DIR.is_dir(), f"{LOCALSTACK_PRO_ROOT_DIR} does not exist"
@@ -193,7 +256,7 @@ def template_path(
193
256
  output_path = (
194
257
  tests_root_dir(pro)
195
258
  .joinpath(
196
- f"{resource_name.python_compatible_service_name.lower()}/{resource_name.path_compatible_full_name()}/templates/{stub}"
259
+ f"{resource_name.python_compatible_service_name.lower()}/resource_providers/templates/{stub}"
197
260
  )
198
261
  .resolve()
199
262
  )
@@ -202,7 +265,7 @@ def template_path(
202
265
  test_path = (
203
266
  root_dir(pro)
204
267
  .joinpath(
205
- f"tests/aws/cloudformation/resource_providers/{resource_name.python_compatible_service_name.lower()}/{resource_name.path_compatible_full_name()}"
268
+ f"tests/aws/{resource_name.python_compatible_service_name.lower()}/resource_providers/templates"
206
269
  )
207
270
  .resolve()
208
271
  )
@@ -276,7 +339,7 @@ class TemplateRenderer:
276
339
  # e.g. .../resource_providers/aws_iam_role/test_X.py vs. .../resource_providers/iam/test_X.py
277
340
  # add extra parameters
278
341
  tests_output_path = root_dir(self.pro).joinpath(
279
- f"tests/aws/cloudformation/resource_providers/{resource_name.python_compatible_service_name.lower()}/{resource_name.full_name.lower()}"
342
+ f"tests/aws/{resource_name.python_compatible_service_name.lower()}/resource_providers/templates"
280
343
  )
281
344
  match file_type:
282
345
  case FileType.getatt_test:
@@ -284,7 +347,9 @@ class TemplateRenderer:
284
347
  kwargs["service"] = resource_name.service.lower()
285
348
  kwargs["resource"] = resource_name.resource.lower()
286
349
  kwargs["template_path"] = str(
287
- template_path(resource_name, FileType.attribute_template, tests_output_path)
350
+ template_path(
351
+ resource_name, FileType.attribute_template, tests_output_path, pro=self.pro
352
+ )
288
353
  )
289
354
  case FileType.provider:
290
355
  property_ir = generate_ir_for_type(
@@ -318,17 +383,25 @@ class TemplateRenderer:
318
383
  kwargs["pro"] = self.pro
319
384
  case FileType.integration_test:
320
385
  kwargs["black_box_template_path"] = str(
321
- template_path(resource_name, FileType.minimal_template, tests_output_path)
386
+ template_path(
387
+ resource_name, FileType.minimal_template, tests_output_path, pro=self.pro
388
+ )
322
389
  )
323
390
  kwargs["update_template_path"] = str(
324
391
  template_path(
325
392
  resource_name,
326
393
  FileType.update_without_replacement_template,
327
394
  tests_output_path,
395
+ pro=self.pro,
328
396
  )
329
397
  )
330
398
  kwargs["autogenerated_template_path"] = str(
331
- template_path(resource_name, FileType.autogenerated_template, tests_output_path)
399
+ template_path(
400
+ resource_name,
401
+ FileType.autogenerated_template,
402
+ tests_output_path,
403
+ pro=self.pro,
404
+ )
332
405
  )
333
406
  # case FileType.cloudcontrol_test:
334
407
  case FileType.parity_test:
@@ -531,20 +604,24 @@ class FileWriter:
531
604
  ),
532
605
  FileType.integration_test: tests_root_dir(self.pro).joinpath(
533
606
  self.resource_name.python_compatible_service_name.lower(),
607
+ "resource_providers",
534
608
  self.resource_name.path_compatible_full_name(),
535
609
  "test_basic.py",
536
610
  ),
537
611
  FileType.getatt_test: tests_root_dir(self.pro).joinpath(
538
612
  self.resource_name.python_compatible_service_name.lower(),
613
+ "resource_providers",
539
614
  self.resource_name.path_compatible_full_name(),
540
615
  "test_exploration.py",
541
616
  ),
542
617
  # FileType.cloudcontrol_test: tests_root_dir(self.pro).joinpath(
543
618
  # self.resource_name.python_compatible_service_name.lower(),
619
+ # "resource_providers",
544
620
  # f"test_aws_{self.resource_name.service.lower()}_{self.resource_name.resource.lower()}_cloudcontrol.py",
545
621
  # ),
546
622
  FileType.parity_test: tests_root_dir(self.pro).joinpath(
547
623
  self.resource_name.python_compatible_service_name.lower(),
624
+ "resource_providers",
548
625
  self.resource_name.path_compatible_full_name(),
549
626
  "test_parity.py",
550
627
  ),
@@ -558,7 +635,9 @@ class FileWriter:
558
635
  FileType.autogenerated_template,
559
636
  ]
560
637
  for template_type in templates:
561
- self.destination_files[template_type] = template_path(self.resource_name, template_type)
638
+ self.destination_files[template_type] = template_path(
639
+ self.resource_name, template_type, pro=self.pro
640
+ )
562
641
 
563
642
  def write(self, file_type: FileType, contents: str):
564
643
  file_destination = self.destination_files[file_type]
@@ -763,21 +842,14 @@ def generate(
763
842
  console = Console()
764
843
  console.rule(title=resource_type)
765
844
 
766
- schema_provider = SchemaProvider(
767
- zipfile_path=Path(__file__).parent.joinpath("CloudformationSchema.zip")
768
- )
845
+ schema_provider = LiveSchemaProvider(boto3.client("cloudformation"))
769
846
 
770
847
  template_root = Path(__file__).parent.joinpath("templates")
771
848
  env = Environment(
772
849
  loader=FileSystemLoader(template_root),
773
850
  )
774
851
 
775
- parts = resource_type.rpartition("::")
776
- if parts[-1] == "*":
777
- # generate all resource types for that service
778
- matching_resources = [x for x in schema_provider.schemas.keys() if x.startswith(parts[0])]
779
- else:
780
- matching_resources = [resource_type]
852
+ matching_resources = schema_provider.available_schemas(resource_type)
781
853
 
782
854
  for matching_resource in matching_resources:
783
855
  console.rule(title=matching_resource)