AWS CodeBuild中SAM esbuild构建报错:不支持该构建器
问题
本地通过CLI使用esbuild执行sam build和sam deploy部署存储在CodeCommit的Lambda+API Gateway代码仓库时一切正常,但将构建流程集成到CodePipeline的CodeBuild环节后,出现以下错误:
File "/root/.pyenv/versions/3.9.5/lib/python3.9/site-packages/samcli/lib/build/workflow_config.py", line 133, in get_selector raise UnsupportedBuilderException("'{}' does not have a supported builder".format(specified_workflow)) samcli.lib.build.workflow_config.UnsupportedBuilderException: 'esbuild' does not have a supported builder
Lambda模板(简化属性后):
BasicFunction: Type: AWS::Serverless::Function Properties: Metadata: BuildMethod: esbuild BuildProperties: Minify: false Target: "es2020" EntryPoints: - appBasic.ts
buildspec.yml内容:
version: 0.2 phases: install: commands: - npm install - npm install esbuild build: commands: - sam build - sam deploy --no-confirm-changeset --no-fail-on-empty-changeset
解决方案
升级SAM CLI版本
CodeBuild默认环境中的SAM CLI版本可能过低,不支持esbuild作为官方构建器。在buildspec的install阶段添加升级命令:phases: install: commands: - pip install --upgrade aws-sam-cli - npm install - npm install esbuild显式指定esbuild路径(可选)
若升级SAM后仍无法识别esbuild,可在sam build命令中指定esbuild的本地路径:build: commands: - sam build --esbuild-path ./node_modules/.bin/esbuild - sam deploy --no-confirm-changeset --no-fail-on-empty-changeset使用高版本CodeBuild镜像
选择预装新版SAM CLI的CodeBuild镜像,例如aws/codebuild/amazonlinux2-x86_64-standard:4.0及以上版本,这类镜像自带的SAM版本已支持esbuild构建器,无需手动升级。
内容的提问来源于stack exchange,提问作者Ari Waisberg
相关产品推荐
相关产品推荐

