aws 代码管道中无服务器框架的 Buildspec.yaml [英] Buildspec.yaml for serverless framework in aws code pipleline
问题描述
我正在尝试使用无服务器框架的 CI/CD 管道.
I am trying my hands on CI/CD pipeline for serverless framework.
我为 SAM 框架做了类似的事情,并且让它工作了.SAM框架有打包和部署两个步骤(部署由cloudformation action处理)
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.
我不知道在 CI/CD 中如何处理无服务器部署.在无服务器部署命令中出错.
I don't know how deployment is handled here in CI/CD for serverless. which is giving error at serverless deploy command.
这是我的 buildspec.yaml 文件
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
正在尝试部署此模板:
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?
推荐答案
基于评论和聊天讨论.
有一些问题导致了问题:
- 缺少
serverless.yml
.通过将template.yml
重命名为serverless.yml
解决了这个问题. - 无服务器提供程序中的配置文件错误.已通过删除它得到解决.
- 缺少 CodeBuild 角色的权限.这已通过向角色添加 codeformation、s3 和 cloudwatch 日志权限得到纠正.
- Missing
serverless.yml
. It was solved by renamingtemplate.yml
intoserverless.yml
. - Wrong profile in serverless provider. It was addressed by removing it.
- Missing permission in CodeBuild role. This was rectified by adding codeformation, s3 and cloudwatch logs permissions to the role.
这篇关于aws 代码管道中无服务器框架的 Buildspec.yaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!