8000 Lambda: Fix behaviour for alias update and delete operations by anisaoshafi · Pull Request #11878 · localstack/localstack · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Lambda: Fix behaviour for alias update and delete operations #11878

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 2 commits into from
Nov 25, 2024

Conversation

anisaoshafi
Copy link
Contributor

Motivation

As reported in #11832:

  • For Lambda alias operations: update_alias and delete_alias, a generic ValueError was thrown which was not in sync with the AWS behavior.
  • For delete_function_url_config with no qualifier, the AWS behavior on the alias fnxs deletion was not clear.

It seems:

  • AWS doesn't throw an error for delete_alias for non-existing alias (but a 204 🤷🏼).
  • AWS throws ResourceNotFoundException( f"Alias not found: {fn_arn}:{name}", Type="User") when updating an alias that doesn't exist (not a ValueError).
  • For delete_function_url_config, AWS doesn't delete the function url configs of all aliases, when not specifying the Qualifier.

Changes

  • Removed ValueError for delete_alias when alias doesn't exist.
  • Changed ValueError in favor of ResourceNotFoundException for update_alias when alias doesn't exist.
  • Added tests for test_non_existent_alias_deletion and test_non_existent_alias_update
  • Added a test test_url_config_deletion_without_qualifier that shows the behaviour on the alias fnxs deletion (doesn't delete the function url configs of all aliases when qualifier not specified)

Let me know if I missed something, or if I messed up 🙏🏼

@localstack-bot
Copy link
Collaborator
localstack-bot commented Nov 19, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Collaborator
@localstack-bot localstack-bot left a comment

Choose a reason for hiding this comment

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

Welcome to LocalStack! Thanks for raising your first Pull Request and landing in your contributions. Our team will reach out with any reviews or feedbacks that we have shortly. We recommend joining our Slack Community and share your PR on the #community channel to share your contributions with us. Please make sure you are following our contributing guidelines and our Code of Conduct.

@anisaoshafi
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@anisaoshafi
Copy link
Contributor Author

recheck

localstack-bot added a commit that referenced this pull request Nov 19, 2024
@dfangl dfangl self-assigned this Nov 20, 2024
@dfangl dfangl added the semver: patch Non-breaking changes which can be included in patch releases label Nov 20, 2024
Copy link
Member
@dfangl dfangl 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 a great first iteration, thank you! I just have some minor comments and questions. Also, it would be nice to add a quick docstring for every new test which describes the scenario being tested, one line is sufficient. (We try to do that for new tests, although as you see, it is not consistent across the codebase).

@@ -1818,8 +1816,12 @@ def update_alias(
function = self._get_function(
function_name=function_name, region=region, account_id=account_id
)
fn_arn = api_utils.unqualified_lambda_arn(function_name, account_id, region)
Copy link
Member

Choose a reason for hiding this comment

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

There is a utility qualified_lambda_arn as well, where you can specify the alias name as qualifier directly, to avoid manually appending :{name}. Also, we only need to calculate this value in the if block, could you move it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree, I focused to much on making it work and didn't place it in the right place. Done.

Comment on lines 590 to 592
"tests/aws/services/lambda_/test_lambda_api.py::TestLambdaUrl::test_function_url_config_deletion_without_qualifier": {
"last_validated_date": "2024-11-19T17:37:22+00:00"
},
Copy link
Member

Choose a reason for hiding this comment

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

It seems you renamed the test at some point, which leads to these leftovers. Can you (just manually) delete that entry, to keep the validation file tidier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it.

self, create_lambda_function_aws, lambda_su_role, snapshot, aws_client
):
function_name = f"alias-fn-{short_uid()}"
snapshot.add_transformer(SortingTransformer("Aliases", lambda x: x["Name"]))
Copy link
Member

Choose a reason for hiding this comment

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

Why is this transformer necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy-pasting 🍝 from a test that worked, it's not needed actually. Thanks for the catch.

self, create_lambda_function_aws, lambda_su_role, snapshot, aws_client
):
function_name = f"alias-fn-{short_uid()}"
snapshot.add_transformer(SortingTransformer("Aliases", lambda x: x["Name"]))
Copy link
Member

Choose a reason for hiding this comment

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

Same question: Why is this necessary for this test? (as well in the third test)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy-pasting 🍝 from a test that worked, it's not needed actually. Thanks for the catch.

@anisaoshafi anisaoshafi requested a review from dfangl November 21, 2024 13:52
Copy link
Member
@dfangl dfangl left a comment

Choose a reason for hiding this comment

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

Looks good to me now, thank you for addressing my comments! I will not merge it now on purpose (even though it is ready), we will do that together in our next meeting.
Thank you for this contribution!

@dfangl dfangl merged commit 4803c4c into localstack:master Nov 25, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0