8000 Fix provisioned concurrency set on Lambda alias by dfangl · Pull Request #12592 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Fix provisioned concurrency set on Lambda alias #12592

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 4 commits into from
May 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ def get_invocation_lease(
provisioned_concurrency_config = function.provisioned_concurrency_configs.get(
function_version.id.qualifier
)
Copy link
Member

Choose a reason for hiding this comment

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

docs: Would a docstring help to clarify our findings?

# Look up a potential provisioned concurrency config for aliases because a function version shares provisioned concurrency with aliases. However, the config only applies to a single function version or alias on the CRUD level.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some comments on it!

if not provisioned_concurrency_config:
# check if any aliases point to the current version, and check the provisioned concurrency config
# for them. There can be only one config for a version, not matter if defined on the alias or version itself.
for alias in function.aliases.values():
if alias.function_version == function_version.id.qualifier:
provisioned_concurrency_config = (
function.provisioned_concurrency_configs.get(alias.name)
)
break
if provisioned_concurrency_config:
available_provisioned_concurrency = (
provisioned_concurrency_config.provisioned_concurrent_executions
Expand Down
53 changes: 53 additions & 0 deletions tests/aws/services/lambda_/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,59 @@ def test_provisioned_concurrency(self, create_lambda_function, snapshot, aws_cli
result2 = json.load(invoke_result2["Payload"])
assert result2 == "on-demand"

@markers.aws.validated
def test_provisioned_concurrency_on_alias(self, create_lambda_function, snapshot, aws_client):
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Should we be confirming within the test that no additional containers are brought up?

Copy link
Member Author

Choose a reason for hiding this comment

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

There will be an additional container brought up for the last invocation, but in general, confirming that we hit the right invocation type environment should be sufficient, otherwise we cannot validate it against AWS as well.

"""
Tests provisioned concurrency created and invoked using an alias
"""
# TODO add test that you cannot set provisioned concurrency on both alias and version it points to
# TODO can you set provisioned concurrency on multiple aliases pointing to the same function version?
min_concurrent_executions = 10 + 5
check_concurrency_quota(aws_client, min_concurrent_executions)

func_name = f"test_lambda_{short_uid()}"
alias_name = "live"

create_lambda_function(
func_name=func_name,
handler_file=TEST_LAMBDA_INVOCATION_TYPE,
runtime=Runtime.python3_12,
client=aws_client.lambda_,
)

v1 = aws_client.lambda_.publish_version(FunctionName=func_name)
aws_client.lambda_.create_alias(
FunctionName=func_name, Name=alias_name, FunctionVersion=v1["Version"]
)

put_provisioned = aws_client.lambda_.put_provisioned_concurrency_config(
FunctionName=func_name, Qualifier=alias_name, ProvisionedConcurrentExecutions=5
)
snapshot.match("put_provisioned_5", put_provisioned)

get_provisioned_prewait = aws_client.lambda_.get_provisioned_concurrency_config(
FunctionName=func_name, Qualifier=alias_name
)

snapshot.match("get_provisioned_prewait", get_provisioned_prewait)
assert wait_until(concurrency_update_done(aws_client.lambda_, func_name, alias_name))
get_provisioned_postwait = aws_client.lambda_.get_provisioned_concurrency_config(
FunctionName=func_name, Qualifier=alias_name
)
snapshot.match("get_provisioned_postwait", get_provisioned_postwait)

invoke_result1 = aws_client.lambda_.invoke(FunctionName=func_name, Qualifier=alias_name)
result1 = json.load(invoke_result1["Payload"])
assert result1 == "provisioned-concurrency"

invoke_result1 = aws_client.lambda_.invoke(FunctionName=func_name, Qualifier=v1["Version"])
result1 = json.load(invoke_result1["Payload"])
assert result1 == "provisioned-concurrency"

invoke_result2 = aws_client.lambda_.invoke(FunctionName=func_name, Qualifier="$LATEST")
result2 = json.load(invoke_result2["Payload"])
assert result2 == "on-demand"

@markers.aws.validated
def test_lambda_provisioned_concurrency_scheduling(
self, snapshot, create_lambda_function, aws_client
Expand Down
38 changes: 38 additions & 0 deletions tests/aws/services/lambda_/test_lambda.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -4463,5 +4463,43 @@
}
}
}
},
"tests/aws/services/lambda_/test_lambda.py::TestLambdaConcurrency::test_provisioned_concurrency_on_alias": {
"recorded-date": "07-05-2025, 09:26:54",
"recorded-content": {
"put_provisioned_5": {
"AllocatedProvisionedConcurrentExecutions": 0,
"AvailableProvisionedConcurrentExecutions": 0,
"LastModified": "date",
"RequestedProvisionedConcurrentExecutions": 5,
"Status": "IN_PROGRESS",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 202
}
},
"get_provisioned_prewait": {
"AllocatedProvisionedConcurrentExecutions": 0,
"AvailableProvisionedConcurrentExecutions": 0,
"LastModified": "date",
"RequestedProvisionedConcurrentExecutions": 5,
"Status": "IN_PROGRESS",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
},
"get_provisioned_postwait": {
"AllocatedProvisionedConcurrentExecutions": 5,
"AvailableProvisionedConcurrentExecutions": 5,
"LastModified": "date",
"RequestedProvisionedConcurrentExecutions": 5,
"Status": "READY",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
}
}
}
}
3 changes: 3 additions & 0 deletions tests/aws/services/lambda_/test_lambda.validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
"tests/aws/services/lambda_/test_lambda.py::TestLambdaConcurrency::test_provisioned_concurrency": {
"last_validated_date": "2024-04-08T17:04:20+00:00"
},
"tests/aws/services/lambda_/test_lambda.py::TestLambdaConcurrency::test_provisioned_concurrency_on_alias": {
"last_validated_date": "2025-05-07T09:26:54+00:00"
},
"tests/aws/services/lambda_/test_lambda.py::TestLambdaConcurrency::test_reserved_concurrency": {
"last_validated_date": "2024-04-08T17:08:10+00:00"
},
Expand Down
Loading
0