Skip to content

fix: handle SAM RestApi stage references - #4719

Closed
0xTaoZ wants to merge 1 commit into
aws-cloudformation:mainfrom
0xTaoZ:agent/fix-sam-restapi-stage
Closed

0xTaoZ wants to merge 1 commit into
aws-cloudformation:mainfrom
0xTaoZ:agent/fix-sam-restapi-stage

Conversation

@0xTaoZ

@0xTaoZ 0xTaoZ commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes #4714.

This updates SAM implicit-resource handling so AWS::Serverless::StateMachine Api events create the same synthetic implicit ServerlessRestApi/stage context as function Api events. It also teaches Fn::Sub validation that SAM ${Api.Stage} references are generated stage-resource references, not CloudFormation Fn::GetAtt attributes on the API resource.

Why

SAM rewrites ${ServerlessRestApi.Stage} to the generated stage logical id during transform. cfn-lint was treating it as a GetAtt against AWS::Serverless::Api/AWS::ApiGateway::RestApi, causing false positives after the schema-based SAM validation changes.

Tests

  • .venv/bin/python -m pytest test/unit/module/context/test_inject_sam_implicit.py test/unit/rules/functions/test_sub.py -q
  • .venv/bin/python -m pytest test/unit/rules/functions/test_sub.py test/unit/rules/functions/test_getatt.py test/unit/module/context/test_inject_sam_implicit.py -q
  • .venv/bin/ruff check src/cfnlint/context/context.py src/cfnlint/rules/functions/Sub.py test/unit/module/context/test_inject_sam_implicit.py test/unit/rules/functions/test_sub.py
  • .venv/bin/ruff format --check src/cfnlint/context/context.py src/cfnlint/rules/functions/Sub.py test/unit/module/context/test_inject_sam_implicit.py test/unit/rules/functions/test_sub.py
  • git diff --check

Note: I also tried a CLI smoke with the issue-shaped SAM templates, but this local environment could not download enhanced schemas due to CERTIFICATE_VERIFY_FAILED, so the focused unit tests are the reliable validation here.

@0xTaoZ 0xTaoZ closed this Sep 29, 2026
@0xTaoZ
0xTaoZ deleted the agent/fix-sam-restapi-stage branch September 29, 2026 12:13
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.

False positives on SAM implicit ServerlessRestApi since 1.54.0: StateMachine Api events ignored, and .Stage checked as a GetAtt

1 participant