fix: handle intrinsic functions in WebSocket API StageName property#3920
Open
fix: handle intrinsic functions in WebSocket API StageName property#3920
Conversation
When StageName is set to an intrinsic function (e.g. !Ref Param), string concatenation in _construct_permission caused TypeError. Fix: use fnSub variable substitution when stage_name is an intrinsic, preserving the original string format for plain string values. Also update property_types to accept one_of(IS_STR, IS_DICT) and update type annotation to Intrinsicable[str] for consistency.
valerena
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
StageNameis set to an intrinsic function (e.g.!Ref Param), SAM Translator crashes with:This happens in
_construct_permissionwhereself.stage_nameis concatenated directly into a string to build theSourceArn.Root Cause
Intrinsic functions like
{"Ref": "Param"}are Python dicts. String concatenation with+fails whenself.stage_nameis a dict instead of a str. Thevalidate_properties()bypass for intrinsics means the dict reaches the generator code without being caught.Fix
Use
isinstance(self.stage_name, str)to branch:fnSubvariable substitution so CloudFormation resolves it at deploy timeAlso updated:
property_typesforStageNameto acceptone_of(IS_STR, IS_DICT)for better error messages (consistent withHttpApi)Intrinsicable[str] | None(consistent withHttpApi)stage_nameparameter type inWebSocketApiGenerator.__init__toIntrinsicable[str] | NoneTesting
Added
test_perms_with_intrinsic_stage_nameunit test verifying the fix works for intrinsicStageName.