amplify-backend icon indicating copy to clipboard operation
amplify-backend copied to clipboard

Support for setting PreTokenGeneration to v2_0

Open Zhuohui-Li opened this issue 9 months ago • 1 comments

Environment information

System:
  OS: macOS 14.4
  CPU: (10) arm64 Apple M1 Pro
  Memory: 155.80 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.12.2 - /private/var/folders/h8/0sklzj9n1pz2zjt34vl3t15w0000gn/T/xfs-94f2b395/node
  Yarn: 4.1.1 - /private/var/folders/h8/0sklzj9n1pz2zjt34vl3t15w0000gn/T/xfs-94f2b395/yarn
  npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/backend: Not Found
  @aws-amplify/backend-cli: 0.16.0
  aws-amplify: Not Found
  aws-cdk: Not Found
  aws-cdk-lib: Not Found
  typescript: Not Found
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

Currently, the amplify backend doesn't support configuring the PreTokenGeneration trigger to v2_0 directly like

export const auth = defineAuth({
 //...
  triggers:{
    preTokenGeneration:{
      resource: preTokenGeneration,
      version:"v2_0"
    }
  }

Zhuohui-Li avatar May 01 '24 13:05 Zhuohui-Li

Hey @Zhuohui-Li, thank you for reaching out. we can override the auth resource to enable this as follows

import * as cognito from "aws-cdk-lib/aws-cognito";

const backend = defineBackend({
  auth,
  data,
  preTokenGenerationTrigger
});

backend.auth.resources.cfnResources.cfnUserPool.userPoolAddOns = {
  advancedSecurityMode: 'ENFORCED'
}

const userpool = backend.auth.resources.userPool as cognito.UserPool
userpool.addTrigger(
  cognito.UserPoolOperation.PRE_TOKEN_GENERATION_CONFIG,
  backend.preTokenGenerationTrigger.resources.lambda,
  cognito.LambdaVersion.V2_0
);

marking this as feature request

ykethan avatar May 01 '24 20:05 ykethan