After spending a whole day attempting to deploy ECS using EC2, I am encountering an error that is preventing the task from being placed due to no container instances meeting all the requirements. The reason given is that there are no Container Instances found in the cluster. This issue is outlined further in the Troubleshooting section of the Amazon ECS Developer Guide.
service prod-ecsStack-EC2Service5392EF94-71wVDsfHgsZh was unable to place a task because no container instance met all of its requirements. Reason: No Container Instances were found in your cluster. For more information, see the Troubleshooting section of the Amazon ECS Developer Guide.
I suspect that the CPU and memory allocation in my task definition container are too small. Currently, I am playing it safe with a t2.small instance, but I aim to use the smallest possible instance in the future.
The ECR houses the container repository, and it is constructed using the correct architecture.
This is my current CDK code. Thank you.
const vpc = new ec2.Vpc(this, 'PersonalWebsiteVpc', {
maxAzs: 2,
});
const cluster = new ecs.Cluster(this, 'PersonalWebsiteCluster', {
vpc: vpc
});
const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.SMALL),
machineImage: new ec2.AmazonLinuxImage(),
minCapacity: 1,
maxCapacity: 2
});
const capacityProvider = new ecs.AsgCapacityProvider(this, 'AsgCapacityProvider', {
autoScalingGroup: autoScalingGroup,
});
cluster.addAsgCapacityProvider(capacityProvider);
const repository = ecr.Repository.fromRepositoryName(this, 'MyRepository', 'my-personal-website-repo');
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
const container = taskDefinition.addContainer('web', {
image: ecs.ContainerImage.fromEcrRepository(repository, 'latest'),
memoryLimitMiB: 1024,
cpu: 512,
});
container.addPortMappings({
containerPort: 80,
hostPort: 80
});
new ecs.Ec2Service(this, 'EC2Service', {
cluster,
taskDefinition,
});