Skip to content

fix: reject invalid WebFunction and NetworkConnector inputs; Ref the WebFunction for revision and endpoint FunctionName - #4016

Merged
seshubaws merged 2 commits into
aws:developfrom
seshubaws:seshub/webfunction-lnc-validation-fixes
Oct 14, 2026
Merged

seshubaws merged 2 commits into
aws:developfrom
seshubaws:seshub/webfunction-lnc-validation-fixes

Conversation

@seshubaws

@seshubaws seshubaws commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available

Description of changes

Fixes from a bug bash of AWS::Serverless::WebFunction with network connectors. Invalid inputs that crashed the transform, or passed and failed later at deploy, now raise InvalidDocumentException with a clear message.

Crashes

  • is_intrinsic() with a non-string single key (intrinsics.py). This was reached from WebFunction EnvironmentVariables, RevisionWeights and ReplicaRegions (for example {1: a}). The helper is shared, so every caller is fixed.
  • ReplicaRegions.IncludeRegions / ExcludeRegions that aren't lists. Scalars raised TypeError, and a string gave a misleading "Unknown region key" error.
  • Unrecognized ReplicaRegions keys of mixed types (sorted() TypeError).
  • Non-string EnvironmentVariables keys and RevisionWeights revision IDs.
  • Non-string property names under Properties (Resource.from_dict, affects every SAM resource).
  • Non-string Globals section names.
  • A null or non-object template (Parser.validate_datatypes).

WebFunction EgressNetworkConnectorArn

  • A Ref or Fn::GetAtt on a network connector in the same template must use LatestVersionArn. Ref and Arn return the unversioned ARN, which only failed at deploy, and other attributes were accepted silently. The error points to !GetAtt <Connector>.LatestVersionArn.
  • Non-string literals (for example an integer) are rejected. The error now includes the expected ARN format and the value given.

NetworkConnector error messages

  • Invalid ComputeTypes entries (for example [5]) and VpcConfig.NetworkProtocol values (IPv6, ipv4, 4) now list the allowed values instead of "value is not a valid dict".

bin/sam-translate.py

  • Exits 1 on an invalid template, and no longer logs a generator object.

WebFunction revision and endpoint FunctionName (partially reverts an earlier workaround)

  • The revision and endpoint now always Ref the AWS::Lambda::WebFunction (its ARN), even when FunctionName is set, like AWS::Lambda::Version does. Renaming the function in a template then only changes the WebFunction, and the revision and endpoint follow.
  • The earlier code repeated the name in all three resources to work around a service bug where an ARN FunctionName could be created but not deleted. That bug is fixed.
  • The AuthType casing fix and the name runtime attribute from the workaround are unchanged.
  • The FunctionName description in sam-docs.json now says the revision and endpoint use Ref.

Not changed: checking that a referenced connector's ComputeTypes includes WebFunction, empty SubnetIds/SecurityGroupIds, the $LATEST qualifier, whole-list !Ref for list properties, ComputeTypes in Globals, and the recursion limit on self-referencing YAML aliases or very deep intrinsics.

Description of how you validated changes

  • New error tests: error_webfunction_egress_network_connector_reference, error_webfunction_invalid_property_types, error_network_connector_non_string_compute_type, error_globals_non_string_section. Updated error_network_connector_invalid_protocol. Added unit tests for is_intrinsic, the parser, and valid and invalid connector references (Ref, Arn, unknown attributes).
  • pytest tests: 4809 passed, 95.5% coverage.
  • Deployed with the public AWS::Lambda::WebFunction* types in us-east-2:
    • Without FunctionName: create, update with new code (revision replaced) and stack delete all succeeded.
    • With FunctionName: create, then renaming only FunctionName replaced the function, revision and endpoint and deleted the old ones, then stack delete succeeded. black, ruff, mypy --strict, the JSON and YAML format checks, and the schema gate pass.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@seshubaws
seshubaws requested a review from a team as a code owner October 13, 2026 23:11
@seshubaws seshubaws changed the title fix: reject invalid WebFunction and NetworkConnector inputs instead of crashing fix: reject invalid LWF and LNC inputs Oct 13, 2026
@seshubaws
seshubaws marked this pull request as draft October 13, 2026 23:39
…f crashing

Crashes (now InvalidDocumentException):
- is_intrinsic() with a non-string single key (e.g. EnvironmentVariables,
  RevisionWeights or ReplicaRegions {1: ...}).
- ReplicaRegions IncludeRegions/ExcludeRegions that aren't lists, and
  unrecognized ReplicaRegions keys of mixed types.
- Non-string EnvironmentVariables keys and RevisionWeights revision IDs.
- Non-string property names under Properties (any SAM resource).
- Non-string Globals section names.
- A null or non-object template.

WebFunction EgressNetworkConnectorArn:
- Reject a Ref or Fn::GetAtt on a network connector in the same template
  unless it uses LatestVersionArn (Ref and Arn return the unversioned ARN).
- Reject non-string literals and include the expected ARN format and the
  given value in the error.

NetworkConnector: name the allowed values for invalid ComputeTypes entries
and VpcConfig.NetworkProtocol instead of "value is not a valid dict".

bin/sam-translate.py exits 1 on an invalid template and no longer logs a
generator object.
@seshubaws
seshubaws force-pushed the seshub/webfunction-lnc-validation-fixes branch from c0ba841 to aec1c9b Compare October 13, 2026 23:40
@seshubaws seshubaws changed the title fix: reject invalid LWF and LNC inputs fix: reject invalid WebFunction and NetworkConnector inputs; Ref the WebFunction for revision and endpoint FunctionName Oct 14, 2026

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Results

Reviewed: a130d8b..2c794f8
Files: 28
Comments: 1

Comment thread samtranslator/model/sam_resources.py Outdated
@seshubaws
seshubaws marked this pull request as ready for review October 14, 2026 00:19
@seshubaws
seshubaws enabled auto-merge October 14, 2026 18:07
The revision and endpoint repeated the function name instead of Ref on the
function, to work around a service bug where a FunctionName given as the
function ARN could be created but not deleted. That bug is fixed.

Always Ref the function (its ARN) for the revision and endpoint
FunctionName, even when FunctionName is set, like AWS::Lambda::Version does.
A FunctionName change then only has to be made on the
AWS::Lambda::WebFunction. The AuthType casing fix and the "name" runtime
attribute from the original workaround are unchanged.
@seshubaws
seshubaws force-pushed the seshub/webfunction-lnc-validation-fixes branch from 2c794f8 to 771b4a3 Compare October 14, 2026 18:26
@seshubaws
seshubaws disabled auto-merge October 14, 2026 18:51
@seshubaws
seshubaws added this pull request to the merge queue Oct 14, 2026
Merged via the queue into aws:develop with commit 8f820ba Oct 14, 2026
9 checks passed
@seshubaws
seshubaws deleted the seshub/webfunction-lnc-validation-fixes branch October 14, 2026 19:15
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.

3 participants