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

Transform fails when DeletionProtection specified in AWS::Cognito::UserPool with Cognito event #2581

Closed
jjaimez opened this issue Nov 8, 2022 · 13 comments
Labels

Comments

@jjaimez
Copy link

jjaimez commented Nov 8, 2022

Describe your idea/feature/enhancement

I wish the SAM Translator would support DeletionProtection in Cognito User Pool definition.

Proposal

MyUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      DeletionProtection: ACTIVE

Things to consider:

Additional Details

I tried to do it and i got the following error.
property DeletionProtection not defined for resource of type AWS::cognito::UserPool

@jjaimez jjaimez added stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/feature labels Nov 8, 2022
@jjaimez jjaimez changed the title Feature request: TITLE Feature request: Support for DeletionProtection in Cognito User Pool definition. Nov 8, 2022
@xazhao
Copy link
Contributor

xazhao commented Nov 14, 2022

Thanks for the feature request. I will discuss this with the team and post updates here.

@ssenchenko
Copy link
Contributor

DeletionProtection seems to be quite a fresh feature. The blog which mentions it, is dated of Oct 2022.
It explains why DeletionProtection is not currently supported by CloudFormation https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpool.html#cfn-cognito-userpool-deletionprotection
We can add it after CloudFormation starts supporting it.

@ssenchenko
Copy link
Contributor

Feel free to reopen this issue if you notice that CloudFormation has started to support this property

@ssenchenko ssenchenko removed the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Nov 17, 2022
@benconnito
Copy link

still seeing the error when adding the DeletionProtection to a user pool

Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [AuthUserPool] is invalid. property DeletionProtection not defined for resource of type AWS::Cognito::UserPool

@JP-tech-sh
Copy link

I'm using SAM CLI to version 1.76.0, I identified that according to Cloud formation docs this feature should be supported. However, if you don't use the Ref build in cloud formation function to refer to the cognito user pool anywhere in the template, it'll work fine. Surprisingly, if you add at least one instance of Ref to a cognito user pool with DeletionProtection enabled, it will show this error. In my case, I'm using cognito events on lambda resources that need a reference to a cognito user pool in the template. If using this particular configuration, it will fail with the error mentioned above. I guess is a very similar use case for the other devs reporting this issue. Please let me know if I can provide additional details or if you recommend that I open a separated issue for this. As a temporary solution, I removed the DeletionProtection from my user pool, but this is risky on a production scenario.

@hoffa hoffa reopened this Mar 14, 2023
@hoffa
Copy link
Contributor

hoffa commented Mar 14, 2023

@jjaimez @benconnito Could you clarify what the ask is?

AWS::Cognito::UserPool supports DeletionProtection:

Transform: AWS::Serverless-2016-10-31
Parameters:
  DeletionProtection:
    Type: String
    Default: ACTIVE
Resources:
  MyUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      DeletionProtection: !Ref DeletionProtection

Deploy:

sam deploy --region us-west-2 --resolve-s3 --capabilities CAPABILITY_IAM --stack-name test-deletion-protection --template template.yaml

@hoffa
Copy link
Contributor

hoffa commented Mar 14, 2023

@JP-tech-sh Would you be able to provide a template reproducing the issue?

@JP-tech-sh
Copy link

@hoffa Yes, I'll provide a minimal working template reproducing the issue, so you can test it. I'll try to have it ready for today.

@benconnito
Copy link

benconnito commented Mar 14, 2023

i am actually unable to get NEW cognito domains (wether initially inactive or active) to have the issue. however updating an existing cognito domain (created BEFORE the deletion protection feature) to have deletion protection seems to fail

all i added to my existing cognito resource in cloudformation was

DeletionProtection: !If [IsProd, 'ACTIVE', 'INACTIVE']

and its actually failing for our staging cognito to update it to INACTIVE (it is not active atm)

@hoffa hoffa added the blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. label Mar 17, 2023
@JP-tech-sh
Copy link

Hello, this is the example sam project showing the error, sorry about the delay. https://github.com/JP-tech-sh/deletion-protection-sam-error
To run the project.
sam build --beta-features --cached
sam deploy --guided

@hoffa
Copy link
Contributor

hoffa commented Mar 17, 2023

Hello, this is the example sam project showing the error, sorry about the delay. https://github.com/JP-tech-sh/deletion-protection-sam-error To run the project. sam build --beta-features --cached sam deploy --guided

Thanks a lot for this, I was able to reproduce.

Here's a minimal example. Save as template.yaml:

Transform: AWS::Serverless-2016-10-31
Resources:
  MyUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      DeletionProtection: ACTIVE

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.8
      InlineCode: foo
      Handler: bar
      Events:
        CognitoEvent:
          Type: Cognito
          Properties:
            Trigger: CustomMessage
            UserPool: !Ref MyUserPool

Creating the change set will fail with:

Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyUserPool] is invalid. property DeletionProtection not defined for resource of type AWS::Cognito::UserPool

If you remove the Cognito event, it succeeds:

Transform: AWS::Serverless-2016-10-31
Resources:
  MyUserPool:
    Type: AWS::Cognito::UserPool
    Properties:
      DeletionProtection: ACTIVE

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.8
      InlineCode: foo
      Handler: bar

@hoffa hoffa added type/bug and removed type/feature blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. labels Mar 17, 2023
@hoffa hoffa changed the title Feature request: Support for DeletionProtection in Cognito User Pool definition. Transform fails when DeletionProtection specified in AWS::Cognito::UserPool with Cognito event Mar 17, 2023
@hoffa
Copy link
Contributor

hoffa commented Mar 17, 2023

I've created a fix for this in #3041. I'll also look into a more longer-term fix so these issues don't occur for every new property.

@hoffa
Copy link
Contributor

hoffa commented Mar 18, 2023

I'll close this since #3041 is merged; it'll roll out over the coming weeks. I've opened #3042 for the longer-term issue.

@hoffa hoffa closed this as completed Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants