CapacityProviderStrategies of EC2Service shows the error, The specified capacity provider ****** was not found

huangapple go评论72阅读模式
英文:

CapacityProviderStrategies of EC2Service shows the error, The specified capacity provider ****** was not found

问题

Here's the translated content you requested:

从这篇文章(已解决,但与此文章相关)

我创建了两个AutoScalingGroup,两个AsgCapacityProvider和两个ecs on ec2 service

现在我想将这些CapacityProvider附加到每个service

但是,出现了错误

指定的容量提供程序myapp-dev-admin-cp未找到

const adminCapacityProvider = new ecs.AsgCapacityProvider(this, 'admin-asg-capacity-provider', {
  autoScalingGroup: adminAutoScalingGroup,
  capacityProviderName: `myapp-${targetEnv}-admin-cp`
});

const adminCapacityProvider2 = new ecs.AsgCapacityProvider(this, 'admin-asg-capacity-provider2', {
  autoScalingGroup: adminAutoScalingGroup2,
  capacityProviderName: `myapp-${targetEnv}-admin-cp2`
});

cluster.addAsgCapacityProvider(adminCapacityProvider);
cluster.addAsgCapacityProvider(adminCapacityProvider2);

const ecsAiService = new ecs.Ec2Service(this, 'AiService', {
  cluster,
  taskDefinition: aiTaskDefinition,
  serviceName: `myapp-${targetEnv}-ai-service`,
  enableExecuteCommand: true,
  securityGroups: [adminServiceSg],
  vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },
  capacityProviderStrategies: [
    { capacityProvider: `myapp-${targetEnv}-admin-cp` } // 错误发生在这里
  ]
})

我在Google上查找并发现,对于Fargate,应该在这里放置FARGATEFARGATE_SPOT,但是我的是ECS on EC2

对于capacityProviderStrategies的props,我应该使用什么?

谢谢任何帮助。

请注意,我只提供了代码的翻译部分,不包括问题或感谢部分。如果需要更多信息,请告诉我。

英文:

From this article (that is solved but this article is related)

I made two AutoScalingGroup, two AsgCapacityProvider and two ecs on ec2 service

Now I want to attach these CapacityProvider to each service.

However, There is error

The specified capacity provider myapp-dev-admin-cp was not found

const adminCapacityProvider = new ecs.AsgCapacityProvider(this, 'admin-asg-capacity-provider', {
  autoScalingGroup:adminAutoScalingGroup,
  capacityProviderName: `myapp-${targetEnv}-admin-cp`
});

const adminCapacityProvider2 = new ecs.AsgCapacityProvider(this, 'admin-asg-capacity-provider2', {
  autoScalingGroup:adminAutoScalingGroup2,
  capacityProviderName: `myapp-${targetEnv}-admin-cp2`
});

cluster.addAsgCapacityProvider(adminCapacityProvider);
cluster.addAsgCapacityProvider(adminCapacityProvider2);

const ecsAiService = new ecs.Ec2Service(this, 'AiService', {
  cluster,
  taskDefinition:aiTaskDefinition,
  serviceName: `myapp-${targetEnv}-ai-service`,
  enableExecuteCommand:true,
  securityGroups: [adminServiceSg],
  vpcSubnets:{subnetType: ec2.SubnetType.PUBLIC },
  capacityProviderStrategies:[
    capacityProvider:`myapp-${targetEnv}-admin-cp`// error occurs here
  ]
})

I googled around and found for fargate, FARGATE or FARGATE_SPOT should be put here, however my one is ECS on EC2.

What should I use for capacityProviderStrategie's props?

Thanks for any help.

答案1

得分: 1

这可能是因为在创建服务之前已经创建了容量提供程序。

要创建隐式依赖关系(同时还去掉了在两个地方指定容量提供程序名称的需求),请尝试以下方法:

...
  capacityProviderStrategies:[
    capacityProvider: adminCapacityProvider.capacityProviderName
  ]
...

这将告诉 CDK,您的服务依赖于容量提供程序,并且只在它被配置后才创建它。

英文:

This might be due to the fact that the service is being created before the capacity provider.

To create an implicit dependency (while also removing the need to specify the name of the capacity provider in two places), try this:

...
  capacityProviderStrategies:[
    capacityProvider: adminCapacityProvider.capacityProviderName
  ]
...

This will let CDK know that your service depends on the capacity provider and only create it after it's been provisioned.

huangapple
  • 本文由 发表于 2023年5月14日 21:18:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247682.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定