awsdocs / amazon-ecs-developer-guide

The open source version of the Amazon ECS developer guide. You can submit feedback & requests for changes by submitting issues in this repo or by making proposed changes & submitting a pull request.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to calculate task definition size

hectron opened this issue · comments

Hi there!

I have had an issue in the past where I have attempted to register a task definition, but it got rejected because it was over the size limit. I looked up the ECS service limits here and was able to identify that there's a 32 KiB limit.

However, what do I need to calculate that number? Is there an AWS CLI command that I can use?

The closest thing to this that I attempted to do is to use the AWS CLI command as follows:

aws ecs describe-task-definition --task-definition <TASK_DEFINITION_NAME> > definition.json

And then check the size of it using ls -ahl. However, this results in a file size that's bigger than 32 kb.

If the total file size of your task definition is over 32 KiB, then that error will come up.

@joelbrandenburg , would you happen to know how to get the total file size of a task definition? I'm not seeing it in the UI, or through the CLI.

@hectron if you save your task definition as a JSON file and check the size, that should tell you.

@joelbrandenburg I have done the following

aws ecs describe-task-definition --task-definition my-task:01 > definition.json

ls -ahl definition.json

-rw-r--r--  1 hectron  hectron    83K Sep 19 16:27 definition.json

Notice how it's 83K. I then minified that file:

ls -ahl minified_definition.json

-rw-r--r--  1 hectron  hectron    40K Sep 19 16:28 minified_definition.json

And after minifying the JSON, it's 40K.

Another approach that I have attempted is to use the AWS UI to save the task definition as a JSON file and check the size. This yields the same value AFTER I minify it.

This is the area where I'm grabbing the JSON from:

image

I also noticed that this limit is in Kibibytes, so I converted it from Kilobyte to Kibibyte:

image

Are you sure that this JSON is what is used to calculate the limit? My data is showing otherwise.

All of those methods leave your task definition over the 32 KiB limit. I'll get confirmation on how exactly the size is being determined and update this issue once I find out.

@hectron it's unusual for a task definition to be over 32 KiB. Are you passing in a command or a large amount of environment variables that is making it so large?

The size limit of the task definition is determined on our backend once it's registered so it's difficult to give an exact answer of how someone could measure it prior to registering it to determine what size is valid, however a general rule of thumb is that a task definition should not contain more than 32,000 characters or should be less than 32 KiB as a JSON document.

If you would like assistance in finding a way to get your task definition down below the 32 KiB limit, can you share details of what you're putting into your task definition?

@joelbrandenburg I'm passing in a lot of environment variables, hence why it's so large.

I copied the environment variables that were used and reduced them from an array of dictionaries to a key-value string of the form key1=value1 key2=value2 ... keyN=valueN. This approach resulted in my environment variables being under 32KiB (they sit around 28KiB). My guess is that the backend does some kind of minification/normalization that is not obvious in the JSON document.