I created an ECS cluster with the configuration of Capacity provider as EC2 instances. I choose a VPC similar to the default VPC. The auto-scaling group minimum size was 1. But when I create the cluster, no EC2 register in the Container instances. However, if I choose the default VPC it works well. What is the reason?
This is my code to create a VPC:
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import { Construct } from 'constructs';
export class VPC_Stack extends cdk.Stack {
public readonly vpc: ec2.Vpc;
constructor(scope: Construct, id: string, stackName: string, appName: string) {
super(scope, id, {
stackName: appName + '-' + stackName,
});
const name = appName + '-' + stackName + 'VPC';
this.vpc = new ec2.Vpc(this, name + '-id', {
cidr: '10.0.0.0/16',
maxAzs: 3,
subnetConfiguration: [
{
name: 'PublicSubnet',
subnetType: ec2.SubnetType.PUBLIC,
cidrMask: 24,
},
{
name: 'PrivateSubnet',
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
cidrMask: 24,
},
],
natGateways: 1,
vpcName: name
});
new cdk.CfnOutput(this, 'VpcId', {
value: this.vpc.vpcId,
});
}
}
It is impossible to share a picture here so I put a snapshot of the created VPC in my GitHub at: https://raw.githubusercontent.com/mnamvarcfd/AWS-CDK-Refrence-guide/master/VPC.bmp
Please let me know if you need any further information.