aws-actions/amazon-ecs-render-task-definition

Bug: Invalid task definition: Could not find container definition with matching name

Abdullah-Shahen opened this issue · 2 comments

I'm using this action with the latest version as well as with the v1.1.3, for one ECS Service, it works just fine, for the other service it does not. Rendering of the ECS Task fails with Error: Invalid task definition: Could not find container definition with matching name.
I have checked the ECS Task JSON and it contains the container name.

Both Services are identical in terms of ECS Task def structure. Just Env. vars are different.

Here my current action step:

      - name: Create new AWS ECS task definition on Stage (DEV)
        id: dev-task-def
        uses: aws-actions/amazon-ecs-render-task-definition@v1.1.3 # Also used latest and it did not work.
        with:
          task-definition: task-definition.json
          container-name: ${{ inputs.ECS_CONTAINER_NAME }}
          image: ${{ steps.dev-image-build.outputs.image }}

@vitalykarasik was somehow able to get it to work (see Issue), still we don't know why it does not work in this case.

Any Idea or hint on how to fix this is highly appreciated.

I'm having the same issue. Here are the things I've tried to far-

  • Went to version 1.1.2, 1.0.9, 1.0.2
  • hard coded the ecr image and URI
  • Quotes, single quotes
  • Manually created task with the image URI I intended to use (did to confirm i was using the right arn)
  • provide ecs:* and ecr:* to ensure gitub action role had enough permissions (previous jobs already validated this, but i was getting desperate.)

None of these got this action to work while disproving other issues. I think i'm just going to go with writing my own script here.

Never mind, I'm a silly goose. I had container-name as the name of the container or repo in ecr not the name of the container in the task definition or more specifically the container definition.

Updating that fixed it and works on 1.1.3 for me.

UPDATE as of 21st Spt. 2023

The action is now working without issues.

In case this action is not working for you, here's an alternative:

#!/bin/bash

# Check if the new image parameter is provided
if [ $# -eq 0 ]; then
    echo "Usage: $0 <new_image>"
    exit 1
fi

# Read the new image from the command line argument
new_image=$1

# Read the JSON file into a variable
json_data=$(cat task-definition.json)

# Use jq to update the "image" field with the new value
updated_json=$(echo "$json_data" | jq --arg new_image "$new_image" '.containerDefinitions[0].image = $new_image')

# Save the updated JSON back to the file
echo "$updated_json" > task-definition.json

Run like:

./aws-ecs-task-def-renderer.sh <YOUR_NEW_IMAGE_TAG_HERE>