AWS CodeBuild error: Expected Phases to be non-empty at line 2
AWS CodeBuild error: Expected Phases to be non-empty at line 2
我正在尝试在 AWS CodeBuild 上部署我的 Angular 8 应用程序。
但是我得到这个错误:DOWNLOAD_SOURCE Failed YAML_FILE_ERROR: Expected Phases to be non-empty at line 2
尽管我在创建 S3 存储桶时授予了所有 public 访问权限,但构建日志事件中也出现了 ACCESS DENIED 错误。 COMMAND_EXECUTION_ERROR: Error while executing command: aws s3 cp dist s3://${S3_BUCKET} --recursive. Reason: exit status 1
我按照 here 所述向我的 S3 存储桶添加了访问策略,但这没有帮助。
我的 buildspec.yml 文件如下所示,阶段列表不为空:
version: 0.1
phases:
install:
commands:
- npm install -g @angular/cli
build:
commands:
- npm install
- ng build --prod --configuration=${BUILD_ENV}
post_build:
commands:
- aws s3 cp dist s3://${S3_BUCKET} --recursive
- aws configure set preview.cloudfront true
- echo ${S3_BUCKET}
artifacts:
files:
- '**/*'
base-directory: 'dist*'
discard-paths: yes
我以前从未使用过 YAML,我做错了什么?
以下是构建日志事件:
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Entering phase PRE_BUILD
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Phase complete: PRE_BUILD State: SUCCEEDED
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Phase context status code: Message:
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Entering phase BUILD
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Running command npm install
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
> core-js@3.6.4 postinstall /codebuild/output/src970973936/src/node_modules/core-js
2020-06-13T10:13:07.379+02:00
> node -e "try{require('./postinstall')}catch(e){}"
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
[96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling
JavaScript standard library![0m
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
[96mThe project needs your help! Please consider supporting of core-js on Open Collective or
Patreon: [0m
2020-06-13T10:13:07.379+02:00
[96m>[94m https://opencollective.com/core-js [0m
2020-06-13T10:13:07.379+02:00
[96m>[94m https://www.patreon.com/zloirock [0m
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
[96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good
job -)[0m
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
> @angular/cli@9.1.5 postinstall /codebuild/output/src970973936/src/node_modules/@angular/cli
2020-06-13T10:13:07.379+02:00
> node ./bin/postinstall/script.js
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:09.415+02:00
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server
/node_modules/fsevents):
2020-06-13T10:13:09.415+02:00
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted
{"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2020-06-13T10:13:09.415+02:00
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack/node_modules
/fsevents):
2020-06-13T10:13:09.415+02:00
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted
{"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2020-06-13T10:13:09.415+02:00
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
2020-06-13T10:13:09.415+02:00
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted
{"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2020-06-13T10:13:09.415+02:00
2020-06-13T10:13:09.415+02:00
added 1413 packages from 1124 contributors and audited 1418 packages in 22.639s
2020-06-13T10:13:09.415+02:00
2020-06-13T10:13:09.415+02:00
run `npm fund` for details
2020-06-13T10:13:09.415+02:00
2020-06-13T10:13:09.415+02:00
found 5 vulnerabilities (3 low, 2 high)
2020-06-13T10:13:09.415+02:00
run `npm audit fix` to fix them, or `npm audit` for details
2020-06-13T10:13:09.415+02:00
2020-06-13T10:13:09.415+02:00
[Container] 2020/06/13 08:13:09 Running command ng build --prod --configuration=${BUILD_ENV}
2020-06-13T10:13:15.474+02:00
Compiling @angular/animations : es2015 as esm2015
2020-06-13T10:13:15.474+02:00
Compiling @angular/core : es2015 as esm2015
2020-06-13T10:13:19.504+02:00
Compiling @angular/animations/browser : es2015 as esm2015
2020-06-13T10:13:21.526+02:00
Compiling @angular/animations/browser/testing : es2015 as esm2015
2020-06-13T10:13:21.526+02:00
Compiling @angular/common : es2015 as esm2015
2020-06-13T10:13:23.553+02:00
Compiling @angular/common/http : es2015 as esm2015
2020-06-13T10:13:23.553+02:00
Compiling @angular/common/http/testing : es2015 as esm2015
2020-06-13T10:13:25.579+02:00
Compiling @angular/forms : es2015 as esm2015
2020-06-13T10:13:27.607+02:00
Compiling @angular/platform-browser : es2015 as esm2015
2020-06-13T10:13:27.607+02:00
Compiling @angular/platform-browser/animations : es2015 as esm2015
2020-06-13T10:13:29.635+02:00
Compiling @angular/core/testing : es2015 as esm2015
2020-06-13T10:13:29.635+02:00
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
2020-06-13T10:13:31.660+02:00
Compiling @angular/platform-browser/testing : es2015 as esm2015
2020-06-13T10:13:31.660+02:00
Compiling @angular/compiler/testing : es2015 as esm2015
2020-06-13T10:13:31.660+02:00
Compiling @angular/platform-browser-dynamic/testing : es2015 as esm2015
2020-06-13T10:13:33.685+02:00
Compiling @angular/common/testing : es2015 as esm2015
2020-06-13T10:13:33.685+02:00
Compiling @angular/router : es2015 as esm2015
2020-06-13T10:13:35.712+02:00
Compiling @angular/router/testing : es2015 as esm2015
2020-06-13T10:14:09.752+02:00
Generating ES5 bundles for differential loading...
2020-06-13T10:14:23.800+02:00
ES5 bundle generation complete.
2020-06-13T10:14:23.800+02:00
2020-06-13T10:14:23.800+02:00
chunk {0} runtime-es2015.1eba213af0b233498d9d.js (runtime) 1.45 kB [entry] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {0} runtime-es5.1eba213af0b233498d9d.js (runtime) 1.45 kB [entry] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {1} main-es2015.cfbcf44215fba926de2a.js (main) 299 kB [initial] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {1} main-es5.cfbcf44215fba926de2a.js (main) 362 kB [initial] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {2} polyfills-es2015.690002c25ea8557bb4b0.js (polyfills) 36.1 kB [initial] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {3} polyfills-es5.9e286f6d9247438cbb02.js (polyfills-es5) 129 kB [initial] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {4} styles.9235c00a82b231f12fd9.css (styles) 586 bytes [initial] [rendered]
2020-06-13T10:14:23.800+02:00
Date: 2020-06-13T08:14:22.612Z - Hash: a55ad60a4042b04ff781 - Time: 70971ms
2020-06-13T10:14:23.800+02:00
2020-06-13T10:14:23.800+02:00
2020-06-13T10:14:23.800+02:00
2020-06-13T10:14:23.800+02:00
**[Container] 2020/06/13 08:14:22 Phase complete: BUILD State: SUCCEEDED**
2020-06-13T10:14:23.800+02:00
[Container] 2020/06/13 08:14:22 Phase context status code: Message:
2020-06-13T10:14:23.800+02:00
**[Container] 2020/06/13 08:14:22 Entering phase POST_BUILD**
2020-06-13T10:14:23.800+02:00
[Container] 2020/06/13 08:14:22 Running command aws s3 cp dist s3://${S3_BUCKET} --recursive
2020-06-13T10:14:29.834+02:00
**upload failed: dist/studileih/styles.9235c00a82b231f12fd9.css to s3://studileih-cicd-env.com
/studileih/styles.9235c00a82b231f12fd9.css An error occurred (AccessDenied) when calling the
PutObject operation: Access Denied**
2020-06-13T10:14:29.834+02:00
**Completed 586 Bytes/847.7 KiB (0 Bytes/s) with 9 file(s) remaining upload failed: dist/studileih
/runtime-es5.1eba213af0b233498d9d.js to s3://studileih-cicd-env.com/studileih/runtime-
es5.1eba213af0b233498d9d.js An error occurred (AccessDenied) when calling the PutObject operation:
Access Denied**
2020-06-13T10:14:29.834+02:00
**Completed 2.0 KiB/847.7 KiB (0 Bytes/s) with 8 file(s) remaining upload failed: dist/studileih
/index.html to s3://studileih-cicd-env.com/studileih/index.html An error occurred (AccessDenied)
when calling the PutObject operation: Access Denied**
2020-06-13T10:14:29.834+02:00
**Completed 3.0 KiB/847.7 KiB (0 Bytes/s) with 7 file(s) remaining upload failed: dist/studileih
/runtime-es2015.1eba213af0b233498d9d.js to s3://studileih-cicd-env.com/studileih/runtime-
es2015.1eba213af0b233498d9d.js An error occurred (AccessDenied) when calling the PutObject
operation: Access Denied**
[...followed by some more similar ACCESS DENIED LOGS]
2020-06-13T10:14:29.834+02:00
**[Container] 2020/06/13 08:14:28 Command did not exit successfully aws s3 cp dist s3://${S3_BUCKET}
--recursive exit status 1**
2020-06-13T10:14:29.834+02:00
**[Container] 2020/06/13 08:14:28 Phase complete: POST_BUILD State: FAILED**
2020-06-13T10:14:29.834+02:00
**[Container] 2020/06/13 08:14:28 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error
while executing command: aws s3 cp dist s3://${S3_BUCKET} --recursive. Reason: exit status 1**
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Expanding base directory path: .
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Assembling file list
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Expanding .
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Expanding file paths for base directory .
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Assembling file list
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Expanding **/*
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Found 57833 file(s)
2020-06-13T10:14:43.865+02:00
[Container] 2020/06/13 08:14:42 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
2020-06-13T10:14:43.865+02:00
[Container] 2020/06/13 08:14:42 Phase context status code: Message:
已解决: 在下面 Marcin 的回答后,我在 CodeBuild 中附加到我的构建项目的服务角色 - 构建现在成功了!:
命令 aws s3 cp dist s3://${S3_BUCKET} --recursive
失败,因为与您的代码构建项目关联的角色没有对 ${S3_BUCKET}
.
的 s3:PutObject
权限
您提供给 S3 存储桶的 link 策略是错误的,因为它应该允许访问 CodeBuild 正在使用的 IAM 角色,而不是 IAM 用户。
要解决这个问题,您有两个选择:
- 向用于构建项目的 CodeBuild role 添加所需的权限。 link 还显示了具有 S3 权限的示例 CodeBuild 角色。
- 将角色添加到存储桶策略。
你没有发布你使用的Bucket Policy,所以我只是举个例子:
{
"Id": "MyPolicyForCodeBuild",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCodeBuild",
"Action": "s3:*",
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::<your-bucket>/*",
"arn:aws:s3:::<your-bucket>"
],
"Principal": {
"AWS": [
"<arn-of-codebuild-role>"
]
}
}
]
}
我正在尝试在 AWS CodeBuild 上部署我的 Angular 8 应用程序。
但是我得到这个错误:DOWNLOAD_SOURCE Failed YAML_FILE_ERROR: Expected Phases to be non-empty at line 2
尽管我在创建 S3 存储桶时授予了所有 public 访问权限,但构建日志事件中也出现了 ACCESS DENIED 错误。 COMMAND_EXECUTION_ERROR: Error while executing command: aws s3 cp dist s3://${S3_BUCKET} --recursive. Reason: exit status 1
我按照 here 所述向我的 S3 存储桶添加了访问策略,但这没有帮助。
我的 buildspec.yml 文件如下所示,阶段列表不为空:
version: 0.1
phases:
install:
commands:
- npm install -g @angular/cli
build:
commands:
- npm install
- ng build --prod --configuration=${BUILD_ENV}
post_build:
commands:
- aws s3 cp dist s3://${S3_BUCKET} --recursive
- aws configure set preview.cloudfront true
- echo ${S3_BUCKET}
artifacts:
files:
- '**/*'
base-directory: 'dist*'
discard-paths: yes
我以前从未使用过 YAML,我做错了什么?
以下是构建日志事件:
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Entering phase PRE_BUILD
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Phase complete: PRE_BUILD State: SUCCEEDED
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Phase context status code: Message:
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Entering phase BUILD
2020-06-13T10:12:47.354+02:00
[Container] 2020/06/13 08:12:45 Running command npm install
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
> core-js@3.6.4 postinstall /codebuild/output/src970973936/src/node_modules/core-js
2020-06-13T10:13:07.379+02:00
> node -e "try{require('./postinstall')}catch(e){}"
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
[96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling
JavaScript standard library![0m
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
[96mThe project needs your help! Please consider supporting of core-js on Open Collective or
Patreon: [0m
2020-06-13T10:13:07.379+02:00
[96m>[94m https://opencollective.com/core-js [0m
2020-06-13T10:13:07.379+02:00
[96m>[94m https://www.patreon.com/zloirock [0m
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
[96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good
job -)[0m
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:07.379+02:00
> @angular/cli@9.1.5 postinstall /codebuild/output/src970973936/src/node_modules/@angular/cli
2020-06-13T10:13:07.379+02:00
> node ./bin/postinstall/script.js
2020-06-13T10:13:07.379+02:00
2020-06-13T10:13:09.415+02:00
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server
/node_modules/fsevents):
2020-06-13T10:13:09.415+02:00
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted
{"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2020-06-13T10:13:09.415+02:00
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack/node_modules
/fsevents):
2020-06-13T10:13:09.415+02:00
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted
{"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2020-06-13T10:13:09.415+02:00
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
2020-06-13T10:13:09.415+02:00
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted
{"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2020-06-13T10:13:09.415+02:00
2020-06-13T10:13:09.415+02:00
added 1413 packages from 1124 contributors and audited 1418 packages in 22.639s
2020-06-13T10:13:09.415+02:00
2020-06-13T10:13:09.415+02:00
run `npm fund` for details
2020-06-13T10:13:09.415+02:00
2020-06-13T10:13:09.415+02:00
found 5 vulnerabilities (3 low, 2 high)
2020-06-13T10:13:09.415+02:00
run `npm audit fix` to fix them, or `npm audit` for details
2020-06-13T10:13:09.415+02:00
2020-06-13T10:13:09.415+02:00
[Container] 2020/06/13 08:13:09 Running command ng build --prod --configuration=${BUILD_ENV}
2020-06-13T10:13:15.474+02:00
Compiling @angular/animations : es2015 as esm2015
2020-06-13T10:13:15.474+02:00
Compiling @angular/core : es2015 as esm2015
2020-06-13T10:13:19.504+02:00
Compiling @angular/animations/browser : es2015 as esm2015
2020-06-13T10:13:21.526+02:00
Compiling @angular/animations/browser/testing : es2015 as esm2015
2020-06-13T10:13:21.526+02:00
Compiling @angular/common : es2015 as esm2015
2020-06-13T10:13:23.553+02:00
Compiling @angular/common/http : es2015 as esm2015
2020-06-13T10:13:23.553+02:00
Compiling @angular/common/http/testing : es2015 as esm2015
2020-06-13T10:13:25.579+02:00
Compiling @angular/forms : es2015 as esm2015
2020-06-13T10:13:27.607+02:00
Compiling @angular/platform-browser : es2015 as esm2015
2020-06-13T10:13:27.607+02:00
Compiling @angular/platform-browser/animations : es2015 as esm2015
2020-06-13T10:13:29.635+02:00
Compiling @angular/core/testing : es2015 as esm2015
2020-06-13T10:13:29.635+02:00
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
2020-06-13T10:13:31.660+02:00
Compiling @angular/platform-browser/testing : es2015 as esm2015
2020-06-13T10:13:31.660+02:00
Compiling @angular/compiler/testing : es2015 as esm2015
2020-06-13T10:13:31.660+02:00
Compiling @angular/platform-browser-dynamic/testing : es2015 as esm2015
2020-06-13T10:13:33.685+02:00
Compiling @angular/common/testing : es2015 as esm2015
2020-06-13T10:13:33.685+02:00
Compiling @angular/router : es2015 as esm2015
2020-06-13T10:13:35.712+02:00
Compiling @angular/router/testing : es2015 as esm2015
2020-06-13T10:14:09.752+02:00
Generating ES5 bundles for differential loading...
2020-06-13T10:14:23.800+02:00
ES5 bundle generation complete.
2020-06-13T10:14:23.800+02:00
2020-06-13T10:14:23.800+02:00
chunk {0} runtime-es2015.1eba213af0b233498d9d.js (runtime) 1.45 kB [entry] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {0} runtime-es5.1eba213af0b233498d9d.js (runtime) 1.45 kB [entry] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {1} main-es2015.cfbcf44215fba926de2a.js (main) 299 kB [initial] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {1} main-es5.cfbcf44215fba926de2a.js (main) 362 kB [initial] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {2} polyfills-es2015.690002c25ea8557bb4b0.js (polyfills) 36.1 kB [initial] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {3} polyfills-es5.9e286f6d9247438cbb02.js (polyfills-es5) 129 kB [initial] [rendered]
2020-06-13T10:14:23.800+02:00
chunk {4} styles.9235c00a82b231f12fd9.css (styles) 586 bytes [initial] [rendered]
2020-06-13T10:14:23.800+02:00
Date: 2020-06-13T08:14:22.612Z - Hash: a55ad60a4042b04ff781 - Time: 70971ms
2020-06-13T10:14:23.800+02:00
2020-06-13T10:14:23.800+02:00
2020-06-13T10:14:23.800+02:00
2020-06-13T10:14:23.800+02:00
**[Container] 2020/06/13 08:14:22 Phase complete: BUILD State: SUCCEEDED**
2020-06-13T10:14:23.800+02:00
[Container] 2020/06/13 08:14:22 Phase context status code: Message:
2020-06-13T10:14:23.800+02:00
**[Container] 2020/06/13 08:14:22 Entering phase POST_BUILD**
2020-06-13T10:14:23.800+02:00
[Container] 2020/06/13 08:14:22 Running command aws s3 cp dist s3://${S3_BUCKET} --recursive
2020-06-13T10:14:29.834+02:00
**upload failed: dist/studileih/styles.9235c00a82b231f12fd9.css to s3://studileih-cicd-env.com
/studileih/styles.9235c00a82b231f12fd9.css An error occurred (AccessDenied) when calling the
PutObject operation: Access Denied**
2020-06-13T10:14:29.834+02:00
**Completed 586 Bytes/847.7 KiB (0 Bytes/s) with 9 file(s) remaining upload failed: dist/studileih
/runtime-es5.1eba213af0b233498d9d.js to s3://studileih-cicd-env.com/studileih/runtime-
es5.1eba213af0b233498d9d.js An error occurred (AccessDenied) when calling the PutObject operation:
Access Denied**
2020-06-13T10:14:29.834+02:00
**Completed 2.0 KiB/847.7 KiB (0 Bytes/s) with 8 file(s) remaining upload failed: dist/studileih
/index.html to s3://studileih-cicd-env.com/studileih/index.html An error occurred (AccessDenied)
when calling the PutObject operation: Access Denied**
2020-06-13T10:14:29.834+02:00
**Completed 3.0 KiB/847.7 KiB (0 Bytes/s) with 7 file(s) remaining upload failed: dist/studileih
/runtime-es2015.1eba213af0b233498d9d.js to s3://studileih-cicd-env.com/studileih/runtime-
es2015.1eba213af0b233498d9d.js An error occurred (AccessDenied) when calling the PutObject
operation: Access Denied**
[...followed by some more similar ACCESS DENIED LOGS]
2020-06-13T10:14:29.834+02:00
**[Container] 2020/06/13 08:14:28 Command did not exit successfully aws s3 cp dist s3://${S3_BUCKET}
--recursive exit status 1**
2020-06-13T10:14:29.834+02:00
**[Container] 2020/06/13 08:14:28 Phase complete: POST_BUILD State: FAILED**
2020-06-13T10:14:29.834+02:00
**[Container] 2020/06/13 08:14:28 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error
while executing command: aws s3 cp dist s3://${S3_BUCKET} --recursive. Reason: exit status 1**
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Expanding base directory path: .
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Assembling file list
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Expanding .
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Expanding file paths for base directory .
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Assembling file list
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Expanding **/*
2020-06-13T10:14:29.834+02:00
[Container] 2020/06/13 08:14:28 Found 57833 file(s)
2020-06-13T10:14:43.865+02:00
[Container] 2020/06/13 08:14:42 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
2020-06-13T10:14:43.865+02:00
[Container] 2020/06/13 08:14:42 Phase context status code: Message:
已解决: 在下面 Marcin 的回答后,我在 CodeBuild 中附加到我的构建项目的服务角色 - 构建现在成功了!:
命令 aws s3 cp dist s3://${S3_BUCKET} --recursive
失败,因为与您的代码构建项目关联的角色没有对 ${S3_BUCKET}
.
s3:PutObject
权限
您提供给 S3 存储桶的 link 策略是错误的,因为它应该允许访问 CodeBuild 正在使用的 IAM 角色,而不是 IAM 用户。
要解决这个问题,您有两个选择:
- 向用于构建项目的 CodeBuild role 添加所需的权限。 link 还显示了具有 S3 权限的示例 CodeBuild 角色。
- 将角色添加到存储桶策略。
你没有发布你使用的Bucket Policy,所以我只是举个例子:
{
"Id": "MyPolicyForCodeBuild",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCodeBuild",
"Action": "s3:*",
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::<your-bucket>/*",
"arn:aws:s3:::<your-bucket>"
],
"Principal": {
"AWS": [
"<arn-of-codebuild-role>"
]
}
}
]
}