简体   繁体   English

AWS Lambda GitLab CI/CD 部署 package 大小比从我的本地环境部署大得多

[英]AWS Lambda GitLab CI/CD deployment package size is much bigger than deploy from my local environment

I set up GitLab CI/CD for deploying a Node.js Lambda to AWS.我设置了 GitLab CI/CD 以将 Node.js Lambda 部署到 AWS。 However the zipped package size is 42.01MB when deployed by GitLab. But from my local PC the package size is only 10.72MB.但是,当 GitLab 部署时,压缩后的 package 大小为 42.01MB。但是从我的本地 PC 上看,package 大小只有 10.72MB。 Same command is used for deployment.相同的命令用于部署。

The .gitlab-ci.yml has the following setup .gitlab-ci.yml具有以下设置

image: node:latest

stages:
  - test
  - deploy_dev

test:
  stage: test
  script:
    - npm install
    - npm test

dev:
    stage: deploy_dev
    before_script:
        - FAILURE_MESSAGE="Must define \$AWS_ACCESS_KEY_ID and \$AWS_SECRET_ACCESS_KEY. Add keys to $CI_PROJECT_URL/-/settings/ci_cd"
        - test -z "$AWS_SECRET_ACCESS_KEY" && echo $FAILURE_MESSAGE && exit 1
        - test -z "$AWS_ACCESS_KEY_ID" && echo $FAILURE_MESSAGE && exit 1
        - npm config set prefix /usr/local
        - npm install -g serverless
    script:
        - npm install
        - npm run deploy -- --stage dev --verbose
    environment: dev
    only: 
        - master

And the package.json is as followspackage.json如下

{
  "name": "test app",
  "version": "1.0.0",
  "description": "",
  "main": "handler.js",
  "scripts": {
    "test": "jest",
    "deploy": "serverless deploy"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "dependencies": {
    "aws-sdk": "^2.754.0",
    "cheerio": "^1.0.0-rc.3",
    "logplease": "^1.2.15",
    "node-fetch": "^2.6.1"
  },
  "devDependencies": {
    "jest": "^26.6.1",
    "serverless-offline": "^6.7.0",
    "serverless-offline-direct-lambda": "0.0.1"
  }
}

Output from GitLab: Output 来自 GitLab:

$ npm install
added 725 packages, and audited 725 packages in 19s
found 0 vulnerabilities
$ npm run deploy -- --stage dev --verbose
> test-app@1.0.0 deploy
> serverless deploy "--stage" "dev" "--verbose"
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service test-app.zip file to S3 (42.01 MB)...

Local output本地 output

added 725 packages from 598 contributors and audited 725 packages in 12.388s

45 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities



Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service test-app.zip file to S3 (10.72 MB)...

It seems like the dev dependencies are NOT excluded although the logs says Excluding development dependencies... .尽管日志显示Excluding development dependencies... ,但似乎并未排除 dev 依赖关系。

Does anyone have any ideas on why the package size is different?有没有人知道为什么 package 大小不同?

Thanks in advance!提前致谢!

  • First of all please move the aws-sdk to dev dependencies.首先,请将aws-sdk移至开发依赖项。 It is already installed in the AWS lambda container.它已安装在 AWS lambda 容器中。

  • Second, you may also use serverless plugin - serverless-webpack for more decreasing the size of lambda.其次,您还可以使用无服务器插件 - serverless-webpack来进一步减小 lambda 的大小。

Besides that, I cannot notice anything significant what may cause the build size to be different:(除此之外,我没有注意到任何可能导致构建大小不同的重要内容:(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM