具有 ECS Blue/Green 的 AWS CodePipeline 部署因内部错误而失败 |拿2

AWS CodePipeline with ECS Blue/Green deployment fails with internal error | take 2

首先,我知道有一个类似的问题 (),但是回答它的人没有提供足够的细节。

根据这个答案:https://superuser.com/questions/1388058/getting-internal-error-in-aws-code-pipeline-while-deploying-to-ecs .. I have gone through the aws guide: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#constraints...确保所有 "required" 字段都在我的 taskdef.json 中(以下)

至于我的管道(构建)buildSpec ...

    - printf '{"ImageURI":"%s"}' $ECR_REPO_URI:demo > imageDetail.json
          - echo Build completed on `date`

  artifacts:
    files:
      - imageDetail.json

pipelinebuild stage设置很简单,我只是将 BuildArtifact 设置为输出。所以我可以从 管道 部署阶段 .

引用 imageDetail.json

至于我的管道(部署)AppSpec ...

version: 0.0

Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: <TASK_DEFINITION>
        LoadBalancerInfo:
          ContainerName: "pipeline_demo"
          ContainerPort: 80
        PlatformVersion: "LATEST"

管道部署阶段设置如下: 输入工件:BuildArtifact、SourceArtifact;然后:

动态更新任务定义图像:BuildArtifact

(..其中一些来自本指南:https://medium.com/@shashank070/in-my-previous-blog-i-have-explained-how-to-do-initial-checks-like-code-review-code-build-cddcc21afd9f

.. 和任务定义:

{
  "family": "devops-platform-ecs-task-def",
  "type": "AWS::ECS::TaskDefinition",
  "properties": {
    "containerDefinitions": [
      {
        "name": "pipeline_demo",
        "image": "<IMAGE1_NAME>",
        "cpu": "1024",
        "memory": "1024",
        "essential": true,
        "portMappings": [
          {
            "hostPort": 0,
            "protocol": "tcp",
            "containerPort": 80
          }
        ]
      }
    ],
    "ExecutionRoleArn": "arn:aws:iam::xxxxxx:role/devops_codepipeline",

    "NetworkMode": "null",
    "PlacementConstraints": [
        "type": "memberOf",
        "expression": ""
    ],
    "ProxyConfiguration": {
      "type": "APPMESH",
      "containerName": "",
      "properties": [
          {
              "name": "",
              "value": ""
          }
      ]
    },
    "RequiresCompatibilities": [
      "EC2"
    ],
    "Tags": [
      {
        "key": "",
        "value": ""
      }
    ],
    "TaskRoleArn": "",
    "Volumes": [
        {
            "name": "",
            "host": {
                "sourcePath": ""
            },
            "dockerVolumeConfiguration": {
                "scope": "task",
                "autoprovision": true,
                "driver": "",
                "driverOpts": {
                    "KeyName": ""
                },
                "labels": {
                    "KeyName": ""
                }
            }
        }
    ]
  }
}

尽管如此,我仍然收到错误...

如有任何帮助,我们将不胜感激!

您的任务定义无效。快速浏览一下,我可以看到以下无效 属性:

"type": "AWS::ECS::TaskDefinition",

请在此处查看示例任务定义 [1]。我还建议从 taskdef 中删除任何无关的部分,这样它们就不会以任何方式干扰。

[1] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/example_task_definitions.html

我实际上发现包含另一个策略 AWSCodeDeployRoleForECS 解决了这个问题。它在 CLI 的 aws 指南中引用(到目前为止,我们一直通过控制台进行管理,因此我偶然发现了这一点)Create a Service Role (CLI)。包含政策后,管道已经超越了列出的问题,但遇到了另一个 "Invalid Configuration Action; Container list cannot be empty." - 您的答案可能会解决?尽管如此,至少我有一个更有意义的错误要处理。