We’ve been having a little bit of a problem with C...
# help
g
We’ve been having a little bit of a problem with Cognito, where the deployer is looking for additional CDK files which are not being copied into the build directory. We are using CDK natively to create a user pool, client, and a custom auth domain with dns validated certificate and route53 A record. In order to make it work, we’ve had to manually sync some of these CDK resources into the build dir, ie,
Copy code
function syncCdkResourceLambdaPackages(buildDir: string) {
  const lambdaPackagesPath = path.resolve(process.cwd(), buildDir, 'lambda-packages');
  fs.mkdirSync(lambdaPackagesPath, { recursive: true });
  const awsCdkLambdaPackages = glob.sync("node_modules/@aws-cdk/**/lambda-packages");
  awsCdkLambdaPackages.forEach(packagePath => fs.copySync(packagePath, lambdaPackagesPath, { preserveTimestamps: true }))
}

function syncCdkCustomResourceRuntime(buildDir: string) {
  const runtimePath = path.resolve(process.cwd(), buildDir, 'lib', 'runtime');
  fs.mkdirSync(runtimePath, { recursive: true });
  const sdkApiMetadataPath = path.resolve(process.cwd(), buildDir, 'lib', 'sdk-api-metadata.json');
  fs.copySync("node_modules/@aws-cdk/custom-resources/lib/aws-custom-resource/runtime", runtimePath, { preserveTimestamps: true })
  fs.copyFileSync("node_modules/@aws-cdk/custom-resources/lib/aws-custom-resource/sdk-api-metadata.json", sdkApiMetadataPath)
}
Here’s one error trace:
Copy code
Error: Cannot find asset at demo_1/.build/lib/runtime
    at new AssetStaging (demo_1/node_modules/@aws-cdk/core/lib/asset-staging.ts:113:13)
    at new Asset (demo_1/node_modules/@aws-cdk/aws-s3-assets/lib/asset.ts:68:21)
    at AssetCode.bind (demo_1/node_modules/@aws-cdk/aws-lambda/lib/code.ts:183:20)
    at new Function3 (demo_1/node_modules/@aws-cdk/aws-lambda/lib/function.ts:331:29)
    at SingletonFunction.ensureLambda (demo_1/node_modules/@aws-cdk/aws-lambda/lib/singleton-lambda.ts:93:12)
    at new SingletonFunction (demo_1/node_modules/@aws-cdk/aws-lambda/lib/singleton-lambda.ts:32:32)
    at new AwsCustomResource (demo_1/node_modules/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts:194:22)
    at UserPoolDomain.get cloudFrontDomainName [as cloudFrontDomainName] (demo_1/node_modules/@aws-cdk/aws-cognito/lib/user-pool-domain.ts:98:39)
    at UserPoolDomainTarget2.bind (demo_1/node_modules/@aws-cdk/aws-route53-targets/lib/userpool-domain.ts:12:28)
    at new RecordSet (demo_1/node_modules/@aws-cdk/aws-route53/lib/record-set.ts:124:73)
t
hm I use the navice cdk userpool/client stuff and I didn't have to do anything special
ah wait are they deploying a function on your behalf or something?
We have this isssue in a few places
k
+1 for this issue. Seems to be a problem for any AwsCustomResource. Thanks @Guy Shechter for the workaround
g
Thanks @Kelly Davis just had to do the same for another resource as well:
Copy code
function syncCdkResourceLambdaPackages(buildDir) {
  const lambdaPackagesPath = path.resolve(process.cwd(), buildDir, 'lib/lambda');
  fs.mkdirSync(lambdaPackagesPath, { recursive: true });
  const awsCdkLambdaPackages = glob.sync("node_modules/@aws-cdk/aws-s3/lib/notifications-resource/lambda/");
  awsCdkLambdaPackages.forEach(packagePath => fs.copySync(packagePath, lambdaPackagesPath, { preserveTimestamps: true }))
}