适用于AWS Code Pipleline中无服务器框架的Buildspec.yaml

时间:2020-09-17 08:09:19

标签: amazon-web-services serverless-framework aws-codepipeline aws-code-deploy aws-codebuild

我正在尝试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

有人可以帮助我进行构建和部署吗?

1 个答案:

答案 0 :(得分:1)

基于评论和聊天讨论。

几个问题引起了问题:

  1. 缺少serverless.yml。通过将template.yml重命名为serverless.yml可以解决此问题。
  2. 无服务器提供程序中的配置文件错误。通过删除它来解决。
  3. 缺少CodeBuild角色的权限。通过向角色添加代码格式,s3和cloudwatch日志权限来纠正此问题。
相关问题