sumanth shetty
sumanth shetty

Reputation: 2181

Buildspec.yaml for serverless framework in aws code pipleline

I am trying my hands on CI/CD pipeline for serverless framework.

I had done a similar thing for SAM framework and had got it working. SAM framework has two steps of package and deploy (deploy is handled by cloudformation actions)

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

But I am not so sure how serverless should work. I know serverless had only 'deploy' stage and no package and all.

I don't know how deployment is handled here in CI/CD for serverless. which is giving error at serverless deploy command.

Here is my buildspec.yaml file

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

which is trying to deploy this template:

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

Could anyone help me out with the build and deploy part of this?

Upvotes: 3

Views: 2434

Answers (1)

Marcin
Marcin

Reputation: 238747

Based on the comments and chat discussion.

There were a few issues causing problems:

  1. Missing serverless.yml. It was solved by renaming template.yml into serverless.yml.
  2. Wrong profile in serverless provider. It was addressed by removing it.
  3. Missing permission in CodeBuild role. This was rectified by adding codeformation, s3 and cloudwatch logs permissions to the role.

Upvotes: 1

Related Questions