I attempted to use code example from the AWS CDK documentation, but it did not function as I had anticipated.
Using CDK version 2.62.2 with Typescript. In various parts of the code, a declaration error occurs stating that
The argument of type "undefined" cannot be assigned to the parameter of type "Construct"
.
Code:
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
declare const vpc: ec2.Vpc;
// Creating an ECS cluster
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
// Adding capacity to the cluster
cluster.addCapacity('DefaultAutoScalingGroupCapacity', {
instanceType: new ec2.InstanceType("t2.xlarge"),
desiredCapacity: 3,
});
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('DefaultContainer', {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
memoryLimitMiB: 512,
});
// Initializing an Amazon ECS Service
const ecsService = new ecs.Ec2Service(this, 'Service', {
cluster,
taskDefinition,
});