Files
floci/compatibility-tests/sdk-test-awscli/test/lambda-web.bats
T
TATSUNO “Taz” Yasuhiro 6f78083080 feat(lambdaweb): Lambda Web Functions control plane (#5706)
* feat(lambdaweb): Lambda Web Functions control plane

The lambda-web service model (apiVersion 2025-03-07) signs as lambda, so
it is served under the lambda service at /2025-03-07/... with the AWS
wire shapes, state words and error wording of the 20 operations on web
functions, revisions, endpoints, tags and the resource policy.

Revisions and endpoints converge at once. They are stored Active and an
endpoint update is stored Successful, while the create and update
responses report the transitional state AWS reports, so a CLI waiter
settles on its first poll. Code comes from an S3 object that must exist.
IamAuth, the resource policy and the endpoint domain are stored but not
served yet.

Part of #5699

* fix(lambdaweb): carry the page position in the token

The nextToken of a list operation was a UUID keyed into an in-memory
anchor map that only grew and was not scoped to the account. The token
is now a core Pagination cursor that encodes the request (operation,
region, account, function, filters and page size) and the cursor of the
item the page ended on. A token reused with other parameters gets the
AWS "does not match the request" error and any other token the AWS
"invalid or has expired" error.

AWS issues UUID tokens and rejects any other shape, so Floci no longer
reproduces the pattern error for a malformed token.

* fix(iam): resolve a Lambda Web revision or endpoint named by its ARN

The route resource for IAM enforcement took the path segment after
revisions or endpoints as the id. A revision or endpoint ARN in that
position carries slashes, so the resource ARN ended in the ARN's first
segment and a policy scoped to the revision or endpoint did not apply.
The id is now the last segment of such an ARN.

* fix(lambdaweb): add the values of a repeated state filter

AWS lists a function when any state filter in the request names its
state. A later state filter replaced the earlier one, so a request with
state=Active followed by state=Failed listed nothing.

* fix(lambdaweb): refuse empty arrays in a resource policy

AWS answers an empty Action or Resource array with the policy syntax
error and an empty principal array with the invalid principal error,
which wins when all three are empty. Floci stored such a policy.

* fix(lambdaweb): judge a wildcard principal by the operator and value of its condition

A trusted condition key alone kept an Allow for every principal out of
the public check. AWS blocks the policy unless a positive operator pins
the key: StringNotEquals and the IfExists forms do not count, nor does a
wildcard in an account value or in the account field of an ARN value,
while a wildcard elsewhere in an ARN and a literal * under StringEquals
do.
2026-10-15 06:46:52 -04:00

144 lines
6.0 KiB
Bash

#!/usr/bin/env bats
# Lambda Web Functions integration tests
#
# The `lambda-web` service model signs as lambda and is served under the lambda
# service. Code comes from an S3 object, so each test seeds one first.
setup() {
load 'test_helper/common-setup'
FUNCTION_NAME=""
BUCKET="cli-lambda-web-code-$$"
ROLE_ARN="arn:aws:iam::000000000000:role/lambda-web"
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null 2>&1 || true
printf 'zip' > "$BATS_TEST_TMPDIR/app.zip"
aws_cmd s3api put-object --bucket "$BUCKET" --key app.zip --body "$BATS_TEST_TMPDIR/app.zip" >/dev/null
}
teardown() {
if [ -n "$FUNCTION_NAME" ]; then
aws_cmd lambda-web delete-web-function --function-name "$FUNCTION_NAME" >/dev/null 2>&1 || true
fi
aws_cmd s3 rb "s3://$BUCKET" --force >/dev/null 2>&1 || true
}
build_config() {
printf '{"codeConfig":{"s3Object":{"bucket":"%s","key":"app.zip"}},"runtimeConfig":{"runtime":"nodejs24.x"}}' "$BUCKET"
}
create_function() {
local name="$1"
aws_cmd lambda-web create-web-function \
--function-name "$name" \
--revision-config "{\"buildConfig\":$(build_config),\"serviceConfig\":{\"executionRoleArn\":\"$ROLE_ARN\"}}" \
--endpoint-config '{"endpointName":"dev","endpointType":"HomeRegion","authType":"ApplicationManaged","autoDeploymentMode":"LatestRevision"}'
}
@test "Lambda Web: create a function with its first revision and endpoint" {
FUNCTION_NAME=$(unique_name "cli-web")
run create_function "$FUNCTION_NAME"
assert_success
state=$(json_get "$output" '.state')
revision_state=$(json_get "$output" '.revision.state')
endpoint_state=$(json_get "$output" '.endpoint.state')
domain=$(json_get "$output" '.endpoint.domainName')
[ "$state" = "Active" ]
[ "$revision_state" = "Pending" ]
[ "$endpoint_state" = "Pending" ]
[[ "$domain" =~ \.lambda-web\.us-east-1\. ]]
run aws_cmd lambda-web wait web-function-endpoint-active --function-name "$FUNCTION_NAME" --endpoint-name dev
assert_success
}
@test "Lambda Web: a new revision moves a LatestRevision endpoint" {
FUNCTION_NAME=$(unique_name "cli-web")
create_function "$FUNCTION_NAME" >/dev/null
run aws_cmd lambda-web create-web-function-revision \
--function-name "$FUNCTION_NAME" \
--build-config "$(build_config)" \
--service-config "{\"executionRoleArn\":\"$ROLE_ARN\",\"timeoutSeconds\":60}"
assert_success
revision_id=$(json_get "$output" '.revisionId')
[[ "$revision_id" =~ ^rev-[a-z0-9]{5}$ ]]
run aws_cmd lambda-web wait web-function-revision-active --function-name "$FUNCTION_NAME" --revision-id "$revision_id"
assert_success
run aws_cmd lambda-web get-web-function-endpoint --function-name "$FUNCTION_NAME" --endpoint-name dev
assert_success
routed=$(json_get "$output" '.revisionWeights[0].revisionId')
[ "$routed" = "$revision_id" ]
}
@test "Lambda Web: weighted routing and the in-use revision guard" {
FUNCTION_NAME=$(unique_name "cli-web")
create_function "$FUNCTION_NAME" >/dev/null
first=$(aws_cmd lambda-web list-web-function-revisions --function-name "$FUNCTION_NAME" | jq -r '.revisions[0].revisionId')
run aws_cmd lambda-web update-web-function-endpoint \
--function-name "$FUNCTION_NAME" --endpoint-name dev \
--auto-deployment-mode Disabled \
--revision-weights "[{\"revisionId\":\"$first\",\"weight\":100}]"
assert_success
status=$(json_get "$output" '.updateStatus')
[ "$status" = "InProgress" ]
run aws_cmd lambda-web wait web-function-endpoint-updated --function-name "$FUNCTION_NAME" --endpoint-name dev
assert_success
run aws_cmd lambda-web delete-web-function-revision --function-name "$FUNCTION_NAME" --revision-id "$first"
assert_failure
assert_output --partial "ConflictException"
assert_output --partial "the endpoints [dev] are using it"
}
@test "Lambda Web: tags and the resource policy" {
FUNCTION_NAME=$(unique_name "cli-web")
create_function "$FUNCTION_NAME" >/dev/null
arn="arn:aws:lambda:us-east-1:000000000000:web-function/$FUNCTION_NAME"
run aws_cmd lambda-web tag-resource --resource "$arn" --tags env=test
assert_success
run aws_cmd lambda-web list-tags --resource "$arn"
assert_success
env_tag=$(json_get "$output" '.tags.env')
[ "$env_tag" = "test" ]
run aws_cmd lambda-web put-resource-policy --resource-arn "$arn" \
--policy "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::000000000000:root\"},\"Action\":\"lambda:InvokeWebFunctionEndpoint\",\"Resource\":\"$arn/endpoint/*\"}]}"
assert_success
revision_id=$(json_get "$output" '.revisionId')
[ -n "$revision_id" ]
run aws_cmd lambda-web delete-resource-policy --resource-arn "$arn" --revision-id "$revision_id"
assert_success
run aws_cmd lambda-web get-resource-policy --resource-arn "$arn"
assert_failure
assert_output --partial "does not have a policy"
}
@test "Lambda Web: invalid names and missing functions" {
run aws_cmd lambda-web get-web-function --function-name cli-no-such-web-function
assert_failure
assert_output --partial "ResourceNotFoundException"
# The = form keeps the CLI from reading a name that starts with a dash as an option.
run aws_cmd lambda-web create-web-function --function-name=-bad \
--revision-config "{\"buildConfig\":$(build_config),\"serviceConfig\":{\"executionRoleArn\":\"$ROLE_ARN\"}}" \
--endpoint-config '{"endpointName":"dev","endpointType":"HomeRegion","authType":"ApplicationManaged"}'
assert_failure
assert_output --partial "Invalid function name or ARN '-bad'"
}
@test "Lambda Web: delete removes the function and the waiter settles" {
FUNCTION_NAME=$(unique_name "cli-web")
create_function "$FUNCTION_NAME" >/dev/null
run aws_cmd lambda-web delete-web-function --function-name "$FUNCTION_NAME"
assert_success
run aws_cmd lambda-web wait web-function-deleted --function-name "$FUNCTION_NAME"
assert_success
FUNCTION_NAME=""
}