title: AWS CloudFormation - using !Ref inside !Sub
body: <p>I'm writing AWS CloudFormation template (using yaml) which creates AWS Service Catalog Product.
  I'm getting the template for the product using parameter S3FilePath which has a value like the above path: <a href="https://bucket.s3-eu-west-1.amazonaws.com/template.yml" rel="nofollow noreferrer">https://bucket.s3-eu-west-1.amazonaws.com/template.yml</a>.
  The URL to the file needs to be send in a JSON format as shown here (this example works):</p>
  <pre><code>Resources:
      Type: AWS::ServiceCatalog::CloudFormationProduct
      Properties: 
        Description: Example Product
        Distributor: xyz
        Name: ExampleProduct
        Owner: xyz
        ProvisioningArtifactParameters: 
          - Description: Example Product
            Info: { &quot;LoadTemplateFromURL&quot;: &quot;https://bucket.s3-eu-west-1.amazonaws.com/template.yml&quot; }
            Name: Version1
  </code></pre>
  <p>I tried to replace the URL using !Sub and !Ref as shown below:</p>
  <pre><code>Parameters:
    S3FilePath:
        Type: String
        Description: file name
  Resources:
      Type: AWS::ServiceCatalog::CloudFormationProduct
      Properties: 
        Description: Example Product
        Distributor: xyz
        Name: ExampleProduct
        Owner: xyz
        ProvisioningArtifactParameters: 
          - Description: Example Product
            Info: !Sub
              - '{ &quot;LoadTemplateFromURL&quot;: &quot;${FILEPATH}&quot; }'
              - {FILEPATH: !Ref S3FilePath}
            Name: Version1
  </code></pre>
  <p>But the CloudFormation stack fails with the error: &quot;invalid input&quot;.
  I guess I am building the JSON in a wrong way, I tried to use \ before each ' &quot; ' but it didn't help either and I couldn't find an example which explain how to build this correctly. There is no problem with the S3FilePath parameter.</p>
  <p>Can you please advice how to use the !Sub and !Ref correctly to build the JSON? Thanks.</p>