apx-aws-lambda 1.2.1__tar.gz → 1.2.2__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 (29) hide show
  1. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/PKG-INFO +1 -1
  2. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/lambda_.py +61 -19
  3. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda.egg-info/PKG-INFO +1 -1
  4. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/pyproject.toml +1 -1
  5. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/tests/test_targets.py +71 -2
  6. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/LICENSE +0 -0
  7. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/README.md +0 -0
  8. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/__init__.py +0 -0
  9. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/cli.py +0 -0
  10. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/connect/template.yaml +0 -0
  11. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/cookiecutter.json +0 -0
  12. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/hooks/post_gen_project.py +0 -0
  13. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +0 -0
  14. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/DEPLOY.md +0 -0
  15. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/Makefile +0 -0
  16. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/policy.json +0 -0
  17. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/trust.json +0 -0
  18. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/samconfig.toml +0 -0
  19. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/template.yaml +0 -0
  20. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/overlays/index.json +0 -0
  21. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/plugin.py +0 -0
  22. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/shell.py +0 -0
  23. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda/tools.py +0 -0
  24. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda.egg-info/SOURCES.txt +0 -0
  25. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda.egg-info/dependency_links.txt +0 -0
  26. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda.egg-info/entry_points.txt +0 -0
  27. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda.egg-info/requires.txt +0 -0
  28. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/apx_aws_lambda.egg-info/top_level.txt +0 -0
  29. {apx_aws_lambda-1.2.1 → apx_aws_lambda-1.2.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apx-aws-lambda
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Summary: AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions.
5
5
  Author-email: Action Platform <cloud@actionplatform.io>
6
6
  License-Expression: Apache-2.0
@@ -257,10 +257,13 @@ class LambdaTarget(DeployTarget):
257
257
 
258
258
  return checks
259
259
 
260
- def _boundary_parameter(self, ctx: Context) -> Check:
260
+ def _takes_boundary(self, ctx: Context) -> bool:
261
261
  text = (ctx.repo_root / "template.yaml").read_text(errors="replace")
262
262
 
263
- if "PermissionsBoundaryArn" in text and "RolePath" in text:
263
+ return "PermissionsBoundaryArn" in text and "RolePath" in text
264
+
265
+ def _boundary_parameter(self, ctx: Context) -> Check:
266
+ if self._takes_boundary(ctx):
264
267
  return Check(
265
268
  "template.boundary", True, "the execution role takes the boundary"
266
269
  )
@@ -441,28 +444,67 @@ class LambdaTarget(DeployTarget):
441
444
  logger.info("stack %s is %s: deleting it before the deploy", stack, status)
442
445
  region = self._region(ctx)
443
446
  env = self.env(ctx)
444
- shell.aws(
445
- "cloudformation",
446
- "delete-stack",
447
- "--stack-name",
448
- stack,
449
- region=region,
450
- env=env,
451
- )
452
- shell.aws(
453
- "cloudformation",
454
- "wait",
455
- "stack-delete-complete",
456
- "--stack-name",
457
- stack,
458
- region=region,
459
- env=env,
460
- )
447
+ self._delete_stack(stack, region, env)
448
+
449
+ if self._status(ctx) != "DELETE_FAILED":
450
+ return
451
+
452
+ stuck = [
453
+ row["LogicalResourceId"]
454
+ for row in shell.aws(
455
+ "cloudformation",
456
+ "describe-stack-resources",
457
+ "--stack-name",
458
+ stack,
459
+ region=region,
460
+ env=env,
461
+ ).get("StackResources", [])
462
+ if row.get("ResourceStatus") == "DELETE_FAILED"
463
+ ]
464
+ logger.info("stack %s kept %s: deleting it without them", stack, stuck)
465
+ self._delete_stack(stack, region, env, retain=stuck)
466
+
467
+ def _delete_stack(
468
+ self,
469
+ stack: str,
470
+ region: str | None,
471
+ env: dict[str, str] | None,
472
+ retain: list[str] | None = None,
473
+ ) -> None:
474
+ """Delete and wait; a delete that fails leaves the stack in DELETE_FAILED for the caller to look at."""
475
+ args = ["cloudformation", "delete-stack", "--stack-name", stack]
476
+
477
+ if retain:
478
+ args += ["--retain-resources", *retain]
479
+
480
+ shell.aws(*args, region=region, env=env)
481
+
482
+ try:
483
+ shell.aws(
484
+ "cloudformation",
485
+ "wait",
486
+ "stack-delete-complete",
487
+ "--stack-name",
488
+ stack,
489
+ region=region,
490
+ env=env,
491
+ )
492
+ except DeployError:
493
+ if retain:
494
+ raise
461
495
 
462
496
  def deploy(self, ctx: Context) -> DeployResult:
463
497
  sam = shell.require("sam", "pip install aws-sam-cli")
464
498
  stage = self._stage(ctx)
465
499
  env = self.env(ctx)
500
+
501
+ if (env or {}).get("AP_BOUNDARY") and not self._takes_boundary(ctx):
502
+ raise DeployError(
503
+ "template.yaml lacks the PermissionsBoundaryArn or RolePath parameter, so the execution role "
504
+ "would land outside what a connected account may create: apply the aws/lambda overlay again "
505
+ "(Configuration → Deploy target, or action-platform cloud set aws/lambda)"
506
+ )
507
+
466
508
  shell.run([*sam, "build"], cwd=ctx.repo_root, env=env)
467
509
  self._clear_failed_creation(ctx)
468
510
  args = [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apx-aws-lambda
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Summary: AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions.
5
5
  Author-email: Action Platform <cloud@actionplatform.io>
6
6
  License-Expression: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "apx-aws-lambda"
3
- version = "1.2.1"
3
+ version = "1.2.2"
4
4
  description = "AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions."
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -106,7 +106,7 @@ class LambdaTargetTest(unittest.TestCase):
106
106
  {
107
107
  "Stacks": [
108
108
  {
109
- "StackStatus": next(statuses),
109
+ "StackStatus": next(statuses, "UPDATE_COMPLETE"),
110
110
  "Outputs": [
111
111
  {"OutputKey": "ApiUrl", "OutputValue": "https://x"}
112
112
  ],
@@ -140,7 +140,14 @@ class LambdaTargetTest(unittest.TestCase):
140
140
 
141
141
  if " ".join(args[1:3]) == "cloudformation describe-stacks":
142
142
  return json.dumps(
143
- {"Stacks": [{"StackStatus": next(statuses), "Outputs": []}]}
143
+ {
144
+ "Stacks": [
145
+ {
146
+ "StackStatus": next(statuses, "UPDATE_COMPLETE"),
147
+ "Outputs": [],
148
+ }
149
+ ]
150
+ }
144
151
  )
145
152
 
146
153
  return "{}"
@@ -536,6 +543,68 @@ class ConnectedAccountTest(unittest.TestCase):
536
543
  )
537
544
  self.assertIn("connect/template.yaml", option.action_copy)
538
545
 
546
+ def test_a_deploy_with_an_old_overlay_stops_before_building(self):
547
+ (self.root / "template.yaml").write_text("Resources: {}\n")
548
+
549
+ with self.patched(), self.assertRaises(DeployError) as caught:
550
+ LambdaTarget().deploy(self.ctx())
551
+
552
+ self.assertIn("overlay again", str(caught.exception))
553
+ self.assertNotIn(["sam", "build"], [c[:2] for c in self.calls])
554
+
555
+ def test_a_failed_creation_whose_delete_fails_is_deleted_keeping_the_stuck_role(
556
+ self,
557
+ ):
558
+ statuses = iter(["ROLLBACK_FAILED", "DELETE_FAILED", "UPDATE_COMPLETE"])
559
+
560
+ def run(args, cwd=None, env=None):
561
+ key = " ".join(args[1:3])
562
+
563
+ if key == "cloudformation describe-stacks":
564
+ self.calls.append([Path(args[0]).name, *args[1:]])
565
+ return json.dumps(
566
+ {"Stacks": [{"StackStatus": next(statuses, "UPDATE_COMPLETE")}]}
567
+ )
568
+
569
+ if key == "cloudformation describe-stack-resources":
570
+ self.calls.append([Path(args[0]).name, *args[1:]])
571
+ return json.dumps(
572
+ {
573
+ "StackResources": [
574
+ {
575
+ "LogicalResourceId": "ApiFunctionRole",
576
+ "ResourceStatus": "DELETE_FAILED",
577
+ },
578
+ {
579
+ "LogicalResourceId": "ApiLogGroup",
580
+ "ResourceStatus": "DELETE_COMPLETE",
581
+ },
582
+ ]
583
+ }
584
+ )
585
+
586
+ if key == "cloudformation wait" and not any(
587
+ "--retain-resources" in c for c in self.calls
588
+ ):
589
+ self.calls.append([Path(args[0]).name, *args[1:]])
590
+ raise DeployError("Waiter StackDeleteComplete failed")
591
+
592
+ return self.run_fake(args, cwd, env)
593
+
594
+ with mock.patch.multiple(
595
+ shell, run=run, require=lambda t, h: [f"/usr/bin/{t}"]
596
+ ):
597
+ LambdaTarget().deploy(self.ctx())
598
+
599
+ deletes = [
600
+ c for c in self.calls if c[1:3] == ["cloudformation", "delete-stack"]
601
+ ]
602
+ self.assertEqual(len(deletes), 2)
603
+ self.assertEqual(
604
+ deletes[1][deletes[1].index("--retain-resources") + 1], "ApiFunctionRole"
605
+ )
606
+ self.assertNotIn("ApiLogGroup", deletes[1])
607
+
539
608
  def test_a_role_of_the_repository_wins_over_the_connected_account(self):
540
609
  target = LambdaTarget(role_arn="arn:aws:iam::1:role/own")
541
610
 
File without changes
File without changes
File without changes