首页 > 解决方案 > 用于 aws 代码管道中的无服务器框架的 Buildspec.yaml

问题描述

我正在尝试使用无服务器框架的 CI/CD 管道。

我为 SAM 框架做了类似的事情并让它工作。SAM框架有打包和部署两个步骤(部署由cloudformation操作处理)

version: 0.2
phases:
  install:
    runtime-versions:
        nodejs: 10
        #trying after adding the art effect in code deploy  
  build:
    commands:
      - npm install time
      - export BUCKET=lambda-loadeo-git
      - aws cloudformation package --template-file template.yml --s3-bucket $BUCKET --output-template-file outputtemplate.yml
artifacts:
  type: zip
  files:
    - template.yml
    - outputtemplate.yml

但我不太确定无服务器应该如何工作。我知道无服务器只有“部署”阶段,没有包等等。

我不知道如何在 CI/CD 中为无服务器处理部署。这在无服务器部署命令中给出错误。

这是我的 buildspec.yaml 文件

version: 0.1
phases:
  install:
    commands:
      - npm install
      - npm install -g mocha
      - npm install -g serverless
  build:
    commands:
      - serverless deploy 
  post_build:
    commands:

      - echo build complete

正在尝试部署此模板:

service: serverless
frameworkVersion: '2'

provider:
  name: aws
  runtime: python2.7
  profile: default 


functions:
  getInfo:
    handler: handler.getInfo
    events:
     - http:
        path: users/info
        method: get

  createInfo:
    handler: handlerpost.createInfo
    events:
     - http:
        path: users/create
        method: post

  patchInfo:
    handler: handlerpatch.patchInfo
    events:
     - http:
        path: users/update
        method: patch

任何人都可以帮助我构建和部署其中的一部分吗?

标签: amazon-web-servicesserverless-frameworkaws-codepipelineaws-code-deployaws-codebuild

解决方案


基于评论和聊天讨论。

几个问题导致问题:

  1. 失踪serverless.yml。通过重命名template.ymlserverless.yml.
  2. 无服务器提供商中的配置文件错误。已通过将其删除来解决。
  3. CodeBuild 角色中缺少权限。这已通过向角色添加 codeformation、s3 和 cloudwatch 日志权限得到纠正。

推荐阅读