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_cognito: lambd trigger version #28683

Closed
2 tasks
tcvall86 opened this issue Jan 12, 2024 · 5 comments · Fixed by #28899
Closed
2 tasks

aws_cognito: lambd trigger version #28683

tcvall86 opened this issue Jan 12, 2024 · 5 comments · Fixed by #28899
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@tcvall86
Copy link

tcvall86 commented Jan 12, 2024

Describe the feature

Now that cognito officially supports modification of access tokens by using lambda version 2 it would be great if the addTrigger functionality could support this. If this is already supported but undocumented maybe just an update to the docs are needed

https://aws.amazon.com/about-aws/whats-new/2023/12/amazon-cognito-user-pools-customize-access-tokens/

https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-token-generation.html

From the second link:
To support access token customization in a pre token generation Lambda trigger

Generate a CreateUserPool or UpdateUserPool API request. You must specify a value for all parameters that you don't want set to a default value. For more information, see Updating user pool configuration.

Include the following content in the LambdaVersion parameter of your request. A LambdaVersion value of V2_0 causes your user pool to add parameters for access token customization. To invoke a specific function version, use a Lambda function ARN with a function version as the value of LambdaArn.

"PreTokenGenerationConfig": { 
   "LambdaArn": "arn:aws:lambda:us-west-2:123456789012:function:MyFunction",
   "LambdaVersion": "V2_0"
}

this is also supported in cloudformation

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-pretokengenerationconfig.html

  LambdaArn: String
  LambdaVersion: String

Use Case

Instead of writing custom code to update this or call the cfn resource and add logic for the updates it would make a lot of sense if this was supported natively with cdk addTrigger function

Proposed Solution

Update add trigger to support input of version string like

(method) UserPool.addTrigger(operation: cdk.aws_cognito.UserPoolOperation, fn: cdk.aws_lambda.IFunction, lambdaVersion: string): void

It should default to V1_0 if not set and it should only be evaluated if the operation ins PRE_TOKEN_GENERATION

userPool.addTrigger(cognito.UserPoolOperation.PRE_TOKEN_GENERATION, lambda.Function.fromFunctionArn(
      this,
      'PreTokenGenerationLambda',
      `arn:aws:lambda:${props.env?.region}:${props.env?.account}:function:MyFunction`
    ),"V2_0");

An alternate approach would be to do this on the userpool trigger config in the userpool
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cognito.UserPoolTriggers.html
ie change the
preTokenGeneration? from iFunction to be a construct with iFunction and version string

(property) UserPoolTriggers.preTokenGenerationConfig?: cdk.aws_cognito.PreTokenGenerationConfig | undefined 

This seem somewhat prepared because you can set the value to preTokenGenerationConfig but it only expects a IFunction

(property) preTokenGenerationConfig: cdk.aws_lambda.IFunction

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.119.0

Environment details (OS name and version, etc.)

macOS 14.2.1 (23C71)

@tcvall86 tcvall86 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 12, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cognito Related to Amazon Cognito label Jan 12, 2024
@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 16, 2024
@pahud
Copy link
Contributor

pahud commented Jan 16, 2024

Thank you for the feature request. We welcome any pull requests for this from the community.

@caosDvlp
Copy link

Hey!

I have the same needs here with the Python AWS CDK. Hope this is updated! ;)

@tcvall86
Copy link
Author

I have the same needs here with the Python AWS CDK. Hope this is updated! ;)

Just throwing in something here. If you are blocked and just want to go forward with new you could try to create the cfn resource first (typescript example below)

const cfnUserPool = new cognito.CfnUserPool(this, 'CfnUserPool', {
      userPoolName: `userPoolName`,
      userPoolAddOns: {
        advancedSecurityMode: cognito.AdvancedSecurityMode.AUDIT
      },
      lambdaConfig: {
        preTokenGenerationConfig: {
          lambdaArn: `yourlambdarn`,
          lambdaVersion: 'V2_0'
        }
      }
      // ....
      // if you need to add other things like clients etc you can export / import it into the stack
      const userPool = cognito.UserPool.fromUserPoolId(this, 'UserPool', cfnUserPool.ref)

It will require recreation of the userPool though if it is an existing one and is not the nicest, but if it is a new thing it may be worth it

@caosDvlp
Copy link

I have the same needs here with the Python AWS CDK. Hope this is updated! ;)

Just throwing in something here. If you are blocked and just want to go forward with new you could try to create the cfn resource first (typescript example below)

const cfnUserPool = new cognito.CfnUserPool(this, 'CfnUserPool', {
      userPoolName: `userPoolName`,
      userPoolAddOns: {
        advancedSecurityMode: cognito.AdvancedSecurityMode.AUDIT
      },
      lambdaConfig: {
        preTokenGenerationConfig: {
          lambdaArn: `yourlambdarn`,
          lambdaVersion: 'V2_0'
        }
      }
      // ....
      // if you need to add other things like clients etc you can export / import it into the stack
      const userPool = cognito.UserPool.fromUserPoolId(this, 'UserPool', cfnUserPool.ref)

It will require recreation of the userPool though if it is an existing one and is not the nicest, but if it is a new thing it may be worth it

Thank you! I will take a look!

@mergify mergify bot closed this as completed in #28899 Feb 2, 2024
mergify bot pushed a commit that referenced this issue Feb 2, 2024
…igger() (#28899)

I have added a `lambdaVersion` to the `UserPool.addTrigger()`. 
This is in response to the [support for V2.0 trigger event in preTokenGeneration](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-token-generation.html).

```ts
declare const userpool: cognito.UserPool;
declare const preTokenGenerationFn: lambda.Function;

userpool.addTrigger(cognito.UserPoolOperation.PRE_TOKEN_GENERATION_CONFIG, preTokenGenerationFn, LambdaVersion.V2_0);
```

In #28683, apart from the current implementation approach, there was also a proposal to add `lambdaVersion` to `UserPoolProps.lambdaTrigger`. However, it was not adopted as it would result in a breaking change.

Closes #28683

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

github-actions bot commented Feb 2, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

SankyRed pushed a commit that referenced this issue Feb 8, 2024
…igger() (#28899)

I have added a `lambdaVersion` to the `UserPool.addTrigger()`. 
This is in response to the [support for V2.0 trigger event in preTokenGeneration](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-token-generation.html).

```ts
declare const userpool: cognito.UserPool;
declare const preTokenGenerationFn: lambda.Function;

userpool.addTrigger(cognito.UserPoolOperation.PRE_TOKEN_GENERATION_CONFIG, preTokenGenerationFn, LambdaVersion.V2_0);
```

In #28683, apart from the current implementation approach, there was also a proposal to add `lambdaVersion` to `UserPoolProps.lambdaTrigger`. However, it was not adopted as it would result in a breaking change.

Closes #28683

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TheRealAmazonKendra pushed a commit that referenced this issue Feb 9, 2024
…igger() (#28899)

I have added a `lambdaVersion` to the `UserPool.addTrigger()`. 
This is in response to the [support for V2.0 trigger event in preTokenGeneration](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-token-generation.html).

```ts
declare const userpool: cognito.UserPool;
declare const preTokenGenerationFn: lambda.Function;

userpool.addTrigger(cognito.UserPoolOperation.PRE_TOKEN_GENERATION_CONFIG, preTokenGenerationFn, LambdaVersion.V2_0);
```

In #28683, apart from the current implementation approach, there was also a proposal to add `lambdaVersion` to `UserPoolProps.lambdaTrigger`. However, it was not adopted as it would result in a breaking change.

Closes #28683

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants