Hi everyone! I’m trying to setup cognito with a c...
# help
m
Hi everyone! I’m trying to setup cognito with a custom domain and getting the following error. Does anyone have any idea what might be going wrong? Currently on SST: 0.53.0 & CDK: 1.132.0
Copy code
Error: Cannot find asset at ---/.build/lib/runtime
    at new AssetStaging (---/node_modules/@aws-cdk/core/lib/asset-staging.ts:113:13)
    at new Asset (---/node_modules/@aws-cdk/aws-s3-assets/lib/asset.ts:68:21)
    at AssetCode.bind (---/node_modules/@aws-cdk/aws-lambda/lib/code.ts:183:20)
    at new Function2 (---/node_modules/@aws-cdk/aws-lambda/lib/function.ts:338:29)
    at SingletonFunction.ensureLambda (---/node_modules/@aws-cdk/aws-lambda/lib/singleton-lambda.ts:93:12)
    at new SingletonFunction (---/node_modules/@aws-cdk/aws-lambda/lib/singleton-lambda.ts:32:32)
    at new AwsCustomResource (---/node_modules/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts:194:22)
    at UserPoolDomain2.get cloudFrontDomainName [as cloudFrontDomainName] (---/node_modules/@aws-cdk/aws-cognito/lib/user-pool-domain.ts:98:39)
    at UserPoolDomainTarget2.bind (---/node_modules/@aws-cdk/aws-route53-targets/lib/userpool-domain.ts:12:28)
    at new RecordSet (---/node_modules/@aws-cdk/aws-route53/lib/record-set.ts:124:73)
My code looks something like this:
Copy code
const hostedZone = HostedZone.fromHostedZoneAttributes(this, 'HostedZone', {
      hostedZoneId: process.env.SYSTEM_HOSTEDZONE_ID,
      zoneName: process.env.SYSTEM_HOSTEDZONE_DOMAIN
    });

const userPool = new UserPool(this, 'UserPool', {
      userPoolName: scope.stage && '-test-userPool',
      selfSignUpEnabled: true,
      signInAliases: {
        email: true,
      },
      autoVerify: {
        email: true,
      },
      standardAttributes: {
        givenName: {
          required: true,
          mutable: true,
        },
        familyName: {
          required: true,
          mutable: true,
        },
      },
      customAttributes: {
        country: new StringAttribute({mutable: true}),
        city: new StringAttribute({mutable: true}),
        isAdmin: new StringAttribute({mutable: true}),
      },
      passwordPolicy: {
        minLength: 6,
        requireLowercase: true,
        requireDigits: true,
        requireUppercase: false,
        requireSymbols: false,
      },
      accountRecovery: AccountRecovery.EMAIL_ONLY,
      removalPolicy: removalPolicy,
    });

const userPoolClient = new UserPoolClient(this, "UserPoolClient", {
      userPool,
      disableOAuth: true,
    });

this.auth = new Auth(this, "Auth", {
      cognito: {
        userPool: userPool,
        userPoolClient: userPoolClient,
      },
    });

const userPoolDomain = new UserPoolDomain(this, "AuthDomain",{
      userPool: userPool,
      customDomain: {
        certificate: Certificate.fromCertificateArn(this, "AuthCert", process.env.SYSTEM_AUTH_CERT),
        domainName: process.env.SYSTEM_AUTH_DOMAIN,
      }
    });

    new ARecord(this, 'UserPoolCloudFrontAliasRecord', {
      zone: hostedZone,
      recordName: process.env.SYSTEM_AUTH_DOMAIN,
      target: RecordTarget.fromAlias(new UserPoolDomainTarget(userPoolDomain)),
    });
If I remove the ARecord part it deploys, so I’m getting the feeling it’s something stupid that I’m not seeing… 🤷‍♂️
Apparently I was missing the “@aws-cdk/aws-cognito” in my package.json 🤭
f
Ah nice.. was going to suggest that
Good news is that AWS CDK v2 is going to come out soon, and it will be a single package with all cdk modules. It will make the life much easier 🙂