Skip to content

CodeDeploy Error: Latest action execution message Exception while trying to read the task definition artifact file from: SourceArtifact

0

I'm new to AWS and have successfully deployed my Django application on an AWS Fargate cluster. My pipeline runs smoothly through the Source and Build stages, but the Deploy stage consistently fails with the following error:

Latest action execution message:
Exception while trying to read the task definition artifact file from: SourceArtifact

my current buildspec.yml:

version: 0.2

phases:
  pre_build:
    commands:
      - echo Logging into Amazon ECR...
      - aws --version
      - aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin {removed for privacy}.dkr.ecr.us-east-2.amazonaws.com
      - echo Logging into Docker Hub...
      - echo "{removed for privacy}" | docker login --username "{removed for privacy}" --password-stdin
  build:
    commands:
      - echo Build started on date
      - echo Building Docker image...
      - docker build -t my-first-repository .
      - docker tag my-first-repository:latest {removed for privacy}.dkr.ecr.us-east-2.amazonaws.com/my-first-repository:latest
  post_build:
    commands:
      - echo Build completed on date
      - echo Pushing the Docker images...
      - docker push {removed for privacy}.dkr.ecr.us-east-2.amazonaws.com/my-first-repository:latest
      - echo Preparing task definition
      - printf '[{"name":"DatosAppContainer","imageUri":"%s"}]' {removed for privacy}.dkr.ecr.us-east-2.amazonaws.com/my-first-repository:latest > imagedefinitions.json
      - echo Listing the contents of the current directory...
      - ls -alh
artifacts:
    files: imagedefinitions.json

appspec.yaml:

version: 0.0 Resources:

  - TargetService:
      Type: AWS::ECS:Service
      Properties:
        TaskDefinition: "arn:aws:ecs:us-east-2:{removed for privacy}:task-definition/DatosTaskDefinition:1"
        LoadBalancerInfo:
          ContainerName: "DatosAppContainer"
          ContainerPort: 8000

It seems that my task definition isn't being read or found, even after setting up the required CodeDeploy role.

I’d really appreciate any guidance on resolving this, as I’ve been stuck on it for the past few days and running out of options.

Thanks in advance!

asked a year ago256 views
2 Answers
0

Hello.

Looking at the buildspec.yaml and appspec.yaml you shared, I don't think there's a problem with the configuration.
This error occurs when the source artifact is larger than 3MB.
Therefore, I think the problem can be solved by either adjusting the size of the source artifact to be smaller, or by outputting "appspec.yml" and "taskdef.json" in the buildspec.ymla artifacts and using "BuildArtifact" instead of "SourceArtifact" in the CodePipeline deploy stage.
https://docs.aws.amazon.com/codepipeline/latest/userguide/troubleshooting.html#troubleshooting-ecstocodedeploy-size

Problem:
The task definition file is a required artifact for the CodePipeline deploy action to Amazon ECS through CodeDeploy (the CodeDeployToECS action). The maximum artifact ZIP size in the CodeDeployToECS deploy action is 3 MB. The following error message is returned when the file is not found or the artifact size exceeds 3 MB:
Exception while trying to read the task definition artifact file from: <source artifact name>
Possible fixes: Make sure the task definition file is included as an artifact. If the file already exists, makes sure the compressed size is less than 3 MB.

EXPERT
answered a year ago
-1

The error you're encountering suggests that there's an issue with the task definition artifact in your CodePipeline deployment to Amazon ECS using CodeDeploy. This is a common problem, and there are a few potential causes and solutions to consider:

  1. Artifact Size: The task definition file is a required artifact for the CodePipeline deploy action to Amazon ECS through CodeDeploy. There's a size limit of 3 MB for the compressed artifact ZIP in the CodeDeployToECS deploy action. If your artifact exceeds this size, you'll encounter this error.

  2. Missing Artifact: Ensure that the task definition file is actually included as an artifact in your pipeline. It should be part of the artifacts generated in your build stage and passed to the deploy stage.

  3. Artifact Name: Double-check that the artifact name in your deploy stage configuration matches the name of the artifact produced by your build stage. In this case, it seems you're looking for "SourceArtifact", but it's possible your build stage is producing an artifact with a different name.

  4. File Path: Verify that the task definition file is in the correct location within your artifact structure. CodeDeploy expects to find it at a specific path.

  5. File Format: Ensure your task definition file is correctly formatted and valid JSON or YAML.

To resolve this issue:

  1. Check your buildspec.yml file to confirm you're creating and outputting the task definition file as an artifact.

  2. Verify the artifact name and file path in your CodePipeline stage configuration.

  3. If the task definition file exists and is correctly named, try to reduce its size if it's approaching or exceeding 3 MB.

  4. Review your CodeDeploy application specification (AppSpec) file to ensure it correctly references the task definition file.

  5. If you're using the AWS Management Console, you can check the details of the failed deployment in the CodePipeline console. This might provide more specific information about why the file couldn't be read.

If you've confirmed all of these and are still facing issues, you may need to review your IAM permissions to ensure CodeDeploy has the necessary access to read the artifacts from your pipeline.

Remember, troubleshooting deployment issues can be complex, so don't hesitate to use AWS CloudWatch logs for more detailed error messages and to reach out to AWS Support if you continue to face difficulties.
Sources
Troubleshooting CodePipeline - AWS CodePipeline
Troubleshoot Amazon ECS deployment issues - AWS CodeDeploy

answered a year ago
  • Kindly be alittle more specific, all these suggestions have failed

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.