English 中文(简体)
Passing the cluster ref to another stack and adding capacityprovider makes cyclic reference
原标题:

I want to make two ECS Services(admin and ai) and let each service has each capacityprovider.

Now I made two codes for admin stack and ai stack

This is my admin stack, it works well.

//make cluster
const cluster = new ecs.Cluster(this, `sm-${targetEnv}-Cluster`, {
  vpc:vpc,
});

//make autosacaling group 
const adminAutoScalingGroup = new autoscaling.AutoScalingGroup(this,  admin-asg , {
  vpc,
  keyName:"ssh-test",
  instanceType: new ec2.InstanceType( t2.medium ),
  machineImage: ecs.EcsOptimizedImage.amazonLinux(),
  securityGroup:instanceSg,     
  minCapacity:1,
  maxCapacity:3,
});

// make capacityprovider
const adminCapacityProvider = new ecs.AsgCapacityProvider(this,  admin-asg-capacity-provider , {
  autoScalingGroup:adminAutoScalingGroup,
});

// add capacityprovider to cluster
cluster.addAsgCapacityProvider(adminCapacityProvider);

//make service with capacity provider
const ecsAdminService = new ecs.Ec2Service(this,  AdminService , {
  cluster,
  taskDefinition:adminTaskDefinition,
  capacityProviderStrategies: [{
    capacityProvider: adminCapacityProvider.capacityProviderName,
    base: 1,
    weight: 1,
  }]
})

Then, I try to do the same thing in ai stack

//at first get cluster from admin stack
export interface SmAiStackProps extends StackProps {
  readonly cluster: admin.Cluster;
}

then

//make autoscaling group
const aiAutoScalingGroup = new autoscaling.AutoScalingGroup(this,  ai-asg , {
  vpc,
  instanceType: new ec2.InstanceType( g4dn.xlarge ),
  machineImage: ec2.MachineImage.genericLinux({
    "ap-northeast-1":"ami-023ec1c000b5029be"
  }),
  minCapacity:0,
  maxCapacity:1,
});

// make capacity provider
const aiCapacityProvider = new ecs.AsgCapacityProvider(this,  ai-asg-capacity-provider , {
  autoScalingGroup:aiAutoScalingGroup,
});

// add capacity provider.
props!.cluster.addAsgCapacityProvider(aiCapacityProvider);

// add service
const ecsAiService = new ecs.Ec2Service(this,  AiService , {
  cluster: props!.cluster,
  taskDefinition:aiTaskDefinition,      
  capacityProviderStrategies: [{
    capacityProvider: aiCapacityProvider.capacityProviderName,
    base: 1,
    weight: 1,
  }]
})

However now it shows the error when deploying ai stack

throw new Error(` ${target.node.path}  depends on  ${this.node.path}  (${cycleDescription}). Adding this dependency (${reason.description}) would create a cyclic reference.`);
            ^
Error:  sm-dev-ecs  depends on  ol-dev-ai  (sm-dev-ecs -> sm-dev-ai/ai-asg-capacity-provider/ai-asg-capacity-provider.Ref). Adding this dependency (sm-dev-ai -> sm-dev-ecs/sm-dev-Cluster/Resource.Arn) would create a cyclic reference.

I guess this error happens here in ai stack code

// add capacity provider.
props!.cluster.addAsgCapacityProvider(aiCapacityProvider);

The difference is that in admin stack, cluster is made there, but in ai stack, cluster is passed from admin stack.

However I have no idea why this makes cyclic reference.

Why this happens?

问题回答

暂无回答




相关问题
Mount windows shared drive to MWAA in bootscript

In MWAA startup script sudo yum install samba-client cifs-utils -y sudo mount.cifs //dev/test/drop /mnt/dev/test-o username=testuser,password= pwd ,domain=XX Executing above commonds giving error - ...

How to get Amazon Seller Central orders programmatically?

We have been manually been keying Amazon orders into our system and would like to automate it. However, I can t seem to figure out how to go about it. Their documentation is barely there. There is: ...

Using a CDN like Amazon S3 to control access to media

I want to use Amazon S3/CloudFront to store flash files. These files must be private as they will be accessed by members. This will be done by storing each file with a link to Amazon using a mysql ...

unable to connect to database on AWS

actually I have my website build with Joomla hosted on hostmonster but all Joomla website need a database support to run this database is on AWS configuration files need to be updated for that I ...

Using EC2 Load Balancing with Existing Wordpress Blog

I currently have a virtual dedicated server through Media Temple that I use to run several high traffic Wordpress blogs. Both tend to receive sudden StumbleUpon traffic surges that (I m assuming) ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

热门标签