[英]Can a CloudWatch Custom Metric be a variable instead of a hard-coded string
I have created a AWS custom metric in CloudWatch.我在 CloudWatch 中创建了一个 AWS 自定义指标。 I am using NodeJs Lambda function to create a custom metric along with dimensions.我正在使用 NodeJs Lambda function 来创建自定义指标和维度。 I would like to know if we can pass variable value to dimensions instead of string (hardcoded strings).我想知道我们是否可以将变量值传递给尺寸而不是字符串(硬编码字符串)。 Does dimension values accept anything other then string value?维度值是否接受字符串值以外的任何值?
This works:这有效:
var params = {
MetricData: [
{
MetricName: 'PAGES_VISITED',
Dimensions: [
{
Name: 'UNIQUE_PAGES',
Value: '**URLS**'
},
],
Unit: 'None',
Value: 1.0
},
],
Namespace: 'SITE/TRAFFIC'
}
But I want to pass something like this:但我想传递这样的东西:
MetricData: [
{
MetricName: 'PAGES_VISITED',
Dimensions: [
{
Name: 'MessageAttributes',
Value: msgattr
},
{
Name: 'CompanyName',
Value: process.env.CompanyName
},
{
Name: 'short_description',
Value: message
},
],
Unit: 'None',
Value: 10.0
},
],
Yes, that will work fine.是的,那会很好用。
The Value
variables for Dimensions can only be strings, but you can provide those strings by referencing variables. Dimensions 的Value
变量只能是字符串,但您可以通过引用变量来提供这些字符串。
To see the result, simply print(params)
and you will see that the values from the variables have been stored.要查看结果,只需print(params)
即可,您将看到变量的值已被存储。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.