当前位置: 首页 > 知识库问答 >
问题:

AWS代码生成错误:第2行的预期阶段为非空

连晟
2023-03-14

我试图在AWS CodeBuild上部署我的Angular 8应用程序。但是我得到了这个错误:DOWNLOAD_SOURCE失败YAML_FILE_ERROR:预期阶段在第2行为非空

构建日志事件中还有一个拒绝访问错误,尽管我在创建S3 bucket时授予了所有公共访问权限<代码>命令执行错误:执行命令时出错:aws s3 cp dist s3://${s3_BUCKET}--递归。原因:退出状态1

我向我的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中附加到我的构建项目的服务角色-现在构建成功了!:

共有1个答案

伯鸿达
2023-03-14

命令aws s3 cp dist s3://${s3_BUCKET}--recursive失败,因为与代码生成项目关联的角色没有对${s3_BUCKET}s3:PutObject权限。

您提供给S3 bucket策略的链接是错误的策略,因为它应该允许访问CodeBuild正在使用的IAM角色,而不是IAM用户。

要纠正此问题,您有两种选择:

  1. 向用于生成项目的CodeBuild角色添加所需的权限。该链接还显示了一个具有S3权限的示例代码构建角色
  2. 将角色添加到bucket策略

你还没有发布你使用的桶政策,所以我只是提供一个例子:

{
    "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>"
                ]
            }
        }
    ]
}
 类似资料:
  • 问题内容: 我从Web服务获取JSon数据,示例数据如下: 当我尝试将其转换时,它将引发错误,我这样做是: 我的班级是: LogCat说: com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_OBJECT,但在第1行第2列为BEGIN_ARRAY 问题答案: 错误说明发生了什么问题…您返回的是数组

  • 我是android编程新手。我有一个类,在这个类中,修改API调用是为了解析和显示JSON文件中的几个属性。但我得到: Java语言lang.IllegalStateException:应为BEGIN\u对象,但在第2行第1列为字符串 好心帮忙。我搜索了答案,但没有发现JSON响应有任何问题。发布了我的JSON响应和JAVA类: JSON响应: JAVA文件: 模型类:

  • 17.3. plural.py, 第 2 阶段 现在你将增加一个抽象过程。 你从定义一个规则列表开始:如果这样,就做那个,否则判断下一规则。 让我们暂时将程序一部分复杂化以便使另一部分简单化。 例 17.6. plural2.py import re def match_sxz(noun): return re.search('[sxz

  • 14.2. roman.py, 第 2 阶段 现在你有了 roman 模块的大概框架, 到了开始写代码以通过测试的时候了。 例 14.3. roman2.py 这个文件可以从 py/roman/stage2/ 目录中找到。 如果您还没有下载本书附带的例子程序, 可以 下载本程序和其他例子程序。 """Convert to and from Roman numerals""" #Define ex

  • 问题内容: 我遇到错误了。 由于以下原因,无法解析JSON:com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_ARRAY,但在第1行第2列为BEGIN_OBJECT 服务器网址 执行请求 上课后 我该如何解决? 问题答案: 您在注释中声明返回的JSON是这样的: 您告诉Gson您有一个对象数组:

  • 在尝试将json文本文件解析为餐厅对象的数组列表时,我遇到了错误“应为BEGIN\u数组,但在第1行第2列路径处为BEGIN\u对象。”我不知道哪里弄错了,因为我的Restaurant类中的数据成员与json文件中的字段完全对应。 主要的 餐厅类 txt文件