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

AWS::Serverless transform creating resources that fail W3011 (DeletionPolicy/UpdateReplacePolicy rule) #1265

Closed
TLaue opened this issue Dec 18, 2019 · 12 comments · Fixed by aws/serverless-application-model#1481 or #1529
Assignees

Comments

@TLaue
Copy link

TLaue commented Dec 18, 2019

cfn-lint version: (cfn-lint --version)
0.26.01

Description of issue.
The latest version of cfn-lint creates a warning in case of missing Deletion and UpdateReplace policy. This complain appears even though both properties are set for an S3 bucket which is the only resource in our stack wich requires these properties according to #1232. This warning did not appear prior to version 0.26.1. What is the difference beween I3011 and W3011?

Resources:
  xxxBucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Delete
    UpdateReplacePolicy: Delete
    Properties:...
@PatMyron PatMyron self-assigned this Dec 18, 2019
@PatMyron
Copy link
Contributor

PatMyron commented Dec 18, 2019

What is the difference beween I3011 and W3011?

W3011 warns about any resource that is protected from deletion through either an UpdateReplacePolicy or a DeletionPolicy but not protected by both

I3011 informs about any resource missing UpdateReplacePolicy / DeletionPolicy that could potentially result in data loss based on its resource type:

likely_stateful_resource_types = ['AWS::CloudFormation::Stack',
'AWS::Backup::BackupVault',
'AWS::DocDB::DBCluster',
'AWS::DocDB::DBInstance',
'AWS::DynamoDB::Table',
'AWS::EC2::Volume',
'AWS::EFS::FileSystem',
'AWS::EMR::Cluster',
'AWS::ElastiCache::CacheCluster',
'AWS::ElastiCache::ReplicationGroup',
'AWS::FSx::FileSystem',
'AWS::Neptune::DBCluster',
'AWS::Neptune::DBInstance',
'AWS::QLDB::Ledger',
'AWS::RDS::DBCluster',
'AWS::RDS::DBInstance',
'AWS::Redshift::Cluster',
'AWS::SDB::Domain',


@TLaue are you comfortable sharing the template that is generating the warning? I wasn't able to produce output with either of these templates:

Resources:
  Bucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Delete
    UpdateReplacePolicy: Delete
Resources:
  Bucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Delete
    UpdateReplacePolicy: Delete
    Properties:
      BucketName: bucket

@TLaue @kddejong some of the confusion might be coming from the 3011 messages lacking the resource logical ID that other rules provide. I can add that. In the meantime, rules give the line number of the violation and the Visual Studio Code extension should show them in context

@TLaue
Copy link
Author

TLaue commented Dec 18, 2019

May I send the template via email to you? Can you provide an email address?

@TLaue
Copy link
Author

TLaue commented Dec 18, 2019

It is on the way.

@PatMyron
Copy link
Contributor

PatMyron commented Dec 18, 2019

@TLaue I believe the AWS::Serverless transform is creating AWS::Lambda::Version resources with DeletionPolicy: Retain but no UpdateReplacePolicy. Will reach out to them about that

@senior88oqz
Copy link

AWS::Lambda::Version

In my template, I've got Transform: AWS::Serverless-2016-10-31 and AutoPublishAlias: live property in my AWS::Serverless::Function, and it fails to pass the updated W3011. I believe it's the AWS::Lambda::Version causing the problem, as if I comment out AutoPublishAlias: live, W3011 passes.

@PatMyron PatMyron changed the title W3011: DeletionPolicy/UpdateReplacePolicy required --> for which resources? AWS::Serverless transform creating resources that fail W3011 (DeletionPolicy/UpdateReplacePolicy rule) Dec 19, 2019
@PatMyron PatMyron pinned this issue Dec 19, 2019
kddejong pushed a commit that referenced this issue Dec 19, 2019
* adding resource path to W3011/I3011 messages

#1265

* adding resource path to W3011/I3011 messages in test results
@forzagreen
Copy link

forzagreen commented Dec 23, 2019

A workaround:

cfn-lint --ignore-checks W3011 -t template.yml

The error is because SAM creates resources of type AWS::Lambda::Version for each lambda function.
This Version resource has a default property "DeletionPolicy": "Retain" , but they don't have UpdateReplacePolicy property.
To see the full resources after transformation run cfn-lint with --info.

zaro0508 added a commit to zaro0508/Bridge-infra that referenced this issue Jan 9, 2020
New version of cfn-lint has a new warning rule (W3011)  that broke the
build.  We can ignore this warning as suggested in issue aws-cloudformation/cfn-lint#1265
@hugoduraes
Copy link

@PatMyron any news on this?

@ohadbenita

This comment has been minimized.

@PatMyron
Copy link
Contributor

The explicit UpdateReplacePolicy changes have been merged into AWS::Serverless transform's develop branch, but still haven't made it into a release yet. Will update once those changes have been released

@PatMyron
Copy link
Contributor

PatMyron commented May 14, 2020

Taking longer than expected for AWS::Serverless transform UpdateReplacePolicy support so I've exempted those two AWS::Lambda resource types from evaluation in W3011, so it should be enforceable as of 0.31.1, which is available through pip3 install cfn-lint --upgrade

Sorry for delays and thanks for waiting

@mhart
Copy link

mhart commented Sep 19, 2020

I'm still getting this with the below template:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:

  Bucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Retain
    UpdateReplacePolicy: Retain

  Function:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs12.x
      Events:
        ObjectCreated:
          Type: S3
          Properties:
            Bucket: !Ref Bucket
            Events: s3:ObjectCreated:*
[cfn-lint] W3011: Both UpdateReplacePolicy and DeletionPolicy are needed to protect Resources/Bucket from deletion

EDIT: Looking at the transformed template, it seems there's still the same issue with SAM – it removes the UpdateReplacePolicy:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  Bucket:
    DeletionPolicy: Retain
    DependsOn:
    - FunctionObjectCreatedPermission
    Properties:
      NotificationConfiguration:
        LambdaConfigurations:
        - Event: s3:ObjectCreated:*
          Function:
            Fn::GetAtt:
            - Function
            - Arn
    Type: AWS::S3::Bucket
# ...

Commented on the SAM repo over at: aws/serverless-application-model#450 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants