简体   繁体   English

管道无服务器部署在依赖项安装时失败

[英]Pipeline Serverless deploy fails on dependency install

We are using AWS Lambda and I'm trying to automate our deployment.我们正在使用 AWS Lambda,我正在尝试自动化我们的部署。 The serverless-offline package generates an error on serverless build. serverless-offline 包在无服务器构建时生成错误。

This is a multi-endpoint deployment.这是一个多端点部署。 we'll be deploying multiple directories hence the cd console in the pipeline.我们将部署多个目录,因此管道中的cd console We can deploy manually just fine using serverless deploy but my attempts to automate so far have come up empty.我们可以使用无服务器部署手动部署就好了,但到目前为止我的自动化尝试都失败了。

My pipeline.yml我的管道.yml

image: lambci/lambda:build-nodejs6.10
pipelines:
  default:
    - step:
        deployment: test
        script:
          - npm install
          - npm install -g serverless
          - npm install -g serverless-offline
          - npm install -g serverless-domain-manager
          - cd console # will be doing this for multiple directories, but just using one for now
          - serverless plugin install --name serverless-webpack
          - serverless plugin install --name serverless-offline
          - serverless plugin install --name serverless-domain-manager
          - serverless create -t aws-nodejs
          - serverless deploy

my partial serverless.yml for that directory我那个目录的部分 serverless.yml

# Use the serverless-webpack plugin to transpile ES6
plugins:
  - serverless-webpack
  - serverless-offline
  - serverless-domain-manager

# serverless-webpack configuration
# Enable auto-packing of external modules
custom:
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true
  customDomain:

I've tried installing using我试过安装使用

npm install -g serverless-offline

and

- serverless plugin install --name serverless-offline . - serverless plugin install --name serverless-offline

If I miss either of these I get the error如果我错过了其中任何一个,我就会收到错误消息

Serverless plugin "serverless-offline" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file.

but now I get但现在我明白了

Serverless plugin "serverless-offline" initialization errored: Unexpected identifier

when I'm running the serverless create step.当我运行无服务器创建步骤时。

Thanks in advance.提前致谢。

Found the problem, I needed to install serverless globally but npm install inside of the directory:发现问题,我需要全局安装 serverless 但 npm install 在目录内:

          - npm install -g serverless          
          - git log --grep=console
          - cd console
          - npm install

You can also add serverless with your version in devDependencies in package.json file as:您还可以在 package.json 文件中的 devDependencies 中添加无服务器版本:

"devDependencies": {
"serverless": "1.72.0",
 ....
 }

then add a custom command in your scripts section然后在脚本部分添加自定义命令

"scripts": {
  "sls:deploy": "serverless deploy",
   .....
 }

then in your pipeline.yml然后在你的pipeline.yml

- npm i
- npm run sls:deploy

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

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