From 2990e66558215cbc0675ff4f9836ddf0c144de19 Mon Sep 17 00:00:00 2001 From: kms254 <36774146+kms254@users.noreply.github.com> Date: Wed, 29 Nov 2023 19:15:36 -0800 Subject: [PATCH] Codification: code --- code | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 code 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