如何修复AWS CODE BUILD COMMAND_EXECUTION_ERROR退出状态255

时间:2019-09-25 14:39:49

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

我要使用aws服务代码配置CICD命令行来构建桩堆线等,以更新ecs fargate集群中的deploymnet,在我的buildspec.yml文件中,aws ecs cli命令无法抛出“ COMMAND_EXECUTION_ERROR:执行命令时出错:aws ecs update- service --services xxxxx。原因:退出状态255“

我尝试通过“ AmazonECS_FullAccess”策略为代码构建角色提供权限。

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  

4 个答案:

答案 0 :(得分:1)

附加AmazonEC2ContainerRegistryPowerUser的策略已为我解决了此问题。

答案 1 :(得分:0)

错误代码255表示:

255-命令失败。 CLI或发出请求的服务都会抛出错误。

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

正如您提到的那样,您已经提供了ECS对CB角色的完全访问权限,接下来您可以检查的是命令失败的原因:ecs describe或ecs update-service失败了吗?由于如果Fargate服务不稳定,则会导致错误255。

我建议:

1)只需保留ecs describe命令,看看是否可行。

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

答案 2 :(得分:0)

您需要向管道授予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 :(得分:0)

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

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

干杯