Skip to content

[Lambda] Add open port support #5124

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

Merged
merged 11 commits into from
Apr 6, 2025
Merged

Conversation

Michaelvll
Copy link
Collaborator

Tested (run the relevant ones):

  • Code formatting: install pre-commit (auto-check on commit) or bash format.sh
  • Any manual or new tests for this PR (please specify below)
  • All smoke tests: /smoke-test (CI) or pytest tests/test_smoke.py (local)
  • Relevant individual tests: /smoke-test -k test_name (CI) or pytest tests/test_smoke.py::test_name (local)
  • Backward compatibility: /quicktest-core (CI) or pytest tests/smoke_tests/test_backward_compat.py (local)

@Michaelvll
Copy link
Collaborator Author

/smoke-test --lambda -k test_lambda_cloud_open_ports

@Michaelvll Michaelvll mentioned this pull request Apr 6, 2025
5 tasks
Copy link
Collaborator

@romilbhardwaj romilbhardwaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, thanks @Michaelvll!

Comment on lines 295 to 296
lambda_client.create_firewall_rule(port_range=[port, port],
protocol='tcp')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lambda API docs say: Firewall rules do not apply to the us-south-1 region

Do we know what's the behavior in SkyPilot if we try to open instances on an instance in us-south-1? E.g., is it silently ignored with the warning in the except below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Added the skip.

Comment on lines +306 to +307
Lambda Cloud firewall rules are global to the account, not cluster-specific.
We skip cleanup because rules may be used by other clusters.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we'll accumulate rules over time?

This may be ok for now, but we should leave a TODO here. Perhaps in the future we can store the instances using the firewall rule in the "description" field of a firewall rule

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a TODO. Yes, it is a bit challenging, as users may also implicitly rely on some of the firewall rules, as it is global.

Comment on lines 292 to 293
for port in ports_to_open:
logger.info(f'Opening port {port}/tcp')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful to have smarter logic here to consolidate contiguous ports numbers into a single firewall rule? E.g., if. ports_to_open is 8000-8100, we should probably create one rule with the range instead of creating 100 rules.

Ok to leave as a TODO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Fixed. Thanks!

Copy link
Collaborator Author

@Michaelvll Michaelvll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @romilbhardwaj! Addressed the comments. PTAL

Comment on lines 292 to 293
for port in ports_to_open:
logger.info(f'Opening port {port}/tcp')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Fixed. Thanks!

Comment on lines 295 to 296
lambda_client.create_firewall_rule(port_range=[port, port],
protocol='tcp')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Added the skip.

Comment on lines +306 to +307
Lambda Cloud firewall rules are global to the account, not cluster-specific.
We skip cleanup because rules may be used by other clusters.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a TODO. Yes, it is a bit challenging, as users may also implicitly rely on some of the firewall rules, as it is global.

Copy link
Collaborator

@romilbhardwaj romilbhardwaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Michaelvll!

Comment on lines +964 to +969
lambda_utils._try_request_with_backoff(
'put',
f'{lambda_utils.API_ENDPOINT}/firewall-rules',
data=data,
headers=lambda_client.headers,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side comment: wow Lambda really needs to add a DELETE function instead of clients needing to fetch and update all rules...

@Michaelvll Michaelvll enabled auto-merge (squash) April 6, 2025 18:10
@Michaelvll Michaelvll merged commit 5e94cce into master Apr 6, 2025
20 checks passed
@Michaelvll Michaelvll deleted the support-expose-port-for-lambda branch April 6, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants