localstack icon indicating copy to clipboard operation
localstack copied to clipboard

Fix: Cfn: non-string parameter values

Open simonrw opened this issue 1 year ago β€’ 1 comments

Motivation

A customer had an issue when they used a non-string Parameter value, e.g.:

Parameters:
  MyValue:
    Type: Number
    Default: 5

When this parameter is used within a Fn::Sub expression:

  Value:
    Fn::Sub: "my value is ${MyValue}"

it causes an error: Could not resolve {'Ref': 'MyValue'} to terminal value type. This is because we raise an error if any Ref type that we resolve does not eventually resolve to a string. This is limited however, as the parameter value is a number, but really the error should be related to if the ref cannot be resolved beyond a structured type, e.g. dict, list or tuple.

[!WARNING]
The true fix probably involves casting all parameters to strings, but using the Type for something... Not quite sure yet at this stage. This PR however applies a bandage over the problem so at least this error does not continue to happen. In the future, we should look into proper parameter/ref handling.

Changes

  • Only raise the existing exception if we resolve a ref to a structured type.
  • Add minimal test that asserts the value is propagaed through the parameter and Fn::Sub invocation.

simonrw avatar Oct 18 '24 13:10 simonrw

LocalStack Community integration with Pro

β€‡β€ˆβ€‡β€‡2 files  Β±0β€‚β€ƒβ€‡β€ˆβ€‡β€‡2 suites  Β±0   1h 46m 6s ⏱️ + 3m 1s 3β€ˆ510 tests +1  3β€ˆ097 βœ… +1  413 πŸ’€ Β±0  0 ❌ Β±0  3β€ˆ512 runsβ€Š +1  3β€ˆ097 βœ… +1  415 πŸ’€ Β±0  0 ❌ Β±0 

Results for commit c56aff20. ± Comparison against base commit 62a302ca.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Oct 18 '24 14:10 github-actions[bot]