📅  最后修改于: 2022-03-11 15:02:14.386000             🧑  作者: Mango
import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
import * as dynamodb from '@aws-cdk/aws-dynamodb';
import * as kinesis from '@aws-cdk/aws-kinesis';
import * as firehose from '@aws-cdk/aws-kinesisfirehose';
import * as iam from "@aws-cdk/aws-iam";
import { CfnResource } from '@aws-cdk/core';
const DynamoDBArn = 'arn:aws:dynamodb:us-east-1:207627709836:table/blog-srsa-ddb-table';
export class DynamoStreamer extends cdk.Stack {
constructor(
scope: cdk.Construct,
id: string
) {
super(scope, id);
const bucket = new s3.Bucket(this, 'data-lake', {
publicReadAccess: false
});
const dataStream=new kinesis.Stream(this,"dataStream",{shardCount:1,streamName:"stevensu_cdk_stream"})
const myTable = new dynamodb.Table(this, 'dynamo-table', {
tableName: 'blog-srsa-ddb-table2',
partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'name', type: dynamodb.AttributeType.STRING },
removalPolicy: cdk.RemovalPolicy.RETAIN,
kinesisStream: dataStream
});
const deliveryStreamRole = new iam.Role(this, `DeliveryStreamRole`, {
assumedBy: new iam.ServicePrincipal("firehose.amazonaws.com"),
});
const firehoseDeliveryStream = new firehose.CfnDeliveryStream(this, 'Delivery Stream', {
redshiftDestinationConfiguration: {
clusterJdbcurl: 'jdbc:redshift://redshift-cluster-1.cicrdvtr7ouk.us-east-1.redshift.amazonaws.com:5439/dev',
username: 'admin',
password: '2131636+aA',
roleArn: 'arn:aws:iam::207627709836:role/service-role/KinesisFirehoseServiceRole-KDS-RED-vTWqG-us-east-1-1630965194702',
copyCommand: {
dataTableName: 'users_test',
copyOptions: 'format as json \'auto\''
},
s3Configuration: {
bucketArn: bucket.bucketArn,
roleArn: deliveryStreamRole.roleArn
},
},
kinesisStreamSourceConfiguration: {
kinesisStreamArn: dataStream.streamArn,
roleArn: deliveryStreamRole.roleArn
},
});
}
}