snippetMinor
How do you instruct AWS FARGATE to provision a t2.small via ECS CLI instead of the default micro?
Viewed 0 times
microtheyouprovisionecsinsteaddefaultsmallviaaws
Problem
I am trialling AWS ECS for the first time. I've run through the tutorials and now I'm trying to deploy an existing Docker Compose suite which I've been using on Digital Ocean for some time.
I have four containers in my composition, an ExpressJS app, NGinx, MemcacheD, and a Python Flask API. These work OK on a Digital Ocean 1GB RAM host.
I've been following the guide and specs here: https://github.com/aws/amazon-ecs-cli#launching-an-aws-fargate-task and other general ECS CLI guides.
I've got ECS to make the cluster+service from the docker YAML (with a few tweaks), but when I try to UP the service, I get an error that the t2.micro EC2 which Fargate boots isn't big enough:
So I'd like to force it to boot an t2.small (2GB RAM) or higher.
I see that you cannot directly tell Fargate to use a specific instant type from ECS - that setting is only for "EC2" direct, but I want to use Fargate to automate the instance management.
I have tried using the
I added this YML file with
When I rebuild my cluster from scratch with this definition, I can see the 2GB is correctly configured under the taskDefinition page (
Am I misunderstanding the task_size.memory parameter?
EDIT:
I w
I have four containers in my composition, an ExpressJS app, NGinx, MemcacheD, and a Python Flask API. These work OK on a Digital Ocean 1GB RAM host.
I've been following the guide and specs here: https://github.com/aws/amazon-ecs-cli#launching-an-aws-fargate-task and other general ECS CLI guides.
I've got ECS to make the cluster+service from the docker YAML (with a few tweaks), but when I try to UP the service, I get an error that the t2.micro EC2 which Fargate boots isn't big enough:
INFO[0016] (service CI) was unable to place a task because no container instance met all of its requirements.
The closest matching (container-instance ...) has insufficient memory available.
For more information, see the Troubleshooting section of the Amazon ECS Developer Guide.So I'd like to force it to boot an t2.small (2GB RAM) or higher.
I see that you cannot directly tell Fargate to use a specific instant type from ECS - that setting is only for "EC2" direct, but I want to use Fargate to automate the instance management.
I have tried using the
task_size memory parameter (which I believe to be the correct way of informing Fargate of your application's requirements?) but this doesn't affect the choice of EC2 instance type which Fargate boots - it still boots the default t2.micro.I added this YML file with
--ecs-params:version: 1
task_definition:
task_size:
cpu_limit: 512
mem_limit: 2GBWhen I rebuild my cluster from scratch with this definition, I can see the 2GB is correctly configured under the taskDefinition page (
console.aws.amazon.com/ecs/home#/taskDefinitions/...) - so the configuration is provided OK, but when I view the instance it's booted, it's still a t2.micro with 1GB RAM.Am I misunderstanding the task_size.memory parameter?
EDIT:
I w
Solution
The short answer is "you don't have to".
The long answer is I was doing it wrong. Here's what was wrong and what I learned.
After working through tutorials, RTFMing and re-building my ECS configuration I found that I actually wasn't launching via Fargate. I had made a mistake during the initial
I figured out the mistake by viewing the config file. I noticed
So I then tried the EC2-only parameter:
and this changed the Autoscaling Group and indeed launched a t2.small. So I now know how to do it the EC2 way.
To do it properly as I had originally intended with Fargate, I needed
Now the config looks like this:
After doing this,
e.g.
It's very clear now I see it. There are no instances for Fargate services.
You can also watch Fargate re-start the task-containers if they fail, either in the control panel, or with
The long answer is I was doing it wrong. Here's what was wrong and what I learned.
After working through tutorials, RTFMing and re-building my ECS configuration I found that I actually wasn't launching via Fargate. I had made a mistake during the initial
configure command, so the default config was using EC2 launch type. When making the cluster it created an Autoscaling Group template with t2.micro in it, and then it was using this to launch the initial instance. I didn't think this was unusual, as I read that Fargate managed your EC2's for you, which I presumed was what was happening. No, this was "traditional" EC2 creation via a scaling template.I figured out the mistake by viewing the config file. I noticed
ecs-cli doesn't have any "view config" commands - they only write to the config, so it feels a bit mysterious when you are issuing later commands, especially as you are encouraged to set lots of defaults (presumably to simplify the CLI commands which get long and cumbersome).less ~/.ecs/config
version: v1
default: MY-TRIAL-CONFIG
clusters:
MY-TRIAL-CONFIG:
cluster: MY-TRIAL-CLUSTER
region: ap-southeast-2
default_launch_type: "" <= this was the problem
tutorial:
cluster: tutorial
region: ap-southeast-2
default_launch_type: FARGATESo I then tried the EC2-only parameter:
ecs-cli up --instance-type "t2.small" --capability-iamand this changed the Autoscaling Group and indeed launched a t2.small. So I now know how to do it the EC2 way.
To do it properly as I had originally intended with Fargate, I needed
default-launch-type FARGATE:ecs-cli configure --cluster MY-TRIAL-CLUSTER --region ap-southeast-2 --default-launch-type FARGATE --config-name MY-TRIAL-CONFIGNow the config looks like this:
less ~/.ecs/config
version: v1
default: MY-TRIAL-CONFIG
clusters:
MY-TRIAL-CONFIG:
cluster: MY-TRIAL-CLUSTER
region: ap-southeast-2
default_launch_type: FARGATE
tutorial:
cluster: tutorial
region: ap-southeast-2
default_launch_type: FARGATEAfter doing this,
ecs-cli compose service up works very differently from the observed ECS launch flow.- it doesn't create any Autoscaling stuff
- it doesn't launch any EC2 instances (I thought Fargate did, but managed it for you, but you don't get to see the container hosts)
- It created a Cloudformation Stack instead (interestingly with a t2.micro EcsInstanceType parameter)
- It's very clearly labelled on the Cluster home page: there's a row for EC2 launch types below the FARGATE row.
e.g.
MY-TRIAL-CLUSTER >
FARGATE
1 0 1
Services Running tasks Pending tasks
EC2
0 0 0 0
Services Running tasks Pending tasks CPUUtilization MemoryUtilization Container instancesIt's very clear now I see it. There are no instances for Fargate services.
You can also watch Fargate re-start the task-containers if they fail, either in the control panel, or with
ecs-cli compose service ps and ecs-cli logs --task-id XXX --follow, to get a feel for the magic and how the Docker Compose features are being performed.Code Snippets
less ~/.ecs/config
version: v1
default: MY-TRIAL-CONFIG
clusters:
MY-TRIAL-CONFIG:
cluster: MY-TRIAL-CLUSTER
region: ap-southeast-2
default_launch_type: "" <= this was the problem
tutorial:
cluster: tutorial
region: ap-southeast-2
default_launch_type: FARGATEecs-cli up --instance-type "t2.small" --capability-iamecs-cli configure --cluster MY-TRIAL-CLUSTER --region ap-southeast-2 --default-launch-type FARGATE --config-name MY-TRIAL-CONFIGless ~/.ecs/config
version: v1
default: MY-TRIAL-CONFIG
clusters:
MY-TRIAL-CONFIG:
cluster: MY-TRIAL-CLUSTER
region: ap-southeast-2
default_launch_type: FARGATE
tutorial:
cluster: tutorial
region: ap-southeast-2
default_launch_type: FARGATEMY-TRIAL-CLUSTER >
FARGATE
1 0 1
Services Running tasks Pending tasks
EC2
0 0 0 0
Services Running tasks Pending tasks CPUUtilization MemoryUtilization Container instancesContext
StackExchange DevOps Q#5651, answer score: 1
Revisions (0)
No revisions yet.