NestedStack中使用NodejsFunction遇解压大小超限错误求助
CDK嵌套栈中NodejsFunction部署报错:包大小超限问题
我正在用CDK创建一个作为嵌套栈(NestedStack)的L3 Construct,其中包含Lambda函数等资源。我们日常大量使用NodejsFunction,依赖其esbuild功能进行函数打包,但在嵌套栈内创建NodejsFunction时,出现如下错误:
Unzipped size must be smaller than 262144000 bytes
将该NodejsFunction移至父栈则可正常部署,且该函数实际包大小仅为3KB,未使用Layers,CDK为最新版本。目前使用基础的Function构造在嵌套栈内可正常部署,但不符合我们的栈结构需求。
嵌套栈内可正常运行的基础Function构造
this.lambda = new lambda.Function(this, 'ConsumerExampleLambda', { functionName: `consumer-${name}`, memorySize: 1024, runtime: Runtime.NODEJS_18_X, handler: 'handler', environment: {}, code: lambda.Code.fromInline(` exports.handler = async (event) => { console.log('Received event:', JSON.stringify(event, null, 2)); return event; }; `), });
嵌套栈内报错的NodejsFunction构造
this.lambda = new NodejsFunction(this, 'ConsumerExampleLambda', { functionName: `consumer-${name}`, memorySize: 1024, runtime: Runtime.NODEJS_18_X, handler: 'handler', bundling: { logLevel: LogLevel.WARNING, target: 'es2020', externalModules: [ '@nestjs/microservices', '@nestjs/microservices/microservices-module', '@nestjs/websockets/socket-module', ], }, entry: bundling.entry, });
内容的提问来源于stack exchange,提问作者Reece
相关产品推荐
相关产品推荐

