如何在AWS CDK中引用生成的域名“elasticsearch.CfnDomain”?
How can I refer to the generated domain name of `elasticsearch.CfnDomain` in AWS CDK?
我在 AWS CDK 中创建了一个 CfnDomain
,我试图获取生成的域名来创建警报。
const es = new elasticsearch.CfnDomain(this, id, esProps);
new cloudwatch.CfnAlarm(this, "test", {
...
dimensions: [
{
name: "DomainName",
value: es.domainName,
},
],
});
但是好像domainName
这个属性其实是我传入的参数(我传了none所以会自动生成),所以实际上是undefined
并且不能'不能使用。
有没有什么方法可以指定它等待创建elasticsearch集群以便我可以获得生成的域名,或者有什么其他方法可以为以下指标创建警报集群?
您使用 CfnDomain.ref
作为维度的域值。红色集群状态的示例警报创建:
const domain: CfnDomain = ...;
const elasticDimension = {
"DomainName": domain.ref,
};
const metricRed = new Metric({
namespace: "AWS/ES",
metricName: "ClusterStatus.red",
statistic: "maximum",
period: Duration.minutes(1),
dimensions: elasticDimension
});
const redAlarm = metricRed.createAlarm(construct, "esRedAlarm", {
alarmName: "esRedAlarm",
evaluationPeriods: 1,
threshold: 1
});
我在 AWS CDK 中创建了一个 CfnDomain
,我试图获取生成的域名来创建警报。
const es = new elasticsearch.CfnDomain(this, id, esProps);
new cloudwatch.CfnAlarm(this, "test", {
...
dimensions: [
{
name: "DomainName",
value: es.domainName,
},
],
});
但是好像domainName
这个属性其实是我传入的参数(我传了none所以会自动生成),所以实际上是undefined
并且不能'不能使用。
有没有什么方法可以指定它等待创建elasticsearch集群以便我可以获得生成的域名,或者有什么其他方法可以为以下指标创建警报集群?
您使用 CfnDomain.ref
作为维度的域值。红色集群状态的示例警报创建:
const domain: CfnDomain = ...;
const elasticDimension = {
"DomainName": domain.ref,
};
const metricRed = new Metric({
namespace: "AWS/ES",
metricName: "ClusterStatus.red",
statistic: "maximum",
period: Duration.minutes(1),
dimensions: elasticDimension
});
const redAlarm = metricRed.createAlarm(construct, "esRedAlarm", {
alarmName: "esRedAlarm",
evaluationPeriods: 1,
threshold: 1
});