Ignore warnings from sam validate --lint

0

Is it possible to ignore warnings based on the warning ID or the line in the template causing the warning?

I use SAM in yaml format to create resources via CloudFormation. I turned on linting and two warnings remains. The first warning I don't understand and the second one I would like to ignore.

I use sam validate in my CI/CD pipeline (Github actions), so a non zero result code from sam validate fails the deployment. If I cannot ignore warnings, I either need to remove the linter of fix every single warning. This one I'm struggling with now is "consider using" so it should not really be a blocker.

I run sam validate -t template.yaml --lint

First template section causing a warning:

  MonitoringStack:
    Type: AWS::Serverless::Application
    Properties:
      Location: monitoring/monitoring.yaml
      Parameters:
        ApiId: !Ref Api
        Stage: !Ref EnvType
        AccessLogsGroupName: !Ref AccessLogs
W3002 This code may only work with `package` cli command as the property (Resources/MonitoringS/Properties/TemplateURL) is a string
/Users/.../template.yaml:978:3

Second is

  CFLogsBucket:
    Type: AWS::S3::Bucket
    Properties:
      AccessControl: BucketOwnerFullControl
      PublicAccessBlockConfiguration:
        BlockPublicAcls: true
        BlockPublicPolicy: true
        IgnorePublicAcls: true
        RestrictPublicBuckets: true
W3045 Consider using AWS::S3::BucketPolicy instead of AccessControl
/Users/.../template.yaml:1012:7

Can I use cnf-lint with the --ignore-checks option as documented here somehow?

My current github action step looks like this:

      - name: Validate SAM templates
        working-directory: ${{ github.workspace }}/api
        run: |
          echo "Validating template for ${{ env.API_CF_STACK_NAME }}"
          sam validate -t template.yaml --lint

Any idea if I can ignore this from the linter somehow, or if it actually would make sense to fix?

Andreax
질문됨 2달 전117회 조회
1개 답변
1
수락된 답변

sam validate does not provide an out-of-the-box feature to ignore specific warnings or errors based on their ID directly in the command or through a configuration file. The primary purpose of sam validate is to check the syntax and basic structure of the SAM template, not to provide extensive linting capabilities. For this reason, if sam validate returns a non-zero exit code due to a warning you wish to ignore, you might need to consider alternative approaches.

cfn-lint is a more flexible tool when it comes to linting CloudFormation templates, including SAM templates in YAML or JSON format. It allows for extensive customization of the linting process, including ignoring specific rules. To ignore specific checks with cfn-lint, you can use the --ignore-checks option followed by the IDs of the checks you want to ignore. For example:

cfn-lint template.yaml --ignore-checks W3002 W3045
profile picture
전문가
답변함 2달 전
  • Thank you!

    Worked as a charm after also adding a pip install cfn-lint in my Github action

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠