localstack-core 4.13.2.dev83__py3-none-any.whl → 4.13.2.dev85__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.
@@ -56,7 +56,7 @@ from localstack.services.lambda_.invocation.lambda_models import (
56
56
  VersionAlias,
57
57
  VersionState,
58
58
  )
59
- from localstack.services.lambda_.invocation.models import lambda_stores
59
+ from localstack.services.lambda_.invocation.models import LambdaStore, lambda_stores
60
60
  from localstack.services.lambda_.invocation.version_manager import LambdaVersionManager
61
61
  from localstack.services.lambda_.lambda_utils import HINT_LOG
62
62
  from localstack.utils.archives import get_unzipped_size, is_zip_file
@@ -196,6 +196,66 @@ class LambdaService:
196
196
  def publish_version_async(self, function_version: FunctionVersion):
197
197
  self.task_executor.submit(self.publish_version, function_version)
198
198
 
199
+ def delete_function_version_async(
200
+ self, function: Function, version: FunctionVersion, qualifier: str
201
+ ):
202
+ """
203
+ Simulates async function cleanup after function deletion API is called
204
+ by introducing a small delay before actually removing the function from the store
205
+ to allow for getting the function details after deletion.
206
+ """
207
+
208
+ def _cleanup():
209
+ time.sleep(0.5)
210
+ function.versions.pop(qualifier, None)
211
+
212
+ new_state = VersionState(state=State.Deleting)
213
+ new_last_status = UpdateStatus(status=LastUpdateStatus.InProgress)
214
+ function.versions[version.id.qualifier] = dataclasses.replace(
215
+ version,
216
+ config=dataclasses.replace(
217
+ version.config, state=new_state, last_update=new_last_status
218
+ ),
219
+ )
220
+ destroy_code_if_not_used(code=version.config.code, function=function)
221
+
222
+ self.task_executor.submit(_cleanup)
223
+
224
+ def delete_function_async(self, store: LambdaStore, function_name: str):
225
+ """
226
+ Simulates async function version cleanup after function deletion API is called
227
+ by introducing a small delay before actually removing the function from the store
228
+ to allow for getting the function version details after deletion.
229
+ """
230
+
231
+ def _cleanup():
232
+ time.sleep(0.5)
233
+ store.functions.pop(function_name)
234
+
235
+ # set each version of the function to deleting state first, to allow for getting the function version details after deletion
236
+ function = store.functions.get(function_name)
237
+ if function:
238
+ for version in function.versions.values():
239
+ new_state = VersionState(state=State.Deleting)
240
+ new_last_status = UpdateStatus(status=LastUpdateStatus.InProgress)
241
+ previous_revision_id = version.config.revision_id
242
+
243
+ function.versions[version.id.qualifier] = dataclasses.replace(
244
+ version,
245
+ config=dataclasses.replace(
246
+ version.config, state=new_state, last_update=new_last_status
247
+ ),
248
+ )
249
+ # Seems the revision id doesn't change when deleting a function right after it has been created (even though state has changed)
250
+ # reassign revision id to avoid dataclass replace removing it, since it's init=False
251
+ object.__setattr__(
252
+ function.versions[version.id.qualifier].config,
253
+ "revision_id",
254
+ previous_revision_id,
255
+ )
256
+
257
+ self.task_executor.submit(_cleanup)
258
+
199
259
  def publish_version(self, function_version: FunctionVersion):
200
260
  """
201
261
  Synchronously create a function version (manager)
@@ -1638,10 +1638,14 @@ class LambdaProvider(LambdaApi, ServiceLifecycleHook):
1638
1638
  function_has_capacity_provider = False
1639
1639
  if qualifier:
1640
1640
  # delete a version of the function
1641
- version = function.versions.pop(qualifier, None)
1641
+ version = function.versions.get(qualifier, None)
1642
1642
  if version:
1643
1643
  if version.config.capacity_provider_config:
1644
1644
  function_has_capacity_provider = True
1645
+ # async delete from store
1646
+ self.lambda_service.delete_function_version_async(function, version, qualifier)
1647
+ else:
1648
+ function.versions.pop(qualifier, None)
1645
1649
  self.lambda_service.stop_version(version.id.qualified_arn())
1646
1650
  destroy_code_if_not_used(code=version.config.code, function=function)
1647
1651
  else:
@@ -1649,19 +1653,24 @@ class LambdaProvider(LambdaApi, ServiceLifecycleHook):
1649
1653
  self._remove_all_tags(unqualified_function_arn)
1650
1654
  # TODO: introduce locking for safe deletion: We could create a new version at the API layer before
1651
1655
  # the old version gets cleaned up in the internal lambda service.
1652
- function = store.functions.pop(function_name)
1656
+ function = store.functions.get(function_name)
1657
+ if function.latest().config.capacity_provider_config:
1658
+ function_has_capacity_provider = True
1659
+ # async delete version from store
1660
+ self.lambda_service.delete_function_async(store, function_name)
1661
+
1653
1662
  for version in function.versions.values():
1654
1663
  # Functions with a capacity provider do NOT have a version manager for $LATEST because only
1655
1664
  # published versions are invokable.
1656
- if version.config.capacity_provider_config:
1657
- function_has_capacity_provider = True
1658
- if version.id.qualifier == "$LATEST":
1659
- pass
1660
- else:
1665
+ if not function_has_capacity_provider or (
1666
+ function_has_capacity_provider and version.id.qualifier != "$LATEST"
1667
+ ):
1661
1668
  self.lambda_service.stop_version(qualified_arn=version.id.qualified_arn())
1662
1669
  # we can safely destroy the code here
1663
1670
  if version.config.code:
1664
1671
  version.config.code.destroy()
1672
+ if not function_has_capacity_provider:
1673
+ store.functions.pop(function_name, None)
1665
1674
 
1666
1675
  return DeleteFunctionResponse(StatusCode=202 if function_has_capacity_provider else 204)
1667
1676
 
localstack/version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '4.13.2.dev83'
32
- __version_tuple__ = version_tuple = (4, 13, 2, 'dev83')
31
+ __version__ = version = '4.13.2.dev85'
32
+ __version_tuple__ = version_tuple = (4, 13, 2, 'dev85')
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: localstack-core
3
- Version: 4.13.2.dev83
3
+ Version: 4.13.2.dev85
4
4
  Summary: The core library and runtime of LocalStack
5
5
  Author-email: LocalStack Contributors <info@localstack.cloud>
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ localstack/deprecations.py,sha256=-3IYgCd6LEC3PjO7hbr3Dg-p0PIS6phjmv1qZnj1uo0,15
4
4
  localstack/openapi.yaml,sha256=jFUzv-NKkJttxb8HRrmKiNYOmJD-zVfPxG3DDMrRwfg,30865
5
5
  localstack/plugins.py,sha256=BIJC9dlo0WbP7lLKkCiGtd_2q5oeqiHZohvoRTcejXM,2457
6
6
  localstack/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- localstack/version.py,sha256=Wh2wST4lvbLiLrWClry4ZT7ZUfcNTir8-ggYRtr9T2A,721
7
+ localstack/version.py,sha256=37sK7ObyQIWYPm3XoY-TIvlbwdWq6ZPujl4ORtPfzXw,721
8
8
  localstack/aws/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  localstack/aws/accounts.py,sha256=102zpGowOxo0S6UGMpfjw14QW7WCLVAGsnFK5xFMLoo,3043
10
10
  localstack/aws/app.py,sha256=n9bJCfJRuMz_gLGAH430c3bIQXgUXeWO5NPfcdL2MV8,5145
@@ -548,7 +548,7 @@ localstack/services/lambda_/ldm.py,sha256=a5EJ5BFQbImAOgCcLBY20R-wQPL0UuLqG5mNhn
548
548
  localstack/services/lambda_/networking.py,sha256=H9fq1aYThqXZkOi0fCoJrHI9rm19qgUVxFe3vYloN08,938
549
549
  localstack/services/lambda_/packages.py,sha256=z81Gm3FdyH6ml_iRmJLRKCxj9jFWR11BAI6rvoIXMrY,3976
550
550
  localstack/services/lambda_/plugins.py,sha256=eZsdzZqgEG9EZpd3W8TUdoydTpPXl6JBzJgDx_qeFUU,1275
551
- localstack/services/lambda_/provider.py,sha256=reDMdVrV-nbMgpCihmdtXxdeRKmYjyRMsCD0xRQ3MPA,206016
551
+ localstack/services/lambda_/provider.py,sha256=yUrhHJOjJHAXM8xH0CQgeQ5Lz3SHOGgdCHVQI-C1jOE,206542
552
552
  localstack/services/lambda_/provider_utils.py,sha256=T0f16GVXgB1LvUrR6Sy-hq3r3n1b-pPvGNfpim3nOVw,3176
553
553
  localstack/services/lambda_/runtimes.py,sha256=05pz5fPQyn3JyQOtMMhd-Z5SCO65TzqJI7UhDySInsA,9253
554
554
  localstack/services/lambda_/urlrouter.py,sha256=LNIXNbAKbGdkbfZsKCVrbdtkc0uZzqdYjLpF1jAoCIA,8960
@@ -582,7 +582,7 @@ localstack/services/lambda_/invocation/execution_environment.py,sha256=XYHdg80fi
582
582
  localstack/services/lambda_/invocation/executor_endpoint.py,sha256=v_tsvn4HqbjtO2vhYUq7TxVzb7zNgMF2snxntjgBqrk,11018
583
583
  localstack/services/lambda_/invocation/internal_sqs_queue.py,sha256=RFjaDcZkFmdCvjHgtAnUQcPQrjOkWSJyqB3vzDo-rq0,7321
584
584
  localstack/services/lambda_/invocation/lambda_models.py,sha256=Bbks7_AGK3Y4keCG3xGw8BPwcRzt7vck-DahrSIeK4k,20671
585
- localstack/services/lambda_/invocation/lambda_service.py,sha256=sRG-JV84SPIf4QLia3sETZO9eAdrIAWb1w-WpbYmKw8,34073
585
+ localstack/services/lambda_/invocation/lambda_service.py,sha256=qrIBZguMyu_t8xJ-4qSnhBKlyfgKzf-GXJGlhrKdKm4,36760
586
586
  localstack/services/lambda_/invocation/logs.py,sha256=TD2oSyKAizn5_KHbnav1Rh_hITKxLV8RSrHR7lYgOUM,3798
587
587
  localstack/services/lambda_/invocation/metrics.py,sha256=IOzQguI3v8xl47FP6jMZYL3g9k-NIZEkvldAImdXljQ,1134
588
588
  localstack/services/lambda_/invocation/models.py,sha256=Z-WcatCB5Scxsp30-h-9Rj4fAY3kPM0iGqmT_ZFMxpQ,1289
@@ -1311,10 +1311,10 @@ localstack/utils/server/tcp_proxy.py,sha256=y2NJAmvftTiAYsLU_8qe4W5LGqwUw21i90Pu
1311
1311
  localstack/utils/xray/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1312
1312
  localstack/utils/xray/trace_header.py,sha256=ahXk9eonq7LpeENwlqUEPj3jDOCiVRixhntQuxNor-Q,6209
1313
1313
  localstack/utils/xray/traceid.py,sha256=GKO-R2sMMjlrH2UaLPXlQlZ6flbE7ZKb6IZMtMu_M5U,1110
1314
- localstack_core-4.13.2.dev83.data/scripts/localstack-supervisor,sha256=nm1Il2d6ASyOB6Vo4CRHd90w7TK9FdRl9VPp0NN6hUk,6378
1315
- localstack_core-4.13.2.dev83.dist-info/licenses/LICENSE.txt,sha256=3PC-9Z69UsNARuQ980gNR_JsLx8uvMjdG6C7cc4LBYs,606
1316
- localstack_core-4.13.2.dev83.dist-info/METADATA,sha256=5qhV1XKYZWzrA2zthNhKDs1If3brCNUujI7rL73HV6Y,5867
1317
- localstack_core-4.13.2.dev83.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
1318
- localstack_core-4.13.2.dev83.dist-info/entry_points.txt,sha256=59aAnn8KVHWAHkMg2dOgmgYtRZ-xTX9T4UiIchWgK6k,20975
1319
- localstack_core-4.13.2.dev83.dist-info/top_level.txt,sha256=3sqmK2lGac8nCy8nwsbS5SpIY_izmtWtgaTFKHYVHbI,11
1320
- localstack_core-4.13.2.dev83.dist-info/RECORD,,
1314
+ localstack_core-4.13.2.dev85.data/scripts/localstack-supervisor,sha256=nm1Il2d6ASyOB6Vo4CRHd90w7TK9FdRl9VPp0NN6hUk,6378
1315
+ localstack_core-4.13.2.dev85.dist-info/licenses/LICENSE.txt,sha256=3PC-9Z69UsNARuQ980gNR_JsLx8uvMjdG6C7cc4LBYs,606
1316
+ localstack_core-4.13.2.dev85.dist-info/METADATA,sha256=v3kOAsbaeK_tn3cb68dnj0_mJZ6hyhDPHA6KETYs1go,5867
1317
+ localstack_core-4.13.2.dev85.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
1318
+ localstack_core-4.13.2.dev85.dist-info/entry_points.txt,sha256=59aAnn8KVHWAHkMg2dOgmgYtRZ-xTX9T4UiIchWgK6k,20975
1319
+ localstack_core-4.13.2.dev85.dist-info/top_level.txt,sha256=3sqmK2lGac8nCy8nwsbS5SpIY_izmtWtgaTFKHYVHbI,11
1320
+ localstack_core-4.13.2.dev85.dist-info/RECORD,,