问题描述
此问题来自.现在,我对那里的问题有了更好的了解,并且可行的(如果不完善的话)解决方案,提交更具针对性的后续措施(我仍然是StackOverflow的新手-请告诉我这是否违反礼节,我应该跟进原始内容).
This question spun out of this one. Now that I have a better understanding of what was going wrong there, and a workable, if imperfect, solution, I'm submitting a more focused follow-up (I'm still something of a novice at StackOverflow - please let me know if this contravenes etiquette, and I should follow-up on the original).
此页面建议"您使用AWS CodeBuild来构建,本地测试和打包无服务器应用程序".但是,当我在 buildspec.yml
中包含 sam build
命令时,我得到以下日志输出,提示未在 sam
上安装CodeBuild图片:
This page suggests that "You use AWS CodeBuild to build, locally test, and package your serverless application". However, when I include a sam build
command in my buildspec.yml
, I get the following log output, suggesting that sam
is not installed on CodeBuild images:
[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
此外,如果我使用 pip install aws-sam-cli
安装SAM,则在CodeBuild中运行 sam build --use-container
会给出错误. sam build
本身可以成功,但是由于它没有安装测试依赖项,因此我仍然需要使用 pip install -r tests/requirements-test.txt -t.
以便能够在CodeBuild中运行测试.此外,此建议具有本地编译程序的程序包(em> ")需要-use-container
.
Furthermore, if I install SAM with pip install aws-sam-cli
, running sam build --use-container
in CodeBuild gives an error. sam build
itself succeeds, but since it doesn't install test dependencies, I'd still need to use pip install -r tests/requirements-test.txt -t .
to be able to run tests in CodeBuild. Moreover, this suggests that --use-container
is required for "packages that have natively compiled programs").
这使我想知道我是否正在尝试做错什么.在AWS的CI/CD工作流程中构建SAM服务的推荐方式是什么?
This makes me wonder whether I'm trying to do something wrong. What's the recommended way of building SAM services in a CI/CD workflow on AWS?
推荐答案
2019_10_18-更新(确认上述@Spiff答案):
2019_10_18 - Update (confirming @Spiff answer above):
显然,Codebuild现在可以与SAM无缝协作,这就是我在 buildspec.yml
中使用 pandas
和 psycopg2-binary
进行lambda所需的全部工作:
Apparently Codebuild now work seamlessly with SAM, that's all I needed in buildspec.yml
for a lambda using pandas
and 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
欢呼
这篇关于是否可以/建议在AWS CodeBuild中使用"sam build"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!