Skip to content

fix(E3010): count post-transform resources on SAM templates - #4889

Open
Varshith-Kali wants to merge 2 commits into
aws-cloudformation:mainfrom
Varshith-Kali:fix/e3010-sam-post-transform-count
Open

Varshith-Kali wants to merge 2 commits into
aws-cloudformation:mainfrom
Varshith-Kali:fix/e3010-sam-post-transform-count

Conversation

@Varshith-Kali

Copy link
Copy Markdown
Contributor

Summary

Fixes #4883.

Since #4491 removed the SAM transform, E3010 counted Resources as written. A SAM template that expands past the 500 resource limit passed lint, even though CloudFormation rejects it at deploy time (each AWS::Serverless::Function becomes at least the function plus its execution role).

Changes

  • E3010 now evaluates the resource count on the post-transform template when the template declares the AWS::Serverless-2016-10-31 transform. The transform itself stays disabled for the rest of the ruleset.
  • The count is a conservative lower bound: every serverless resource counts as the CloudFormation resource it expands to (AWS::Serverless::Connector creates none), plus the generated resources the transform is known to create (implicit roles, versions, aliases, function URLs, CodeDeploy resources, per-event permissions, implicit APIs). The rule fires only when the template provably exceeds the limit, so the estimate cannot cause false positives.
  • The SAM resource generation model in cfnlint/context is now shared: _inject_sam_implicit_resources is built on the new sam_generated_resources generator, which E3010 also uses for counting.
  • Fixed the model generating CodeDeploy resources for functions that do not specify DeploymentPreference (they were injected for every function).

Testing

  • New regression test reproduces the issue exactly: 260 AWS::Serverless::Function resources (under 500 as written) now fail E3010, matching the 520 resources CloudFormation reports at deploy. Also verified end to end with the issue's repro template.
  • Negative tests: non-SAM templates count exactly as written; SAM templates under the limit stay clean; the I3010 approaching-limit check uses the same count.
  • test/unit/rules/resources, test/unit/rules/jsonschema, test/unit/rules/mappings, test/unit/rules/outputs, test/unit/module/context, and the SAM integration tests are all green. Ruff check and format clean.

@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Hi team, the [CI] Test PR workflow run on the current head is still parked waiting for a first-time-contributor approval (action_required). Could a maintainer approve the run so CI can proceed? Thanks.

Since the SAM transform stopped running in aws-cloudformation#4491, E3010 counted Resources
as written, so a SAM template expanding past the 500 resource limit passed
lint even though CloudFormation rejects it at deploy.

E3010 now counts a conservative lower bound of the post-transform total
when the template declares the AWS::Serverless-2016-10-31 transform: each
serverless resource counts as the CloudFormation resource it expands to,
plus the resources the transform generates (implicit roles, versions,
aliases, URLs, CodeDeploy resources, per-event permissions, implicit APIs).
It fires only when the template provably exceeds the limit, never on an
over-estimate. The transform itself stays disabled for the rest of the
ruleset.

Also fixes the implicit resource model generating CodeDeploy resources for
functions without DeploymentPreference.

Fixes aws-cloudformation#4883
@kddejong
kddejong force-pushed the fix/e3010-sam-post-transform-count branch from 938e5e3 to 2c0ae0c Compare November 9, 2026 17:43
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Fixed the CI failure: it was only the isort hook in the style job, not the tests. All 3485 unit tests passed on windows-latest 3.13; isort flagged src/cfnlint/rules/resources/MaxProperties.py for an extra blank line after the import block. Removed that one blank line in 9211bd6. Verified locally: isort check clean, ruff check and format clean, and the affected unit tests pass (1643 passed in test/unit/rules/resources and test/unit/module/context).

@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Hi team, the fix for the CI failure is now on the current head 9211bd6 (isort hook only, all 3485 unit tests pass locally), but no workflow runs have started on it yet. Could a maintainer approve the first-time-contributor run so CI can verify the fix?

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.

E3010: SAM templates that expand past 500 resources pass since 1.54.0

1 participant