Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“Error: Task definition file does not exist: ” when deploying Docker images to AWS ECS #68

Closed
naveen-marthala opened this issue Oct 26, 2020 · 9 comments

Comments

@naveen-marthala
Copy link

naveen-marthala commented Oct 26, 2020

I am trying to push docker images from GitHub Actions to AWS ECR then to ECS with a task to deploy the latest container in AWS ECS.

I am using the default aws.config file with changes only for AWS ECR repository name, AWS ECS cluster name and it's service name and docker image details to push docker images to AWS ECR to which could then to deployed as containers to AWS ECS by defining tasks. And I got an error message with defining tasks to deploy to ECS(in the section "Fill in the new image ID in the Amazon ECS task definition" in aws.yml) and it is:

Error: Task definition file does not exist: ecs-task-definition.json

Some information to prove everything is in place(presumably):
Here's me checking the existence of file and pushing the task from my terminal to AWS ECS:
enter image description here

And here's that very task definition with the revision number and task's family name shown in screenshot above:
enter image description here

So, as you can see task-definition file does exist, but GitHub doesn't recognise it. What has caused this error and how do I fix this?

Here's the complete build screenshot:
enter image description here

and this is the error:
enter image description here

And here's the part of my ".github/workflows/aws.yml" in my repo for task definition (file can be found here in my repository)

    - name: Fill in the new image ID in the Amazon ECS task definition
      id: task-def
      uses: aws-actions/amazon-ecs-render-task-definition@v1
      with:
        task-definition: ecs-task-definition.json
        container-name: aws-dock-p-cont
        image: ${{ steps.build-image.outputs.image }}

Images are being pushed to my ECR repository without any problems, but the problem comes right before executing tasks to use those images and deploy as containers.

EDIT:
Here's the cluster I have used in aws.yml file:
enter image description here
Here's the role I have specified in the task json file:
enter image description here

I have done as described in this article.

@naveen-marthala naveen-marthala changed the title "Error: Task definition file does not exist: " during step: "Fill in the new image ID in the Amazon ECS task definition" “Error: Task definition file does not exist: ” when deploying Docker images to AWS ECS Oct 28, 2020
@naveen-marthala
Copy link
Author

I hadn't uploaded the task defintion file to my github repo with the thought that the GitHub will pull it from my AWS account.

@chorsnell
Copy link

for anyone else finding this, it turns out task-definition: does not obey working_directory, so the relative path needs to be from the root of your repo

@ShyamPanj
Copy link

my task-defintion.json file is directly under repo. How should I specify the path?

@sandeepinsys
Copy link

my task-defintion.json file is directly under repo. How should I specify the path?

In that case, path should be ./task-defintion.json

@RulerOf
Copy link

RulerOf commented Aug 27, 2022

In my case, I had forgotten to run the checkout step.

@JohnQ1981
Copy link

JohnQ1981 commented Sep 23, 2022

Please anyone can help, failing at the same step as mentioned above. and i have my
image

image

and my github is https://github.com/JohnQ1981/teachermonsters

env:
AWS_REGION: us-east-2
ECR_REPOSITORY: mfedockertest
ECS_SERVICE: mfedockertest-service
ECS_CLUSTER: mfedockertest-cluster
ECS_TASK_DEFINITION: ./task-definition.json
CONTAINER_NAME: mfedockertest-task-definition
AWS_DEFAULT_REGION: us-east-2
AWS_ACCESS_KEY_ID: ***
AWS_SECRET_ACCESS_KEY: ***
Error: Task definition file does not exist: ./task-definition.json

@tatianafrank
Copy link

Please anyone can help, failing at the same step as mentioned above. and i have my image

image

and my github is https://github.com/JohnQ1981/teachermonsters

env: AWS_REGION: us-east-2 ECR_REPOSITORY: mfedockertest ECS_SERVICE: mfedockertest-service ECS_CLUSTER: mfedockertest-cluster ECS_TASK_DEFINITION: ./task-definition.json CONTAINER_NAME: mfedockertest-task-definition AWS_DEFAULT_REGION: us-east-2 AWS_ACCESS_KEY_ID: *** AWS_SECRET_ACCESS_KEY: *** Error: Task definition file does not exist: ./task-definition.json

because your file is .yml but your path says .json

@islamsalah2020
Copy link

I faced the same issue, then I figured out that I need to download the task definition first then update it with the new container image. that solved the issue and I was able to deploy to ECS.

- name: Download task definition
      run: |
          aws ecs describe-task-definition --task-definition ${{ vars.MY_ECS_TASK_DEFINITION }} \
          --query taskDefinition > task-definition.json
      
 - name: Fill in the new image ID in the Amazon ECS task definition
      id: task-def
      uses: aws-actions/amazon-ecs-render-task-definition@v1
      with:
          task-definition: task-definition.json
          container-name: ${{ vars.MY_CONTAINER_NAME   }}
          image: ${{ steps.build-image.outputs.image }}

@shubhamnagota
Copy link

for anyone else finding this, it turns out task-definition: does not obey working_directory, so the relative path needs to be from the root of your repo

Continuing on @chorsnell answer, I changed task-definition.json to ./server/task-definition.json
you can change server to your-subdirectory-name
Turns out to be working.

      id: task-def
      uses: aws-actions/amazon-ecs-render-task-definition@v1
      with:
          task-definition: ./server/task-definition.json
          container-name: ${{ vars.MY_CONTAINER_NAME   }}
          image: ${{ steps.build-image.outputs.image }}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants