Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!Sub not supported in template file #718

Closed
tmay57 opened this issue Aug 15, 2020 · 11 comments
Closed

!Sub not supported in template file #718

tmay57 opened this issue Aug 15, 2020 · 11 comments
Assignees

Comments

@tmay57
Copy link

tmay57 commented Aug 15, 2020

Description

Resources:
  GetBlogs:
    Properties:
      FunctionName: !Sub ${AWS::StackName}

Generates an error: Error parsing JSON CloudFormation Template. ... : Exception during deserialization
Using Fn::Sub: also fails.
This is true for both JSON and Yaml template file formats.

Reproduction Steps

Create the sample Blogger application. Add the FunctionName property as shown above. Try to publish.
BTW - using the SAM CLI works just fine as does Stackery.io. My assumption is that any template that is valid for the SAM CLI should be valid with the VS extension.

Logs

NA

Environment

  • OS Info: Windows 10 Pro
  • Build Environment: Visual Studio - 16.6.5
  • AWS Toolkit version 1.18.1.0

Resolution


This is a 🐛 bug-report

@tmay57 tmay57 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 15, 2020
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Aug 17, 2020

Hi @tmay57,

Good morning.

From what I see in the Description, the syntax if for the YAML template. This is different from the JSON syntax. Please let me know the exact reproduction steps and the JSON template content.

Some helpful links:

  1. Formatting a AWS CloudFormation Template in Visual Studio

  2. Learn template basics

  3. General template snippets

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Aug 17, 2020
@tmay57
Copy link
Author

tmay57 commented Aug 18, 2020 via email

@ashishdhingra
Copy link
Contributor

Hi @tmay57,

Thanks for your inputs. Although its evident but just want to confirm if you are using AWS Toolkit for Visual Studio. Based on your confirmation we would need to move it to proper repository aws/aws-toolkit-visual-studio.

Thanks,
Ashish

@tmay57
Copy link
Author

tmay57 commented Aug 18, 2020 via email

@ashishdhingra
Copy link
Contributor

@tmay57 Thanks for your reply. I will have developer look at it, but it could be a while until fix is implemented since we need to ensure backward compatibility, etc.

Thanks,
Ashish

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Aug 19, 2020
@ganeshnj
Copy link
Contributor

@tmay57 I can confirm that short form !Sub doesn't work in the YAML based cloud formation template. Visual Studio Toolkit fails to parse it and outputs error during the validation phase. (given template file has no errors on validation)

YAML

Description: !Sub 'From JSON: Function to get a list of blogs hosted in ${AWS::Region}'

However, I was able to use full form Fn::Sub in both JSON and YAML based templates.

JSON

"Description": {
    "Fn::Sub": "From JSON: Function to get a list of blogs hosted in ${AWS::Region}"
},

YAML

Description:
  'Fn::Sub': 'From JSON: Function to get a list of blogs hosted in ${AWS::Region}'

Therefore, I would suggest you to use full form Fn::Sub to unblock you. Meanwhile, we fix short form.

Let me know if you are still blocked.

Also, as an additional check, you can verify your cloud formation template using validate-template. Make sure you prefix your template file path with file://.

@tmay57
Copy link
Author

tmay57 commented Aug 19, 2020

Thanks for the update. A few notes:

  • All the !* intrinsic functions seem to be unsupported - not just !Sub

I was able to get the following form, based on your example, to work:

Description:
  Fn::Sub: Function to get a list of blogs hosted in ${AWS::Region}

Note the single quotes are not included. There is no need to single quote either the Fn::Sub or the string value. Single quotes are added to the string value only if it contains characters that could be interpreted as yaml special characters. Since the form without single quotes worked, my assumption is that your parser is not depending on them unless required per yaml parsing specifications.

  • The following single line form is legal yaml and is not currently supported in the VS Toolkit (but is supported in the SAM CLI)
    Description: Fn::Sub: Function to get a list of blogs hosted in ${AWS::Region}

I see a lot of the single line form so it may be worth figuring that out as well so folks used to editing templates in yaml don't get frustrated by differences between SAM CLI and VS Toolkit yaml file processing.

In our case we generate pretty much the entire serverless.template file from meta-data so I can change the emitter to use the Fn::Sub style naming and multi-line form. However, these generated templates may be subsequently updated by humans so we will have to beef up our docs to tell users to ignore the AWS docs on intrinsic functions until this gets resolved.

We are not blocked and will just update our generators and docs to play pretty with the VS Toolkit. Thank you for your quick reply.

@ganeshnj
Copy link
Contributor

VS Toolkit uses YamlDotNet for parsing YAML document and it doesn't support short form of intrinsic functions i.e. !{function name}.

I have created an issue in YamlDotNet repository and as well as a backlog item in our queue.

@tmay57
Copy link
Author

tmay57 commented Aug 20, 2020

FWIW, we also use YamlDotNet and have no problem with parsing the intrinsic functions.

However, we did have a bit of head scratching to get the following emitter form to work:
Description: !Sub ${AWS::StackName}${EnvrionmentTagName}
It turns out you need to use the Tag property of the YamlScalarNode build the tree element for that form to emit properly.
example:
apiProperties.Add("Description", new YamlScalarNode("${StackTagName}${EnvironmentTagName}") { Tag = "!Sub" });

@ashishdhingra ashishdhingra added B and removed needs-triage This issue or PR still needs to be triaged. labels Sep 29, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2021

We have noticed this issue has not recieved attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 3, 2021
@github-actions github-actions bot closed this as completed Oct 8, 2021
@ashishdhingra ashishdhingra reopened this Oct 8, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2022

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants