forked from mbonig/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource.ts
More file actions
65 lines (55 loc) · 1.97 KB
/
resource.ts
File metadata and controls
65 lines (55 loc) · 1.97 KB
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
58
59
60
61
62
63
64
65
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import { RemovalPolicy } from 'aws-cdk-lib';
import * as pipes from 'aws-cdk-lib/aws-pipes';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as logs from 'aws-cdk-lib/aws-logs';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import { ExtractContentStateMachine } from './sfn';
class DdbToSfnPipe extends Construct {
constructor(scope: Construct, id: string, table: dynamodb.ITable, stateMachine: sfn.IStateMachine) {
super(scope, id);
const pipeRole = new iam.Role(this, 'PipeRole', {
assumedBy: new iam.ServicePrincipal('pipes.amazonaws.com'),
});
table.grantStreamRead(pipeRole);
stateMachine.grantStartExecution(pipeRole);
const logGroup = new logs.LogGroup(this, 'PipeLogGroup', {
retention: logs.RetentionDays.ONE_WEEK,
});
new pipes.CfnPipe(this, 'DdbToSfnPipe', {
roleArn: pipeRole.roleArn,
source: table.tableStreamArn!,
sourceParameters: {
dynamoDbStreamParameters: {
startingPosition: 'LATEST',
},
},
target: stateMachine.stateMachineArn,
targetParameters: {
stepFunctionStateMachineParameters: {
invocationType: 'FIRE_AND_FORGET',
},
},
logConfiguration: {
cloudwatchLogsLogDestination: {
logGroupArn: logGroup.logGroupArn,
},
level: 'INFO',
},
});
}
}
export class ProcessLinks extends Construct {
constructor(scope: Construct, id: string, props: { table: dynamodb.ITable }) {
super(scope, id);
const { table } = props;
const bucket = new s3.Bucket(this, 'AssetsBucket', {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
});
const stateMachine = new ExtractContentStateMachine(this, 'ExtractContentStateMachine', bucket);
new DdbToSfnPipe(this, 'DdbToSfnPipe', table, stateMachine.stateMachine);
}
}