可以/建议在AWS CodeBuild中使用“ sam build”吗?

scu*_*bbo 5 amazon-web-services aws-codebuild aws-serverless

这个问题的纺出这一个。现在,我对那里的问题有了更好的了解,并且是一个可行的(如果不完美的话)解决方案,我正在提交一个更集中的后续措施(我仍然是StackOverflow的新手,请告诉我是否这违反了礼节,我应该对原文进行跟进)。

该页面建议“ 您使用AWS CodeBuild来构建,本地测试和打包无服务器应用程序 ”。但是,当我在中包含sam build命令时buildspec.yml,我得到以下日志输出,提示sam未在CodeBuild映像上安装:

[Container] 2018/12/31 11:41:49 Running command sam build --use-container 
sh: 1: sam: not found 

[Container] 2018/12/31 11:41:49 Command did not exit successfully sam build --use-container exit status 127 
[Container] 2018/12/31 11:41:49 Phase complete: BUILD Success: false 
[Container] 2018/12/31 11:41:49 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: sam build --use-container. Reason: exit status 127 
Run Code Online (Sandbox Code Playgroud)

此外,如果我使用来安装SAM pip install aws-sam-cli,则sam build --use-container在CodeBuild中运行会给出错误消息sam build本身可以成功,但是由于它没有安装测试依赖项,因此我仍然需要使用pip install -r tests/requirements-test.txt -t .它才能在CodeBuild中运行测试。此外,表明--use-container具有本地编译程序的软件包 ”是必需的。

这使我想知道我是否正在尝试做错什么。在AWS的CI / CD工作流程中构建SAM服务的推荐方法是什么

saz*_*aza 6

2019_10_18 - 更新(确认上面@Spiff 的回答):

显然 Codebuild 现在可以与 SAM 无缝协作,这就是我buildspec.yml使用pandasand的 lambda所需要的psycopg2-binary

version: 0.2

phases:
  install:
    runtime-versions:
      python: 3.7

  pre_build:
    commands:
      - python -m unittest discover tests

  build:
    commands:
      - sam build

  post_build:
    commands:
      - sam package --output-template-file packaged.yaml --s3-bucket my-code-pipeline-bucketz

artifacts:
  type: zip
  files:
    - packaged.yaml
Run Code Online (Sandbox Code Playgroud)

干杯


Lec*_*dal 4

请参阅下文,了解在将AWS SAMAWS CodeBuild结合buildspec.yaml使用时对我有用的方法cloudformation.yml

phases:
  build:
    commands:
      - pip install --user aws-sam-cli
      - USER_BASE_PATH=$(python -m site --user-base)
      - export PATH=$PATH:$USER_BASE_PATH/bin
      - sam build -t cloudformation.yml
      - aws cloudformation package --template-file .aws-sam/build/template.yaml --s3-bucket <TARGET_S3_BUCKET> --output-template-file cloudformation-packaged.yaml
      - aws s3 cp ./cloudformation-packaged.yaml <TARGET_S3_BUCKET>/cloudformation-packaged.yaml   
Run Code Online (Sandbox Code Playgroud)

结果我得到了一个部署包和打包好的cloudformation模板TARGET_S3_BUCKET

对于文件夹中的每个函数./src,我都有一个requirements.txt包含所有依赖项的文件,但我不pip install -r requirements.txt手动运行。