-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(s3): add MetricsConfiguration Property to S3 Bucket (#2163)
Add metric Property to S3 Bucket for configuring bucket metrics. You can either specify the metrics as properties: new Bucket(stack, 'Bucket', { metrics: [{ id: "test", tagFilters: {tagname1: "tagvalue1", tagname2: "tagvalue2"} }] }); Or use the `addMetric` function: const bucket = new Bucket(stack, 'Bucket'); bucket.addMetric({ id: "test" });
- Loading branch information
Showing
2 changed files
with
182 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { expect, haveResource } from '@aws-cdk/assert'; | ||
import { Stack } from '@aws-cdk/cdk'; | ||
import { Test } from 'nodeunit'; | ||
import { Bucket } from '../lib'; | ||
|
||
export = { | ||
'Can use addMetrics() to add a metric configuration'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
|
||
// WHEN | ||
const bucket = new Bucket(stack, 'Bucket'); | ||
bucket.addMetric({ | ||
id: "test" | ||
}); | ||
|
||
// THEN | ||
expect(stack).to(haveResource('AWS::S3::Bucket', { | ||
MetricsConfigurations: [{ | ||
Id: "test" | ||
}] | ||
})); | ||
|
||
test.done(); | ||
}, | ||
|
||
'Bucket with metrics on prefix'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
|
||
// WHEN | ||
new Bucket(stack, 'Bucket', { | ||
metrics: [{ | ||
id: "test", | ||
prefix: "prefix" | ||
}] | ||
}); | ||
|
||
// THEN | ||
expect(stack).to(haveResource('AWS::S3::Bucket', { | ||
MetricsConfigurations: [{ | ||
Id: "test", | ||
Prefix: "prefix" | ||
}] | ||
})); | ||
|
||
test.done(); | ||
}, | ||
|
||
'Bucket with metrics on tag filter'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
|
||
// WHEN | ||
new Bucket(stack, 'Bucket', { | ||
metrics: [{ | ||
id: "test", | ||
tagFilters: {tagname1: "tagvalue1", tagname2: "tagvalue2"} | ||
}] | ||
}); | ||
|
||
// THEN | ||
expect(stack).to(haveResource('AWS::S3::Bucket', { | ||
MetricsConfigurations: [{ | ||
Id: "test", | ||
TagFilters: [ | ||
{ Key: "tagname1", Value: "tagvalue1" }, | ||
{ Key: "tagname2", Value: "tagvalue2" }, | ||
] | ||
}] | ||
})); | ||
|
||
test.done(); | ||
}, | ||
|
||
'Bucket with multiple metric configurations'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
|
||
// WHEN | ||
new Bucket(stack, 'Bucket', { | ||
metrics: [ | ||
{ | ||
id: "test", | ||
tagFilters: {tagname1: "tagvalue1", tagname2: "tagvalue2"} | ||
|
||
}, | ||
{ | ||
id: "test2", | ||
prefix: "prefix" | ||
}, | ||
] | ||
}); | ||
|
||
// THEN | ||
expect(stack).to(haveResource('AWS::S3::Bucket', { | ||
MetricsConfigurations: [{ | ||
Id: "test", | ||
TagFilters: [ | ||
{ Key: "tagname1", Value: "tagvalue1" }, | ||
{ Key: "tagname2", Value: "tagvalue2" }, | ||
] | ||
}, | ||
{ | ||
Id: "test2", | ||
Prefix: "prefix" | ||
}] | ||
})); | ||
|
||
test.done(); | ||
}, | ||
}; |