aws-cloudformation/cloudformation-coverage-roadmap

AWS CloudFormation Intrinsic Functions - Fn::ImportValue - Error

Closed this issue · 1 comments

Resource Name

When using Fn::ImportValue function, within Fn::Sub, observing the following weird behavior:

When following considered as valid:
image

However, following is NOT considered as valid cloudformation template:
image

However, both are pointing to SAME cross stack reference.

Details

When using Fn::ImportValue function, within Fn::Sub, observing the following weird behavior:

When following considered as valid:
image

However, following is NOT considered as valid cloudformation template:
image

However, both are pointing to SAME cross stack reference.

The structure for your Fn::Sub is a little off. The second value in an Fn::Sub is an object with key and values. So the following is how it should be structured.

Parameters:
  Env:
    Type: String
    AllowedValues:
      - prod
      - stage
      - dev 
Resources:
  Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument: {}
      RoleName: !Sub
        - ${UAI}-${TEST}
        - UAI:
            Fn::ImportValue: !Sub "AeGAIUAI-${Env}"
          TEST:
            Fn::ImportValue: !Sub "AeGAIUAI-${Env}"

Unless I'm missing something I'm going to close this issue as I believe it is working as intended. I can always reopen based on your feedback.