Cfn-python-lint: E3012 "String" recommended for an external template parameter where type is "Number"

Created on 5 Apr 2019  Â·  11Comments  Â·  Source: aws-cloudformation/cfn-python-lint

cfn-lint version: 0.18.0

I define some of my template with sub-templates and everything is packaged with that kind of command line

aws cloudformation package --template-file ./sources/template-source.yaml --s3-bucket my-bucket-build --output-template-file final-template.yaml 

In template-source I have a resource which type is AWS::CloudFormation::Stack.
It's definition looks like that :

    ManagerService:
        Type: AWS::CloudFormation::Stack
        Properties:
            TemplateURL: ../../../common/service.yaml
            Parameters:
                Cluster: !Ref Cluster
                DesiredCount: 1

Here is the definition of the parameter in my service template :

Parameters: 

    Cluster:
        Description: Please provide the ECS Cluster ID that this service should run on
        Type: String

    DesiredCount: 
        Description: How many instances of this task should we run across our cluster?
        Type: Number
        Default: 1

And cfn-lint return the following error :

cfn-lint source-template.yaml
E3012 Property Resources/ManagerService/Properties/Parameters/DesiredCount should be of type String

It says that type should be a String, but the type in the template is define as Number.
Am I missing something ?

Thanks for your help

question

All 11 comments

this is an interesting question. So we don't pull the nested stack templates to check their parameter types. We use the CloudFormation Spec to determine correctness for this. The trick here is the Map types are Strings. I am debating if we should just disable that check for this scenario.

"Parameters": {
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-parameters",
          "DuplicatesAllowed": false,
          "PrimitiveItemType": "String",
          "Required": false,
          "Type": "Map",
          "UpdateType": "Mutable"
        },

Thanks for the quick answer ! It make sens if the documentation define it as String. But the problem is if we want to ensure the data to match a Number, it still a best practice to keep it as a Number. Otherwise we also could set it as string and use AllowedPattern but it's a bit complexe as the Number type exist.

So yeah, maybe disable that check in the specific cas could be a solution.

I agree with you on this. I would like @chuckmeyer and @fatbasstard to weigh in on this too. Going to mark it as a question for now and until we can get their opinions.

Few more thoughts.

  • We won't know what the sub stack types are so we can't really test them. Basically, I won't know its a number so that is on you to validate (at least with the current features in cfn-lint)
  • Has anyone tested what List parameters look like here?

@kddejong List parameters do not pass through to sub stacks successfully. If you have a CommaDelimitedList type in your main stack and you attempt pass it through to a CommaDelimitedList in the sub stack, you will get a failure. Only types that can be coerced to strings can be passed through to a substack, like numbers and booleans.

The only way to pass a list through is to !Join [',', !Ref MyList] as you pass it through to the sub stack.

I think configuring E3012 with strict: False would do the trick here.

Any progress on this? I'm using this in vscode-cfn-lint and the same scenario is tripping me up.

For the moment, I've disabled the check with the follwing .cfnlintrc file :

include_checks:
- I
configure_rules:
  E3012:
    strict: False

I too am having this issue, even for AWS Resource properties that has a number. For example, the AllocatedStorage complains because it's a number, and it's checking for a string, so instead it wants quotes. Yet, CloudFormation/YAML works fine with it remaining without quotes, its just the cfn-lint checker. Can this be fixed, I encounter this in other areas too.

Resources:
  DB:
    Type: "AWS::RDS::DBInstance"
    Properties:
      AllocatedStorage: 5
      StorageType: gp2
      DBInstanceClass: db.t2.micro
      DBName: wordpress
      Engine: MySQL
      MasterUsername: wordpress
      MasterUserPassword: XXXXXX

@BatmanTheBlind I think the best we can do for now is to not check this when we are in AWS::CloudFormation::Stack and Parameters property. The spec lists it as a string of course but since we don't know the other template we won't have what it should be.

@tekdj1 you will want to refer to https://github.com/aws-cloudformation/cfn-python-lint/issues/547. By default we strictly check the value types based on the CloudFormation spec . You can disable the strict checking by configuring that rule

How do I add a rule? What exactly do I need to put as my rule to solve
this problem? Sorry, new to this.

I like cfn-lint checking this stuff, just wish that for strings and
numbers, it would ignore, as CloudFormation doesn’t care if quotes exist or
not.

On Sun, Feb 23, 2020 at 10:01 AM Kevin DeJong notifications@github.com
wrote:

@tekdj1 https://github.com/tekdj1 you will want to refer to #547
https://github.com/aws-cloudformation/cfn-python-lint/issues/547. By
default we strictly check the value types based on the CloudFormation spec
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-resource-specification.html
. You can disable the strict checking by configuring that rule
https://github.com/aws-cloudformation/cfn-python-lint#configure-rules

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/aws-cloudformation/cfn-python-lint/issues/800?email_source=notifications&email_token=ADIJTFIPSVDZBQRCO3ZKVHDREKFS7A5CNFSM4HD2SUH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMV53IQ#issuecomment-590077346,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADIJTFJL3CU6P7AUZCV3AMTREKFS7ANCNFSM4HD2SUHQ
.

@tekdj to configure that rule in your template @BatmanTheBlind has a good example above. https://github.com/aws-cloudformation/cfn-python-lint/issues/800#issuecomment-589053519

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlessandroLorenzi picture AlessandroLorenzi  Â·  3Comments

KarthickEmis picture KarthickEmis  Â·  4Comments

Sergei-Rudenkov picture Sergei-Rudenkov  Â·  4Comments

jecnua picture jecnua  Â·  5Comments

kddejong picture kddejong  Â·  3Comments