aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
185 stars 62 forks source link

Circular Error when use custom message via AWS Amplify trigger #2247

Open dukeho1996 opened 2 days ago

dukeho1996 commented 2 days ago

Environment information

System:
  OS: macOS 15.0.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 141.30 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 22.9.0 - ~/.nvm/versions/node/v22.9.0/bin/node
  Yarn: 1.22.22 - ~/.yarn/bin/yarn
  npm: 10.8.3 - ~/.nvm/versions/node/v22.9.0/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.5.0
  @aws-amplify/backend: 1.7.0
  @aws-amplify/backend-auth: 1.4.0
  @aws-amplify/backend-cli: 1.4.2
  @aws-amplify/backend-data: 1.2.0
  @aws-amplify/backend-deployer: 1.1.9
  @aws-amplify/backend-function: 1.7.5
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.3
  @aws-amplify/backend-secret: 1.1.5
  @aws-amplify/backend-storage: 1.2.2
  @aws-amplify/cli-core: 1.2.0
  @aws-amplify/client-config: 1.5.2
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.9
  @aws-amplify/platform-core: 1.2.0
  @aws-amplify/plugin-types: 1.4.0
  @aws-amplify/sandbox: 1.2.5
  @aws-amplify/schema-generator: 1.2.5
  aws-amplify: 6.8.2
  aws-cdk: 2.167.1
  aws-cdk-lib: 2.167.1
  typescript: 5.6.3
No AWS environment variables
No CDK environment variables

Describe the bug

Hi, I want to send a temporary password and the verification code in the email. I'm using the signUp function from aws-amplify/auth to create a new user and set the 'custom:temporaryPassword' attribute.

I'm also using the defineAuth function from @aws-amplify/backend to define and configure auth resource. In this configuration, I have described the 'custom:temporaryPassword' attribute as a custom user attribute and set the customMessage trigger to a custom Lambda function customSignUpEmail/resource.

import { defineAuth } from '@aws-amplify/backend';
import { customMessage as customMessageLambda } from './customSignUpEmail/resource';

export const auth = defineAuth({
  loginWith: {
    email: true,
  },
  groups: ['MERCHANT_ADMIN', 'MERCHANT_VIEWER'],
  userAttributes: {
    'custom:temporaryPassword': {
      dataType: 'String',
    },
  },
  triggers: {
    customMessage: customMessageLambda,
  },
});

However, I get this error failed: ValidationError: Circular dependency between resources: [storage0EC3F24A, auth179371D7, data7552DF31, CustomVerifiedPermissions4A29311F, function1351588B, AmplifyStack7460781E]

I attached my backend.ts here message.txt

Reproduction steps

Run npx ampx sandbox --profile wlnzportalsdev --debug --once Circular error will show up