5

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
Community
  • 1
  • 1
krismath
  • 1,879
  • 2
  • 23
  • 41

3 Answers3

11

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.

krismath
  • 1,879
  • 2
  • 23
  • 41
  • 4
    [This article](https://docs.aws.amazon.com/codepipeline/latest/userguide/troubleshooting.html#troubleshooting-ecstocodedeploy-size) references the size limit of 3MB (not sure if it was made after you posted this). – double_j Aug 31 '20 at 18:35
1

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

Diego Jancic
  • 7,280
  • 7
  • 52
  • 80
Mech
  • 1,326
  • 11
  • 14
  • Thank you for your detailed answer Makani. However, none of your suggestions worked for me. I have checked that the file exists in the compressed artifact file. The `taskdef.json` file works on a separate ECS deployment setup and the `appspec.yaml` is copied from AWS documentation. In the end it was a different problem - see my answer. I am sure that others may find your answer useful. – krismath Jul 29 '19 at 11:19
  • Thank you Krismath...I somehow missed to mention the size but yes there is a size limit of 3 MB and reason behind it is CodeDeploy expects only appspec and taskdef file in source repository and 3 MB limits is both of these files and I am totally agree that this part is missed from documentation – Mech Aug 04 '19 at 03:42
1

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.

hkjamil
  • 100
  • 1
  • 8
  • This is not needed, you can have appspec.yaml and taskdef.json in your main project, as long as your buildspec.yml generates the right artifacts, see more here: https://stackoverflow.com/a/62037921/843898 – Berend de Boer Dec 22 '20 at 21:19