Aws-cli: ecs register-task-definition only --cli-input-json not working

Created on 15 Sep 2018  路  3Comments  路  Source: aws/aws-cli

I have the following base task definition with JSON format:

{
    "taskDefinition": {
        "status": "ACTIVE", 
        "memory": "128", 
        "networkMode": "bridge", 
        "family": "my-task-name", 
        "placementConstraints": [], 
        "requiresAttributes": [
            {
                "name": "ecs.capability.execution-role-ecr-pull"
            }, 
            {
                "name": "com.amazonaws.ecs.capability.ecr-auth"
            }, 
            {
                "name": "com.amazonaws.ecs.capability.task-iam-role"
            }
        ], 
        "cpu": "128", 
        "executionRoleArn": "arn:aws:iam::%ACCOUNT_ID%:role/SOME-ROLE", 
        "compatibilities": [
            "EC2"
        ], 
        "volumes": [], 
        "requiresCompatibilities": [
            "EC2"
        ], 
        "taskRoleArn": "arn:aws:iam::%ACCOUNT_ID%:role/SOME-ROLE", 
        "taskDefinitionArn": "arn:aws:ecs:%REGION%:%ACCOUNT_ID%:task-definition/my-task-name:%BUILD_NUMBER%", 
        "containerDefinitions": [
            {
                "environment": [], 
                "name": "some-container-name", 
                "mountPoints": [], 
                "image": "%ECR_BASE_URL%/some-repo-name:latest", 
                "cpu": 128, 
                "portMappings": [
                    {
                        "protocol": "tcp", 
                        "containerPort": 3000, 
                        "hostPort": 3000
                    }
                ], 
                "memory": 128, 
                "essential": true, 
                "volumesFrom": []
            }
        ]
    }
}

I am trying execute a task definition on mi CI, with the following command:

- sed -e "s;%BUILD_NUMBER%;${COMMIT_SHA};g" -e "s;%ACCOUNT_ID%;${AWS_ACCOUNT_ID};g" -e "s;%REGION%;${AWS_REGION};g" -e "s;%ECR_BASE_URL%;${ECR_BASE_URL};g" base-task-definition.json > task-definition-${COMMIT_SHA}.json
- aws ecs register-task-definition --cli-input-json "file://task-definition-${COMMIT_SHA}.json"

But I am get the error when I try register the task definition:

Parameter validation failed:
Missing required parameter in input: "family"
Missing required parameter in input: "containerDefinitions"
Unknown parameter in input: "taskDefinition", must be one of: family, taskRoleArn, executionRoleArn, networkMode, containerDefinitions, volumes, placementConstraints, requiresCompatibilities, cpu, memory

My aws cli version is: aws-cli/1.16.14 Python/2.7.15 Linux/4.14.48-coreos-r2 botocore/1.12.4

According to the official documentation is a way to register a task: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_AWSCLI_EC2.html#AWSCLI_EC2_register_task_definition

What am I doing wrong?

guidance

Most helpful comment

Hi again, I could resolve my problem, I really needed to have as a base a container-definition, like as this:

{
    "containerDefinitions": [
        {
            "environment": [], 
            "name": "s", 
            "mountPoints": [], 
            "image": "%ECR_BASE_URL%/some-repo-name:latest", 
            "cpu": 128, 
            "portMappings": [
                {
                    "protocol": "tcp", 
                    "containerPort": 3000, 
                    "hostPort": 3000
                }
            ], 
            "memory": 128, 
            "essential": true, 
            "volumesFrom": []
        }
    ]
}

I'll leave this here, in case someone is as clueless as me. xD.

All 3 comments

Hi again, I could resolve my problem, I really needed to have as a base a container-definition, like as this:

{
    "containerDefinitions": [
        {
            "environment": [], 
            "name": "s", 
            "mountPoints": [], 
            "image": "%ECR_BASE_URL%/some-repo-name:latest", 
            "cpu": 128, 
            "portMappings": [
                {
                    "protocol": "tcp", 
                    "containerPort": 3000, 
                    "hostPort": 3000
                }
            ], 
            "memory": 128, 
            "essential": true, 
            "volumesFrom": []
        }
    ]
}

I'll leave this here, in case someone is as clueless as me. xD.

@fernandops26 , to rephrase your answer, instead of:

{
    "taskDefinition": { 
        "containerDefinitions": [
        ]
    }
}

Change it to this:

{
    "containerDefinitions": [
    ]
}

in other words, remove "taskDefinition".

Hi, i am stilll getting the same error can anybody please help how can i resolve the same.
My CI pipeline is in Jenkins , how can i refer to this taskdef.json in the jenkinsfile.
Please help me with the same

Was this page helpful?
0 / 5 - 0 ratings