Skip to content

Commit 901f531

Browse files
authored
fix: handel update stack error (#42)
* fix: handel update stack error * fix: handel error to codebuild
1 parent a5c9a7d commit 901f531

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/emd/cfn/codepipeline/template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Resources:
5050
- cloudformation:DescribeStacks
5151
- cloudformation:CreateStack
5252
- cloudformation:DeleteStack
53+
- cloudformation:UpdateStack
5354
- ec2:*
5455
- ecs:*
5556
- iam:CreateRole

src/emd/cfn/ecs/post_build.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import argparse
6+
import sys
67
from emd.models.utils.serialize_utils import load_extra_params
78

89
# Post build script for ECS, it will deploy the VPC and ECS cluster.
@@ -26,10 +27,10 @@ def wait_for_stack_completion(client, stack_name):
2627
print(f"Stack {stack_name} deployment complete")
2728
break
2829
else:
29-
raise Exception(
30+
print(
3031
f"Post build stage failed. The stack {stack_name} is in an unexpected status: {stack_status}. Please visit the AWS CloudFormation Console to delete the stack."
3132
)
32-
33+
sys.exit(1)
3334

3435
def get_stack_outputs(client, stack_name):
3536
response = client.describe_stacks(StackName=stack_name)
@@ -47,12 +48,15 @@ def create_or_update_stack(client, stack_name, template_path, parameters=[]):
4748
with open(template_path, "r") as template_file:
4849
template_body = template_file.read()
4950

50-
response = client.update_stack(
51-
StackName=stack_name,
52-
TemplateBody=template_body,
53-
Capabilities=["CAPABILITY_NAMED_IAM"],
54-
Parameters=parameters
55-
)
51+
try:
52+
response = client.update_stack(
53+
StackName=stack_name,
54+
TemplateBody=template_body,
55+
Capabilities=["CAPABILITY_NAMED_IAM"],
56+
Parameters=parameters
57+
)
58+
except Exception as e:
59+
print(f"No updates are to be performed for stack {stack_name}.")
5660

5761
print(f"Started update of stack {stack_name}")
5862
wait_for_stack_completion(client, stack_name)
@@ -75,9 +79,10 @@ def create_or_update_stack(client, stack_name, template_path, parameters=[]):
7579
print(f"Started deployment of stack {stack_name} with ID {stack_id}")
7680
wait_for_stack_completion(client, stack_name)
7781
else:
78-
raise Exception(
82+
print(
7983
f"Post build stage failed. The stack {stack_name} is in an unexpected status: {stack_status}. Please visit the AWS CloudFormation Console to delete the stack."
8084
)
85+
sys.exit(1)
8186

8287

8388
def update_parameters_file(parameters_path, updates):

0 commit comments

Comments
 (0)