如何通过名称获取已存在的集群?

问题描述 投票:0回答:1

我正在使用

CDK
并且想使用现有集群(用于ECS)

我尝试了这个,但它显示,

错误如

Property 'fromClusterName' does not exist on type 'typeof Cluster'. Did you mean 'fromClusterArn'?

const clusterName = "mycluster"
const cluster = ecs.Cluster.fromClusterName(this, "StCluster", {
  clusterName: clusterName
});

但是,我想通过

name
而不是
arn

来获取集群

我想我应该提前记下

arn
的名字?

我正在查看这个文档,没有办法通过名字获取

Cluster

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.Cluster.html

我该怎么做?

amazon-web-services amazon-ecs aws-cdk
1个回答
0
投票

您可以使用

fromClusterAttributes
,但您还需要拥有集群所在的
vpc
。这是首选,因为它还可以访问
vpc
和其他属性。

const clusterName = "mycluster"
const cluster = ecs.Cluster.fromClusterAttributes(this, "iCluster", {
  "vpc": myVpc,
  "clusterName": clusterName
})

© www.soinside.com 2019 - 2024. All rights reserved.