Skip to content

Commit

Permalink
[AWS] Fix image not found when checking image size (#3216)
Browse files Browse the repository at this point in the history
* [AWS] Fix image not found when checking image size

* format
  • Loading branch information
Michaelvll authored Feb 22, 2024
1 parent 9d05415 commit 4579bcd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions sky/clouds/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,17 @@ def get_image_size(cls, image_id: str, region: Optional[str]) -> float:
return DEFAULT_AMI_GB
assert region is not None, (image_id, region)
client = aws.client('ec2', region_name=region)
image_not_found_message = (
f'Image {image_id!r} not found in AWS region {region}.\n'
f'\nTo find AWS AMI IDs: https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html#examples\n' # pylint: disable=line-too-long
'Example: ami-0729d913a335efca7')
try:
image_info = client.describe_images(ImageIds=[image_id])
image_info = image_info['Images'][0]
image_info = image_info.get('Images', [])
if not image_info:
with ux_utils.print_exception_no_traceback():
raise ValueError(image_not_found_message)
image_info = image_info[0]
image_size = image_info['BlockDeviceMappings'][0]['Ebs'][
'VolumeSize']
except aws.botocore_exceptions().NoCredentialsError:
Expand All @@ -269,10 +277,7 @@ def get_image_size(cls, image_id: str, region: Optional[str]) -> float:
return DEFAULT_AMI_GB
except aws.botocore_exceptions().ClientError:
with ux_utils.print_exception_no_traceback():
raise ValueError(
f'Image {image_id!r} not found in AWS region {region}.\n'
f'\nTo find AWS AMI IDs: https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html#examples\n' # pylint: disable=line-too-long
'Example: ami-0729d913a335efca7') from None
raise ValueError(image_not_found_message) from None
return image_size

@classmethod
Expand Down

0 comments on commit 4579bcd

Please sign in to comment.