question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to disable E1029 using a regex pattern on the variable name

See original GitHub issue

cfn-lint version: 0.26.0

This is another take on the https://github.com/aws-cloudformation/cfn-python-lint/issues/740. I am using cfn-lint in combination with Serverless Framework and the VSCode plugin to validate the CloudFormation template “chunks” that are referenced in the resource section within the serverless.yml (spec: https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/)

serverless.yml (not validated by cfn-lint, provided for reference)

service: my-service
provider:
  name: aws
[... other stuff ..]

# importing raw CloudFormation files here
resources:
  - Description: My Example Service Stack
  # roles
  - ${file(./cfn-resources/resource1.yml)}
  - ${file(./cfn-resources/resource2.yml)}

.cfnlintrc

templates:
- cfn-resources/*.yml

resource1.yml

Conditions:
  PrimaryRegion: !Equals ['${self:provider.region}', 'us-east-1']

[some resources]

Serverless framework will pre-process the yml file and replace the ${…} sequence with actual string values before generating the actual CloudFormation template to be sent to AWS. Unfortunately they chose a syntax that conflicts with something CloudFormation uses as well.

With the above config, cfn-lint generates this error:

E1029: Found an embedded parameter outside of an "Fn::Sub" at Conditions/PrimaryRegion/Fn::Equals/0

I can get around this error by putting a !Sub in front of it (which is useless, it will upload an unnecessary !Sub ‘us-east-1’ to AWS). But then I get this:

E1019: Parameter self:provider.region for Fn::Sub not found at Conditions/PrimaryRegion/Fn::Equals/0/Fn::Sub

So I have to disable both rules, or disable E1019 and stick a !Sub in front of everything that has a serverless-specific variable.

It would be great to have a way to be able to configure both rules in such a way that they treat the whole ${variable} block as a literal by if variable matches a regex pattern. Ideally through .cfnlintrc so it applies to all the files…

NOTE: I am aware that this is not an issue with cfn-python-lint, but I don’t see how it could be solved by the VSCode plugin (it basically reports what it gets from cfn-lint) or the Serverless team (they’re stuck with the syntax due to backwards compatibility, it’s been discussed before, in the context of having the problem in the opposite direction by serverless treating ${AWS::Region} as its own variable and trying to replace it, see https://github.com/serverless/serverless/pull/3694)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
coyoteecdcommented, Feb 18, 2020

I installed 0.28.1 and it works as intended, we can close this.

1reaction
kddejongcommented, Jan 9, 2020

I think this could be done easily. Configuring this rule seems to be never ending so making it a little more dynamic seems like a reasonable approach to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Option to disable E1029 using a regex pattern on the variable ...
After a bit of thought, I realized that the initial config proposal is not what I need; the reason is the resource/condition excludes...
Read more >
Regular Expression (Regex) Tutorial
Regular Expression, or regex or regexp in short, is extremely and amazingly powerful in searching and manipulating text strings, particularly in processing ...
Read more >
Change Variable Name using Regular Expression
I want to remove "AC" in the middle, changing variables' name to "CRAGE" , "CCRAA1" . I've tried the following expression and it...
Read more >
Regular expression examples - Product documentation
When creating regular expressions for Cloud Insights automatic resolution, you can configure output format by entering values in a field named ...
Read more >
Best Practices for Regular Expressions in .NET - Microsoft Learn
Regular expression objects represent compiled patterns when a Regex object is instantiated with an options argument that includes the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found