You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 05:59:55