Skip to content

Creating rules

If you are thinking of creating or proposing a new rule, please follow the process outline below. The first step before adding a new rule is to submit an issue to collect feedback from other members of the community.

Create an issue

Before starting the implementation of a new rule, please create an issue using the New rule template. This will allow members of the community to provide feedback on its implementation, if it meets the needs of most serverless users, if it's the right level, etc.

Template for cfn-lint rules

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# TODO: set the rule name
class __Rule(CloudFormationLintRule):
    # TODO: set docstring
    """
    Ensure that ...
    """

    # TODO: update these values
    id = "..." # noqa: VNE003
    shortdesc = "..."
    description = "Ensure that ..."
    source_url = "..."
    tags = ["lambda"]

    _message = "... {} ..."

    def match(self, cfn):
        # TODO: update docstring
        """
        Match against ...
        """

        matches = []

        # TODO: set resource type
        for key, value in cfn.get_resources(["..."]).items():
            # TODO: set property name
            prop = value.get("Properties", {}).get("...", None)

            if prop is None:
                matches.append(RuleMatch(["Resources", key], self._message.format(key)))

        return matches

Template for documentation

Please use the following template when writing documentation for a rule. Each rule goes into a separate markdown file into the relevant service folder. For example, a rule for AWS Lambda would go into the docs/rules/lambda/ folder.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# _Service Name Rule name_

__Level__: _Rule level_
{: class="badge badge-red" }

__Initial version__: _release version_
{: class="badge badge-blue" }

__cfn-lint__: _cfn-lint rule ID_
{: class="badge" }

__tflint__: _tflint rule name_
{: class="badge" }

_Short explanation on the rule_

## Implementations

=== "CDK"

    ```typescript
    // Imports here

    export class MyStack extends cdk.Stack {
      constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        // Implementation
      }
    }
    ```

=== "CloudFormation (JSON)"

    ```json
    {
      "Resources": {
        // Add resources here
      }
    }
    ```

=== "CloudFormation (YAML)"

    ```yaml
    Resources:
      # Add resources here
    ```

=== "Serverless Framework"

    ```yaml
    provider:
      name: aws
      # Add provider-specific configuration here

    resources:
      # Add resources here
    ```

=== "Terraform"

    ```tf
    # Add Terraform resources here
    ```

## See also

* _List of links to the relevant documentation, from sources such as AWS Well-Architected, service documentation, etc._