Search code examples
amazon-ecsaws-fargateaws-auto-scaling

AWS ECS Fargate: How to create a service with auto scaling with the service API


I do not understand how I can create auto scaling for a ecs fargate service with the API. I create my service with code like this with the ecs create service api:

{    
    "serviceName": "my-service",
    "cluster": "my-cluster",
    "taskDefinition": "my-task",
    "desiredCount": 1,
    "launchType": "FARGATE",
    "loadBalancers":[
        {
            "targetGroupArn": my_target_group_arn,
            "containerName": "my-container-nginx",
            "containerPort": 8090
        }        
    ],
    "networkConfiguration": {
        'awsvpcConfiguration': {
            'subnets': settings.AWS_SUBNET_IDS,
            'securityGroups': [securitygroup_id]
        }
    },   

}

How to add the auto scaling, which I can configure in the AWS console in the browser easily? Do I have to create a capacityProvider?


Solution

  • This documentation walks you through how to configure a service autoscaling policy for ECS via the CLI. Note that often the console provides a "macro" experience to make all the steps easier whereas if you have to do the same with the CLI/API it's often multiple steps (as outlined in the doc).