Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AWS] Adding filter for default aws vpc if not specified #4546

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/cloud-setup/cloud-permissions/aws.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ IAM Role Creation

Using a specific VPC
-----------------------
By default, SkyPilot uses the "default" VPC in each region.
By default, SkyPilot uses the "default" VPC in each region. If a region does not have a `default VPC <https://docs.aws.amazon.com/vpc/latest/userguide/work-with-default-vpc.html#create-default-vpc>`_, SkyPilot will not be able to use the region.

To instruct SkyPilot to use a specific VPC, you can use SkyPilot's global config
file ``~/.sky/config.yaml`` to specify the VPC name in the ``aws.vpc_name``
Expand Down
14 changes: 11 additions & 3 deletions sky/provision/aws/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,13 @@ def _get_pruned_subnets(current_subnets: List[Any]) -> Set[str]:
raise exc

if not subnets:
vpc_msg = (f'Does a default VPC exist in region '
f'{ec2.meta.client.meta.region_name}? ') if (
vpc_id_of_sg is None) else ''
_skypilot_log_error_and_exit_for_failover(
'No usable subnets found, try '
'manually creating an instance in your specified region to '
'populate the list of subnets and trying this again. '
f'No usable subnets found. {vpc_msg}'
'Try manually creating an instance in your specified region to '
'populate the list of subnets and try again. '
'Note that the subnet must map public IPs '
'on instance launch unless you set `use_internal_ips: true` in '
'the `provider` config.')
Expand Down Expand Up @@ -495,6 +498,11 @@ def _get_subnet_and_vpc_id(ec2, security_group_ids: Optional[List[str]],
vpc_id_of_sg = None

all_subnets = list(ec2.subnets.all())
# If no VPC is specified, use the default VPC.
# We filter only for default VPCs to avoid using subnets that users may
# not want SkyPilot to use.
if vpc_id_of_sg is None:
all_subnets = [s for s in all_subnets if s.vpc.is_default]
subnets, vpc_id = _usable_subnets(
ec2,
user_specified_subnets=None,
Expand Down
Loading