Open your CDK project and create a new stack named ClusterStack.java.

To create the ECS stack, we need the VPC that we previously created. Therefore, we need to create a record class to pass the VPC into the ECS Stack. Add the following code outside the ClusterStack class:
record ClusterStackProps(Vpc vpc) {}

Create the cluster property and a getter method within the ClusterStack class:
private final Cluster cluster;
public Cluster getCluster() {
return cluster;
}

public ClusterStack(final Construct scope, final String id,
final StackProps props, ClusterStackProps clusterStackProps) {
super(scope, id, props);
}

ClusterStack.java using the following code: this.cluster = new Cluster(this, "Cluster", ClusterProps.builder()
.build());

.clusterName("ECommerce")

.vpc(clusterStackProps.vpc())

.containerInsights(true)

Open the file named Fcj2024CdkApp in the root directory.

Create an ECS Stack with the ID Vpc using the following code snippet:
ClusterStack clusterStack = new ClusterStack(app, "Cluster", StackProps.builder()
.build());

new ClusterStackProps(vpcStack.getVpc())

.env(environment)
.tags(infraTags)

clusterStack.addDependency(vpcStack);

cdk deploy --all
cdk deploy --all --require-approval never

Check the newly created cluster:

In the ECS interface, you should see a cluster named ECommerce that has been created.
