https://pulumi.com logo
Title
e

echoing-actor-55539

11/10/2022, 8:53 PM
I am trying to create an
aws.cloudwatch.MetricAlarm
however i cant see how to get the filterId from
aws.s3.BucketMetric
snip:
const bucket = new aws.s3.BucketV2(
  `viz-bucket-${region}`,
  {
    bucketPrefix: `par-${region}-`,
    forceDestroy: true
  },
  {provider: PriActProviders[region]}
);

const bucketMetrics = new aws.s3.BucketMetric(
  `bucketMetrics-${region}`,
  {bucket: bucket.bucket},
  {provider: PriActProviders[region], parent: bucket}
);

// create alarm for R53 to monitor as health check
const bucketMetricAlarm = new aws.cloudwatch.MetricAlarm(
  `bucketMetricAlarm-${region}`,
  {
    comparisonOperator: 'GreaterThanOrEqualToThreshold',
    evaluationPeriods: 1,
    datapointsToAlarm: 1,
    treatMissingData: 'missing',
    metricName: '5xxErrors',
    namespace: 'AWS/S3',
    unit: 'Count',
    period: 60,
    statistic: 'Sum',
    threshold: 2,
    dimensions: {
      BucketName: bucket.bucket,
      // FilterId: ''  // ????
    },
    alarmDescription: 'This metric monitors s3 bucket Sum 5xx errors.'
  },
  {
    provider: PriActProviders[region],
    parent: bucket
  }
);
m

millions-furniture-75402

11/10/2022, 9:03 PM
Have you tried something like a prefix?
This dimension filters metrics configurations that you specify for the request metrics on a bucket. When you create a metrics configuration, you specify a filter ID (for example, a prefix, a tag, or an access point). For more information, see Creating a metrics configuration.
To request metrics for the entire bucket, create a metrics configuration without a filter.
e

echoing-actor-55539

11/10/2022, 9:10 PM
my bucketMetrics does not specify a filter, however a filter Id is created that only has the criteria of entire bucket. and the alarm does not get data in cloudwatch unless a filterId is specified
m

millions-furniture-75402

11/10/2022, 9:10 PM
have you tried
.
or
/
?
e

echoing-actor-55539

11/10/2022, 9:12 PM
the metrics get created. i can see them in the s3 console, however the alarm wont pick up the data without the filterId, however i dont see any way to get it from the BucketMetric object
m

millions-furniture-75402

11/10/2022, 9:22 PM
Have you tried using
bucketMetrics.filter
?
Do you even need the dimensions on the alarm if the metric is for a single bucket?
e

echoing-actor-55539

11/10/2022, 9:24 PM
bucketMetrics.filter
is just the definition of the filter, does not give the FilterId
the alarm at the very least needs the BucketName dimension otherwise it would have no link to the bucket at all
m

millions-furniture-75402

11/10/2022, 9:26 PM
Ahh yes, sorry, I'm using awsx and alarms a bit differently
e

echoing-actor-55539

11/10/2022, 9:27 PM
The alarm as is just sits in a state of "Insufficient data", however if i manually create the alarm in the cloudwatch console it wont let me not specify the filter id
which i can see does exist as was created by pulumi, just does not seem to be exposed
m

millions-furniture-75402

11/10/2022, 9:30 PM
If you can get it with the aws sdk, you can use
aws.sdk
directly within pulumi to get that ID until the behavior is added to the provider. Might want to open an issue for that.
What is the filter id when you do it in the console?
e

echoing-actor-55539

11/10/2022, 9:33 PM
to enable requests metrics you must create a filter, you can give it whatever name you want then just scope to entire bucket. in the case of the auto generated pulumi one it uses the same resource name as BucketMetric with a hash appended to it
m

millions-furniture-75402

11/10/2022, 9:33 PM
oh, but it's different than
bucketMetric.id
?
e

echoing-actor-55539

11/10/2022, 9:35 PM
ok, i looks likte bucketMetrics.name is being used as the filter id, let me try that
m

millions-furniture-75402

11/10/2022, 9:36 PM
perfect!
e

echoing-actor-55539

11/10/2022, 9:41 PM
deployment is running, will keep you posted. thank you for your help!
That worked