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

Feature Request: support DeletionPolicy #450

Closed
huribeir opened this issue May 30, 2018 · 6 comments
Closed

Feature Request: support DeletionPolicy #450

huribeir opened this issue May 30, 2018 · 6 comments

Comments

@huribeir
Copy link

This is a feature request to cover the implementation of support to using DeletionPolicy statements on AWS SAM resources. The result of specifying a DeletionPolicy attribute on a SAM resource should be the resulting CloudFormation resources also having that attribute

@shwetaskatdare
Copy link

Thanks for the request. We'll look into it.

@jfpaccini
Copy link

As per https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-resource-attributes.html, only 'DependsOn' resource attribute is supported accross the board and DeletionPolicy is only supported for LayerVersion.

It would be very useful to support it for DynamoDb tables (aka AWS::Serverless::SimpleTable), as we do not want to delete a database table for some sensitive environments.

thanks

@PatMyron
Copy link
Contributor

PatMyron commented Jun 12, 2020

UpdateReplacePolicy and Metadata too


Without supporting DeletionPolicy and UpdateReplacePolicy, AWS::Serverless resources cannot be easily protected

Without supporting Metadata, resource level cfn-lint / cfn-nag ignores fail, and deployment safety Cloudformation Linter rules are ignored for entire templates, endangering other resource types too:

aws-cloudformation/cfn-lint#1265


More Metadata support thoughts

@mhart
Copy link

mhart commented Sep 19, 2020

I'm not sure if this is the same issue, but it looks like UpdateReplacePolicy is actually removed from an S3 bucket in the transformed output:

Original 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:*

Transformed template (just the bucket portion):

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

Note the DeletionPolicy is present, but the UpdateReplacePolicy has been removed. If I remove the function, the bucket stays as-is.

Let me know if I should file a separate issue for this.

@rocifier
Copy link

rocifier commented Mar 4, 2021

How can I add DeletionPolicy: Retain onto the actual function itself?

@mndeveci
Copy link
Contributor

mndeveci commented Jun 9, 2021

Closing this issue since it is been released with SAM v1.36.0 and SAM CLI v1.24.0.

You can read more about how resource level attributes are handled in SAM via our updated documentation; https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-resource-attributes.html

Thanks!

@mndeveci mndeveci closed this as completed Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants