masahirompp / aws-cdk-webpack-lambda-function Goto Github PK
View Code? Open in Web Editor NEWThis library provides constructs for Node.js Lambda function bundled using webpack.
License: MIT License
This library provides constructs for Node.js Lambda function bundled using webpack.
License: MIT License
Does this construct have a solve for function versioning that takes into account the "builded function code" in order to base the hash off that?
Thanks for this library, it's pretty handy. Any chance you can dedicate sometime to support CDK v2
I see it's a wrapper of lambda constructor, but is anything missing ?
At package.json there are some old versions of aws-cdk
"@aws-cdk/aws-lambda": "^1.33.1",
"@aws-cdk/core": "^1.33.1",
Can you upgrade to the latest 1.47.0 ?
I can make a pull request too, but how can I know if version change breaks something? (any test?)
I'm using a mono-repo, perhaps this is part of the issue. CDK reports there are no stack changes when I have only updated the lambda code.
The library doesn't seem to work on windows environnement. When I cdk synth
with the WebpackFunction
construct:
const func = new WebpackFunction(this,id,{
entry: '../functions/portfolio/src/lambda.ts',
config: '../functions/portfolio/webpack.config.js'
})
I get this weird error:
Error: spawnSync C:\serverless-rest-api-typescript\cdk\node_modules\webpack-cli\bin\cli.js UNKNOWN
at Object.spawnSync (internal/child_process.js:1041:20)
at Object.spawnSync (child_process.js:616:24)
at Builder.build (C:\serverless-rest-api-typescript\cdk\node_modules\aws-cdk-webpack-lambda-function\lib\builder.js:29:41)
at preProcess (C:\serverless-rest-api-typescript\cdk\node_modules\aws-cdk-webpack-lambda-function\lib\function.js:60:13)
at new WebpackFunction (C:\serverless-rest-api-typescript\cdk\node_modules\aws-cdk-webpack-lambda-function\lib\function.js:14:66)
at new PortfolioCRUDRestAPI (C:\serverless-rest-api-typescript\cdk\lib\portfolio-crud-api.ts:21:22)
at new AppStack (C:\serverless-rest-api-typescript\cdk\lib\app-stack.ts:8:5)
at Object.<anonymous> (C:\serverless-rest-api-typescript\cdk\bin\cdk.ts:7:1)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Module.m._compile (C:\serverless-rest-api-typescript\cdk\node_modules\ts-node\src\index.ts:858:23)
Any ideas on this? If I make the dir ahead of time, there's no issue, but I don't think I should have to?
ENOENT: no such file or directory, stat '/path/to/my/src/.build/91ab6e0cbf68bb050912bfa74de0d9c607e86930fc1685e4d90b08e21e445da9'
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 instal
led, 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,
}
);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.