Monitors for CloudFormation stack drifts
npm install cdk-drift-monitorMonitors for CloudFormation stack drifts. By default, detects drifts for all stacks:
``ts`
new DriftMonitor(driftDetectStack, 'DriftMonitor');
You can also specify a list of stacks to detect drifts:
`ts`
new DriftMonitor(driftDetectStack, 'DriftMonitor', {
stacks: [myStack1, myStack2],
});
It can also be initialized by providing stack names:
`ts`
new DriftMonitor(driftDetectStack, 'DriftMonitor', {
stackNames: ['myStack1', 'myStack2'],
});
By default, the drift detection will run every hour. This can be customized:
`ts`
new DriftMonitor(driftDetectStack, 'DriftMonitor', {
runEvery: Duration.hours(24),
});
The construct creates an alarm with no actions. Here's an example for adding an alarm action:
`ts
import * as sns from 'aws-cdk-lib/aws-sns';
import { SnsAction } from 'aws-cdk-lib/aws-cloudwatch-actions';
const driftMonitor = new DriftMonitor(driftDetectStack, 'DriftMonitor');
const topic = new sns.Topic(this, 'errorTopic');
driftMonitor.alarm.addAlarmAction(new SnsAction(topic));
`
By default, the drift detection Lambda function uses the latest Node.js runtime available in your deployment region. This is determined automatically at CDK synthesis time.
You can override the runtime to use a specific Node.js version:
`ts
import * as lambda from 'aws-cdk-lib/aws-lambda';
new DriftMonitor(driftDetectStack, 'DriftMonitor', {
runtime: lambda.Runtime.NODEJS_20_X,
});
`
- [ ] Publish to Maven
- [ ] Publish to PyPi
- [ ] Publish to NuGet
- [ ] Use AWS Config rule cloudformation-stack-drift-detection-check` instead of custom lambda
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.