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

use*_*241 5 amazon-web-services amazon-ecs amazon-iam aws-codebuild

我正在使用 AWS 服务代码构建 Pilepileline 等配置 CICD piepline,以更新我的 ecs Fargate 集群中的部署网络,在我的 buildspec.yml 文件中,aws ecs cli 命令失败,抛出“COMMAND_EXECUTION_ERROR:执行命令时出错:aws ecs update-service --服务 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  

Run Code Online (Sandbox Code Playgroud)

sha*_*aws 0

错误代码 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 条目)。