According to Amazon's official documentation,

For Amazon ECS, AWS Fargate pricing is calculated based on the vCPU and memory resources used from the time you start to download your container image (docker pull) until the Amazon ECS Task* terminates, rounded up to the nearest second. A minimum charge of 1 minute applies.

Does this mean that

a) It knows when my containers consume cpu/ram and applies charges only for this time frames?

b) It aplies charges based on pre-allocations I do when creating the tasks?


Orchestration Timers

Regardless of the internal implementation, there is most likely an orchestrator that starts and stops a timer based on particular signals or events within the Fargate service. Basically, the charges are from when the pull command are executed until an orchestration process issues or receives the termination command/signal for your process. Conceptually, think of it as similar to wrapping a shell script in time { :; }.

Again conceptually, you might think of the way it charges as the following pseudocode:

cpu_charges = $num_cpus * cpu_rate_per_second
mem_charges = $mem_size * mem_rate_per_second
charge_rate = cpu_charges + mem_charges

elapsed_time = time () {
    docker pull foo_image
    docker run --cpus $num_cpus -m $mem_size -it --rm foo_image

bill_for elapsed_time * charge_rate

I am not currently aware of any public documentation that exposes the real mechanics of how this is internally implemented by AWS, but this is likely accurate enough for most practical purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.