【问题标题】:How to fix the aws CODE BUILD COMMAND_EXECUTION_ERROR exit status 255如何修复 aws CODE BUILD COMMAND_EXECUTION_ERROR 退出状态 255
【发布时间】:2020-01-25 19:08:54
【问题描述】:

我正在配置 CICD piepline 使用 aws 服务代码构建 pilepileline 等,以更新我的 ecs fargate 集群中的 deploymnet,在我的 buildspec.yml 文件中,aws ecs cli 命令失败并抛出“COMMAND_EXECUTION_ERROR:执行命令时出错:aws ecs update- service --services xxxxx。原因:退出状态 255"

我已尝试使用“AmazonECS_FullAccess”策略为 codebuild 角色提供权限。

post_build:  
    commands:  
      - echo Build completed on `date`  
      - echo Pushing the Docker images...  
      - docker push $REPOSITORY_URI:latest  
      - docker push $REPOSITORY_URI:$IMAGE_TAG  
      - echo Writing image definitions file...  
      - printf '[{"name":"xxxxxxx","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json  
      - cat imagedefinitions.json 
      - echo Updating ECSfargate service ...  
      - aws ecs describe-services --services xxxxxxxxxxxxxxxxx 
      - aws ecs update-service --service xxxxxxxxxxxxxxxxx --desired-count 2 --no-force-new-deployment  

【问题讨论】:

    标签: amazon-web-services amazon-iam amazon-ecs aws-codebuild


    【解决方案1】:

    我遇到了和你一样的问题,我解决它的方法是:尝试转到 CodeBuild,然后转到它的 IAM 角色。 AmazonEC2ContainerRegistryFullAccess 角色,现在单击该代码构建的“编辑”并选择“环境”并单击允许 AWS CodeBuild 修改此服务角色,以便它可以用于此构建项目。现在再试一次。

    在 CodeBuild 项目中使用 PrivilegedMode 模式。在 docker 容器内构建 docker 镜像时需要该模式。

    干杯

    【讨论】:

      【解决方案2】:

      您需要将管道的 GetAuthorizationToken 权限授予

      ecr:*
      

      而不是去

      ecr:repository/<you_repo>
      

      因为

      aws ecr get-login-password --region <aws_region>
      

      被执行

      <account_id>.dkr.ecr.<aws_region>.amazonaws.com 
      

      不反对

      <account_id>.dkr.ecr.<aws_region>.amazonaws.com/repository/<your_repo>
      

      【讨论】:

        【解决方案3】:

        附加AmazonEC2ContainerRegistryPowerUser 的策略为我解决了这个问题。

        【讨论】:

          【解决方案4】:

          错误代码 255 表示:

          255 -- 命令失败。 CLI 或发出请求的服务引发了错误。

          https://docs.aws.amazon.com/cli/latest/topic/return-codes.html

          正如您提到的,您提供了对 CB 角色的完全 ECS 访问权限,接下来您可以检查命令失败的原因:它在 ecs describe 或 ecs update-service 上是否失败?因为如果 Fargate 服务没有稳定下来,就会导致错误 255。

          我建议:

          1) 留下 ecs describe 命令,看看是否有效。

          2) 如果 (1) 成功,则执行 ecs update-service 并监控 AWS ECS 控制台和/或 CW 日志组中的服务(如果您的 Fargate Taskdef 有 logGroup 条目)。

          【讨论】:

            猜你喜欢
            • 2021-04-27
            • 2020-11-27
            • 1970-01-01
            • 2020-09-25
            • 2015-09-04
            • 1970-01-01
            • 1970-01-01
            • 2014-01-04
            • 2019-03-12
            相关资源
            最近更新 更多