2
votes

I have a Codepipeline that deploys an ECR image to an ECS cluster using an ECS Blue / Green Deployment action. The pipeline contains two sources: one for the ECR image using an AWS ECR action and another one for fetching the configuration from Github using a ThirdParty Github action. The ECR action outputs an image artifact while the Github action outputs a config artifact. Both of these artifacts are provided as an input to the ECS Blue / Green Deployment action.

The pipeline fails at the ECS Blue / Green Deployment action with the following error (visible from AWS console):

Invalid action configuration

Exception while trying to read the task definition artifact file from: config

Here is the structure of the pipeline (some details are edited for anonymity):

$ aws codepipeline get-pipeline --name my-codepipeline
{
  "pipeline": {
    "name": "my-codepipeline",
    "roleArn": "arn:aws:iam::123456789000:role/my-codepipeline-role",
    "artifactStore": {
      "type": "S3",
      "location": "my-codepipeline-s3"
    },
    "stages": [
      {
        "name": "Source",
        "actions": [
          {
            "name": "ImageSource",
            "actionTypeId": {
              "category": "Source",
              "owner": "AWS",
              "provider": "ECR",
              "version": "1"
            },
            "runOrder": 1,
            "configuration": {
              "ImageTag": "latest",
              "RepositoryName": "my-ecr"
            },
            "outputArtifacts": [
              {
                "name": "image"
              }
            ],
            "inputArtifacts": []
          },
          {
            "name": "ConfigSource",
            "actionTypeId": {
              "category": "Source",
              "owner": "ThirdParty",
              "provider": "GitHub",
              "version": "1"
            },
            "runOrder": 1,
            "configuration": {
              "Branch": "master",
              "OAuthToken": "****",
              "Owner": "me",
              "PollForSourceChanges": "false",
              "Repo": "application-config"
            },
            "outputArtifacts": [
              {
                "name": "config"
              }
            ],
            "inputArtifacts": []
          }
        ]
      },
      {
        "name": "Deploy",
        "actions": [
          {
            "name": "DeployBackend",
            "actionTypeId": {
              "category": "Deploy",
              "owner": "AWS",
              "provider": "CodeDeployToECS",
              "version": "1"
            },
            "runOrder": 1,
            "configuration": {
              "AppSpecTemplateArtifact": "config",
              "AppSpecTemplatePath": "production/appspec.yaml",
              "ApplicationName": "my-codedeploy",
              "DeploymentGroupName": "my-codedeploy-group",
              "Image1ArtifactName": "image",
              "Image1ContainerName": "IMAGE_NAME",
              "TaskDefinitionTemplateArtifact": "config",
              "TaskDefinitionTemplatePath": "production/taskdef.json"
            },
            "outputArtifacts": [],
            "inputArtifacts": [
              {
                "name": "image"
              },
              {
                "name": "config"
              }
            ]
          }
        ]
      }
    ],
    "version": 1
  },
  "metadata": {
    "pipelineArn": "arn:aws:codepipeline:ap-northeast-1:123456789000:my-codepipeline",
    "created": 1564107543.285,
    "updated": 1564107543.285
  }
}

I have checked the compressed artifact in the S3 and it definitely contains the configuration files in the Github repository at the location specified by AppSpecTemplatePath and TaskDefinitionTemplatePath.

Here is the content of appspec.yaml:

$ cat production/appspec.yaml
version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: <TASK_DEFINITION>
        LoadBalancerInfo:
          ContainerName: "my-container"
          ContainerPort: 80
3

3 Answers

5
votes

After extensively trying out things, I stumbled upon a thread in a foreign language which I cannot find it. The thread said something about the artifact being passed to the action cannot be larger than 3 MB.

I solved my problem by reducing the size of the artifact (config). The configuration repository is shared among many projects and by moving those items to another project, I decreased the compressed artifact size from 14 MB to 3 kB. Miraculously, everything worked fine. AWS if you are reading this, please add more documentation about the artifact size limits to ECS CodeDeploy as I don't see any mention about this and I have no way of debugging this problem with such a general error message.

1
votes

Thought I know a little about artifact config and could not found any help.

I created another codecommit repo where i stored appspec.yml and taskdef.json file only and followed this aws userguide. And this worked

Previously I was committing those file with main project repo. But every time it failed in deploy state with this message.[Exception while trying to read the task definition artifact file from ...]

I felt safe this way in production codebuild and codedeploy are separated in pipeline.

I created artifact pipeline and build pipeline. Two pipeline. To blue/green ECS service.

1
votes

As far as I understand there are three major things we have to check as even if there is a syntax issue on file we might get the exception

  1. Files exists on correct path and you have already verified this.
  2. Content of the both taskdef.json file and appspec.yaml is proper without any syntax error and we can always refer to this document [1] for it.
  3. Also make sure that image has correct place holder "<IMAGE1_NAME>".
  4. Also if these options don't work then you may try to create on test public github repo just put taskdef.json and appspec.yaml file in it and test the same thing.

[1] Tutorial: Create a Pipeline with an Amazon ECR Source and ECS-to-CodeDeploy Deployment - https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-ecs-ecr-codedeploy.html