Skip to content

(aws-cognito): UserPool constructor adds an incorrect Lambda permission #19604

@Tietew

Description

@Tietew

What is the problem?

When I specify lambdaTriggers in UserPool, the function's lambda permission should have a SourceArn condition with the UserPool's ARN.

But UserPool constructor adds a lambda permisson without SourceArn condition.
UserPool.addTrigger method adds a correct permission with SourceArn.

This seems to be caused that the constructor code calls addLambdaPermission before assigning this.userPoolArn.

Reproduction Steps

const handler = new lambda.Function(this, 'Handler', { ... });
new cognito.UserPool(this, 'UserPool', {
  lambdaTriggers: {
    postConfirmation: handler,
  },
  ...
});

What did you expect to happen?

Following Lambda::Permission resource is created:

    "HandlerPostConfirmationCognitoXXXXXXXX": {
      "Type": "AWS::Lambda::Permission",
      "Properties": {
        "Action": "lambda:InvokeFunction",
        "FunctionName": {
          "Fn::GetAtt": [
            "HandlerXXXXXXXX",
            "Arn"
          ]
        },
        "Principal": "cognito-idp.amazonaws.com",
        "SourceArn": {
          "Fn::GetAtt": [
            "UserPoolXXXXXXXX",
            "Arn"
          ]
        }
      },
      "Metadata": {
        "aws:cdk:path": "..."
      }
    },

What actually happened?

Following Lambda::Permission resource was created:

    "HandlerPostConfirmationCognitoXXXXXXXX": {
      "Type": "AWS::Lambda::Permission",
      "Properties": {
        "Action": "lambda:InvokeFunction",
        "FunctionName": {
          "Fn::GetAtt": [
            "HandlerXXXXXXXX",
            "Arn"
          ]
        },
        "Principal": "cognito-idp.amazonaws.com"
      },
      "Metadata": {
        "aws:cdk:path": "..."
      }
    },

CDK CLI Version

2.18.0

Framework Version

No response

Node.js Version

14.19.0

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-cognitoRelated to Amazon CognitobugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions