in cfn-lint-serverless/cfn_lint_serverless/utils.py [0:0]
def _get_from_sub(self, value: Union[str, list]) -> Tuple[str, List[str]]:
"""
Return the name and references from a 'Fn::Sub' intrinsic function
"""
pattern = value
variables = {}
if isinstance(value, list):
pattern = value[0]
# Using Value() here to get nested references
variables = {k: Value(v) for k, v in value[1].items()}
references = []
for match in SUB_PATTERN.findall(pattern):
if match in variables:
# Variable with reference(s)
if len(variables[match].references) > 0:
references.extend(variables[match].references)
# Hard-coded variable
else:
# Replace with hard-coded value in value ID
pattern = pattern.replace(f"${{{match}}}", variables[match].id)
# No matching variable
else:
references.append(match)
return (pattern, references)