-
Notifications
You must be signed in to change notification settings - Fork 4k
/
integ.aws-api.ts
57 lines (49 loc) · 1.56 KB
/
integ.aws-api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import events = require('@aws-cdk/aws-events');
import cdk = require('@aws-cdk/core');
import targets = require('../../lib');
const app = new cdk.App();
class AwsApi extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Force new deployment of 'cool-service' and stop 'dev-instance' at midnight everyday
const scheduleRule = new events.Rule(this, 'ScheduleRule', {
schedule: events.Schedule.cron({
hour: '0',
minute: '0'
})
});
scheduleRule.addTarget(new targets.AwsApi({
service: 'ECS',
action: 'updateService',
parameters: {
service: 'cool-service',
forceNewDeployment: true
} as AWS.ECS.UpdateServiceRequest,
}));
scheduleRule.addTarget(new targets.AwsApi({
service: 'RDS',
action: 'stopDBInstance',
parameters: {
DBInstanceIdentifier: 'dev-instance'
} as AWS.RDS.StopDBInstanceMessage,
}));
// Create snapshots when a DB instance restarts
const patternRule = new events.Rule(this, 'PatternRule', {
eventPattern: {
detailType: ['RDS DB Instance Event'],
detail: {
Message: ['DB instance restarted']
}
}
});
patternRule.addTarget(new targets.AwsApi({
service: 'RDS',
action: 'createDBSnapshot',
parameters: {
DBInstanceIdentifier: events.EventField.fromPath('$.detail.SourceArn')
} as AWS.RDS.CreateDBSnapshotMessage
}));
}
}
new AwsApi(app, 'aws-cdk-aws-lambda-target-integ');
app.synth();