Creating an ECS cluster

0

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,
    });
  }
}
1 Answer
0

Apologies I’ve never used the cdk before but I am used to terraform.

Where have you defined which AZ and cidr range the subnets are setup?

Where are the routes for the subnets?

Do you have a screenshot of the the vpc and sinners that are created?

profile picture
EXPERT
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions