diff --git a/code b/code new file mode 100644 index 0000000..e990c91 --- /dev/null +++ b/code @@ -0,0 +1,53 @@ +import * as cdk from 'aws-cdk-lib'; +import * as ecs from 'aws-cdk-lib/aws-ecs'; +import * as ec2 from 'aws-cdk-lib/aws-ec2'; + +const app = new cdk.App(); + +const vpc = ec2.Vpc.fromLookup(app, 'Vpc', { + isDefault: true, +}); + +const cluster = new ecs.Cluster(app, 'MyTestCluster', { + vpc, + clusterName: 'mytestcluster', +}); + +cluster.addCapacity('DefaultAutoScalingGroup', { + instanceType: new ec2.InstanceType('t2.micro'), + desiredCapacity: 1, +}); + +const containerInsights = cluster.addDefaultCloudMapNamespace({ + name: 'containerInsights', +}); + +containerInsights.createService('MyTestService', { + name: 'mytestservice', + taskDefinition: new ecs.FargateTaskDefinition(app, 'MyTestTaskDefinition'), + cloudMapOptions: { + name: 'mytestservice', + }, +}); + +const taskDefinition = new ecs.FargateTaskDefinition(app, 'MyTestTaskDefinition'); + +taskDefinition.addContainer('MyTestContainer', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, +}); + +const service = new ecs.FargateService(app, 'MyTestService', { + cluster, + taskDefinition, + serviceName: 'mytestservice', + cloudMapOptions: { + name: 'mytestservice', + }, +}); + +service.attachToApplicationTargetGroup(new elbv2.ApplicationTargetGroup(app, 'MyTestTargetGroup', { + vpc, + port: 80, + targetType: elbv2.TargetType.IP, +})); \ No newline at end of file