Can someone help me with a minimal webpack.config.js to get this construct setup with webpack-node-externals?
I'm new to the CDK world and have yet to figure out how to get node_modules to the correct place. Lots of the CDK docs seem to allude to the fact that your repo should be structured in a magic way and your dependencies in package.json are magically bundled / npm installed, but I've not been able to get that to work with TypeScript - I need experimentalDecorators support to be able to use typegraphql.
I can get my code working and deployed with the example webpack.config.js, but my machine is taking around 30 seconds to build code vs. < 3 with webpack-node-externals configured which is making local development a challenge, especially when combined with the slowness of docker and the SAM CLI.
Any ideas on how to improve my iteration time?
The relevant portions of my directory are structured like this:
.
├── cdk.json
├── infrastructure
│ ├── infra-stack.ts
│ └── infra.ts
├── lambda
│ ├── apollo
│ │ ├── graphql.ts
│ │ ├── resolvers
│ │ │ ├── ...
│ │ │ └── ....
├── package.json
├── tsconfig.module.json
├── webpack.config.js
└── yarn.lock
// cdk.json
{
"app": "npx ts-node --project tsconfig.module.json --prefer-ts-exts infrastructure/infra.ts",
"context": {
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true",
"@aws-cdk/core:stackRelativeExports": "true",
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
"@aws-cdk/aws-kms:defaultKeyPolicies": true,
"@aws-cdk/aws-s3:grantWriteWithoutAcl": true,
"@aws-cdk/aws-ecs-patterns:removeDefaultDesiredCount": true,
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
"@aws-cdk/aws-efs:defaultEncryptionAtRest": true,
"@aws-cdk/aws-lambda:recognizeVersionProps": true
}
}
And the actual function definition
const apolloGraphqlLambdaId = `${process.env.TARGET_ENV}ApolloGraphql`;
const apolloGraphqlLambda = new WebpackFunction(
this,
apolloGraphqlLambdaId,
{
functionName: apolloGraphqlLambdaId,
entry: path.join(__dirname, '../lambda/apollo/graphql.ts'),
buildDir: path.join(__dirname, '../.build/lambda'),
handler: 'apolloGraphQLHandler',
runtime: lambda.Runtime.NODEJS_14_X,
config: path.join(__dirname, '../webpack.config.js'),
ensureUniqueBuildPath: process.env.TARGET_ENV !== 'localhost',
timeout: cdk.Duration.seconds(60),
memorySize: 1024,
}
);
Can someone help me with a minimal
webpack.config.jsto get this construct setup withwebpack-node-externals?I'm new to the CDK world and have yet to figure out how to get
node_modulesto the correct place. Lots of the CDK docs seem to allude to the fact that your repo should be structured in a magic way and your dependencies inpackage.jsonare magically bundled /npm installed, but I've not been able to get that to work with TypeScript - I needexperimentalDecoratorssupport to be able to usetypegraphql.I can get my code working and deployed with the example
webpack.config.js, but my machine is taking around 30 seconds to build code vs. < 3 withwebpack-node-externalsconfigured which is making local development a challenge, especially when combined with the slowness of docker and the SAM CLI.Any ideas on how to improve my iteration time?
The relevant portions of my directory are structured like this:
And the actual function definition