AWS Fargate

Article by:
Date Published:
Last Modified:


AWS Fargate is a container execution service provided by AWS. AWS manages the complexity of running and scaling the underlying infrastructure (which happens to be AWS EC2 instances).

Why Fargate?

The AWS Lambda service is another way you can run code in the cloud in a serverless manner. Choose lambda if:

  • You don’t need more than 500MB hard disk space
  • You don’t need more than 3GB of memory
  • Your program can finish within 15 minutes
  • Your program does not need heavy compute power

Choose AWS Fargate if:

  • You need more than 500MB disk space (you are only limited to what EC2 can provide).
  • You need more than 3GB of memory (you are only limited to what EC2 can provide).
  • Your program might take more than 15 minutes to complete. There is no runtime limitations with AWS Fargate.
  • Your program needs heavy compute power. Fargate provides you with all the CPU options that EC2 can offer.

CloudFormation is a good example of setting up a Fargate service in CloudFormation.

Hello, World Example

Invoke Fargate Job

You can invoke Fargate jobs from within Python by using boto3:

import boto3

client = boto3.client('ecs')
response = client.run_task(
cluster='fargatecluster', # name of the cluster
launchType = 'FARGATE',
taskDefinition='my-batch-job:1', # replace with your task definition name and revision
count = 1,
      'awsvpcConfiguration': {
          'subnets': [
              'subnet-2ec3a94a', # replace with your public subnet or a private with NAT
              'subnet-413a9c6e' # Second is optional, but good idea to have two
          'assignPublicIp': 'DISABLED'
return str(response)



Related Content:


comments powered by Disqus