CodeDeploy blue/green ECS fargate error: Invalid arn syntax

0

I created ECS fargate, codebuild, codedeploy and codepipeline with terraform but when pipeline run, it fail on CodeDeploy with following log

Deploy log

Deploy input

HereHere is my artifact files

appspec.yml

version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: "<TASK_DEFINITION>"
        LoadBalancerInfo:
          ContainerName: "name-container"
          ContainerPort: "3000"
        PlatformVersion: "LATEST"

taskdef.json

{
    "networkMode": "awsvpc",
    "requiresCompatibilities": [
      "FARGATE"
    ],
    "family": "name-task-def",
    "executionRoleArn": "arn:aws:iam::ACC_ID:role/name-execution-role",
    "taskRoleArn": "arn:aws:iam::ACC_ID:role/name-task-role",
    "memory": "1024",
    "cpu": "512",
    "containerDefinitions": [
      {
        "image": "ACC_ID.dkr.ecr.eu-central-1.amazonaws.com/name-ecr-repo:latest",
        "name": "name-container",
        "mountPoints": [],
        "logConfiguration": {
          "options": {
            "awslogs-group": "/aws/ecs/task-name",
            "awslogs-region": "eu-central-1",
            "awslogs-stream-prefix": "rails"
          },
          "logDriver": "awslogs"
        },
        "cpu": 0,
        "portMappings": [
          {
            "protocol": "tcp",
            "containerPort": 3000,
            "hostPort": 3000
          }
        ],
        "environment": [],
        "environmentFiles": [
            {
              "value": "name-s3-store-envs/fe-app/.env",
              "type": "s3"
            }
        ],
        "essential": true
      }
    ]
}

main.tf

resource "aws_ecs_service" "ecs_service" {
  ...

  deployment_controller {
    type = CODE_DEPLOY
  }
}

resource "aws_codedeploy_app" "codedeploy_app" {
  name             = "${var.codedeploy_app.name}-codedeploy-app"
  compute_platform = "ECS"
}

resource "aws_codedeploy_deployment_group" "codedeploy_deployment_group" {
  app_name               = aws_codedeploy_app.codedeploy_app.name
  deployment_group_name  = "${var.deploy_name}-deploy-grp"
  service_role_arn       = aws_iam_role.code_deploy_role.arn
  deployment_config_name = "CodeDeployDefault.ECSAllAtOnce"
  autoscaling_groups     = var.codedeploy_deployment_groups[0].autoscaling_groups

  deployment_style {
    deployment_type   = "BLUE_GREEN"
    deployment_option = "WITH_TRAFFIC_CONTROL"
  }

  auto_rollback_configuration {
    enabled = var.codedeploy_deployment_groups[0].auto_rollback_configuration
    events  = ["DEPLOYMENT_FAILURE"]
  }

  load_balancer_info {
    target_group_pair_info {
      prod_traffic_route {
        listener_arns = [aws_lb_listener.listen_443.arn]
      }
      target_group {
        name = aws_lb_target_group.target_group_blue.name
      }
      target_group {
        name = aws_lb_target_group.target_group_green.name
      }
    }
  }
}

resource "aws_codepipeline" "codepipeline" {
  name          = "${var.codepipeline_app.name}-codepipeline"
  pipeline_type = "V2"
  role_arn      = aws_iam_role.code_pipeline_role.arn

  artifact_store {
    location = module.s3_artifact.s3_bucket_id
    type     = "S3"

  ...

  stage {
    name = "Deploy"
    action {
      name            = "Deploy-BlueGreen"
      category        = "Deploy"
      owner           = "AWS"
      provider        = "CodeDeployToECS"
      input_artifacts = ["build"]
      version          = "1"
      run_order        = "1"
      configuration = {
        ApplicationName                = aws_codedeploy_app.codedeploy_app.name
        DeploymentGroupName            = "${var.deploy_name}-deploy-grp"
        AppSpecTemplateArtifact        = "build"
        AppSpecTemplatePath            = var.codepipeline_app.app_spec_path
        TaskDefinitionTemplateArtifact = "build"
        TaskDefinitionTemplatePath     = var.codepipeline_app.task_def_path
      }
    }
  }

The strangest thing is there is no deployment, just only above logs

Deployment

Deploy grp

Could anyone please help me with this? I have been struggle with this error for hours

I have try to change, update, validate config, but nothing works

2 個答案
0
已接受的答案

I have knew where is wrong.

Turn out, it has to be ARN of S3, not name of S3

        "environmentFiles": [
            {
              "value": "arn:aws:s3:::name-s3-store-envs/fe-app/.env",
              "type": "s3"
            }
        ],
已回答 1 個月前
0

Hi,

In your "real" code, do you have the value of account-id (i.e digits only) to replace ACC_ID ? Also can you try ARN with no value for account-id, .i.e., just :: with no value in the middle?

Best

Didier

profile pictureAWS
專家
已回答 1 個月前
  • Thank you for response This is my taskdef.json file

    {
      "networkMode": "awsvpc",
      "requiresCompatibilities": [
        "FARGATE"
      ],
      "family": "name-task-def",
      "executionRoleArn": "arn:aws:iam::012345678910:role/name-execution-role",
      "taskRoleArn": "arn:aws:iam::012345678910:role/name-task-role",
      "memory": "1024",
      "cpu": "512",
      "containerDefinitions": [
        {
          "image": "012345678910.dkr.ecr.eu-central-1.amazonaws.com/name-ecr-repo:latest",
          "name": "name-container",
          "mountPoints": [],
          "logConfiguration": {
            "options": {
              "awslogs-group": "/aws/ecs/task-name",
              "awslogs-region": "eu-central-1",
              "awslogs-stream-prefix": "rails"
            },
            "logDriver": "awslogs"
          },
          "cpu": 0,
          "portMappings": [
            {
              "protocol": "tcp",
              "containerPort": 3000,
              "hostPort": 3000
            }
          ],
          "environment": [],
          "environmentFiles": [
              {
                "value": "name-s3-store-envs/fe-app/.env",
                "type": "s3"
              }
          ],
          "essential": true
        }
      ]
    }
    

    The point is I don't know why there is no deployment

  • I fixed it, pls read accepted answer. Thank you for supporting!

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南