Handle error when the template cannot be found

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2022-10-31 18:00:53 +00:00 committed by Megan Wilhite
parent 077f2f350e
commit 6c2b4dc1e5

View file

@ -472,9 +472,15 @@ class VM:
# Grab the public subnet of the vpc used on the template
client = boto3.client("ec2", region_name=self.region_name)
data = client.describe_launch_template_versions(
LaunchTemplateName=LAUNCH_TEMPLATE_NAME_FMT.format(self.config.ami)
)
try:
data = client.describe_launch_template_versions(
LaunchTemplateName=LAUNCH_TEMPLATE_NAME_FMT.format(self.config.ami)
)
except ClientError as exc:
if "InvalidLaunchTemplateName.NotFoundException" not in str(exc):
raise
self.ctx.error(f"Could not find a launch template for {self.name!r}")
self.ctx.exit(1)
# The newest template comes first
template_data = data["LaunchTemplateVersions"][0]["LaunchTemplateData"]
subnet_id = template_data["NetworkInterfaces"][0]["SubnetId"]