Skip to content

Commit 867c75b

Browse files
committed
Add CDK deployment
1 parent c7a1056 commit 867c75b

26 files changed

+7605
-1065
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@ local.properties
2424
#macOS
2525
.DS_Store
2626

27-
cdk
27+
cdk/*.js
28+
cdk/!jest.config.js
29+
cdk/*.d.ts
30+
cdk/node_modules
31+
32+
# CDK asset staging directory
33+
cdk/.cdk.staging
34+
cdk/cdk.out

README.md

Lines changed: 12 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -221,46 +221,6 @@ Streams and write to DynamoDB) by assuming the role
221221
ECSTaskConsumerRole01. This sample deployment uses 2 vCPU and 4 GB
222222
memory to run the container.
223223

224-
### Kinesis capacity management
225-
226-
When changes in the rate of data flow occur, you may have to increase or
227-
decrease the capacity. With Kinesis Data Streams, you can have one or
228-
more *hot shards* as a result of unevenly distributed partition keys,
229-
very similar to a hot key in a database. This means that a certain shard
230-
receives more traffic than others, and if it's overloaded, it produces a
231-
ProvisionedThroughputExceededException (enable detailed monitoring to
232-
see that metric on shard level).
233-
234-
You need to split these hot shards to increase throughput, and merge
235-
cold shards to increase efficiency. For this post, you use random
236-
partition keys (and therefore random shard assignment) for the records,
237-
so we don't dive deeper into splitting and merging specific shards.
238-
Instead, we show how to increase and decrease throughput capacity for
239-
the whole stream. For more information about scaling on a shard level,
240-
see [Strategies for
241-
Resharding](https://docs.aws.amazon.com/streams/latest/dev/kinesis-using-sdk-java-resharding-strategies.html).
242-
243-
You can build your own scaling application utilizing the
244-
[UpdateShardCount](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_UpdateShardCount.html),
245-
[SplitShard](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_SplitShard.html),
246-
and
247-
[MergeShards](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_MergeShards.html)
248-
APIs or use the custom resource scaling solution as described in [Scale
249-
Amazon Kinesis Data Streams with AWS Application Auto
250-
Scaling](https://aws.amazon.com/blogs/big-data/scaling-amazon-kinesis-data-streams-with-aws-application-auto-scaling/)
251-
or [Amazon Kineis Scaling
252-
Utils](https://github.com/awslabs/amazon-kinesis-scaling-utils).
253-
The Application Auto Scaling is an event-driven scaling architecture
254-
based on CloudWatch alarms, and the Scaling Utils is a Docker container
255-
that constantly monitors your data stream. The Application Auto Scaling
256-
manages the number of shards for scaling, whereas the Kinesis Scaling
257-
Utils additionally handles shard keyspace allocations, hot shard
258-
splitting, and cold shard merging. For this solution, you use the
259-
Kinesis Scaling Utils and deploy it on Amazon ECS. You can also deploy
260-
it on [AWS Elastic
261-
Beanstalk](https://aws.amazon.com/elasticbeanstalk) as a container
262-
or on an Apache Tomcat platform.
263-
264224
## Prerequisites
265225

266226
For this walkthrough, you must have an [AWS
@@ -270,21 +230,20 @@ account](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activ
270230

271231
In this post, we walk through the following steps:
272232

273-
1. Deploying the CloudFormation template.
233+
1. Deploying the CDK Stack template.
274234

275235
2. Sending records to Kinesis Data Streams.
276236

277237
3. Monitoring your stream and applications.
278238

279-
Deploying the CloudFormation template
280-
281-
Deploy the CloudFormation stack by choosing **Launch Stack**:
239+
#### Deploying the CDK Stack
282240

283-
[<img src="https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png">](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?&templateURL=https://flomair-dataprocessor-source.s3-us-west-2.amazonaws.com/deployment.yaml)
241+
1. Clone the repository
242+
2. `cd cdk`
243+
3. `npm install`
244+
4. `cdk deploy`
284245

285-
The template launches in the US East (N. Virginia) Region by default. To
286-
launch it in a different Region, use the Region selector in the console
287-
navigation bar. The following Regions are supported:
246+
The following Regions are supported:
288247

289248
- US East (Ohio)
290249

@@ -300,24 +259,12 @@ navigation bar. The following Regions are supported:
300259

301260
- Europe (Ireland)
302261

303-
Alternatively, you can download the [CloudFormation
304-
template](https://flomair-dataprocessor-source.s3-us-west-2.amazonaws.com/deployment.yaml)
305-
and deploy it manually. When asked to provide an IPv4 CIDR range, enter
306-
the CIDR range that can send records to your application. You can change
307-
it later on by adapting the [security groups inbound
308-
rule](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html#AddRemoveRules)
309-
for the Application Load Balancer.
310262

311263
### Sending records to Kinesis Data Streams
312264

313265
You have several options to send records to Kinesis Data Streams. You
314-
can do it from the CLI or any API client that can send REST requests, or
315-
use a load testing solution like [Distributed Load Testing on
316-
AWS](https://aws.amazon.com/solutions/distributed-load-testing-on-aws/)
317-
or [Artillery](https://artillery.io/). With load testing,
318-
additional charges for requests occur; as a guideline, 10,000 requests
319-
per second for 10 minutes generate an AWS bill of less than \$5.00. To
320-
do a POST request via curl, run the following command and replace
266+
can do it from the CLI or any API client that can send REST requests.
267+
To do a POST request via curl, run the following command and replace
321268
*ALB_ENDPOINT* with the DNS record of your Application Load Balancer.
322269
You can find it on the CloudFormation stack's **Outputs** tab. Ensure
323270
you have a JSON element "data". Otherwise, the application can't process
@@ -364,20 +311,14 @@ For example, if you increase the value of RecordMaxBufferedTime, data
364311
records are buffered longer at the producer, more records can be
365312
aggregated, but the latency for ingestion is increased.
366313

367-
All three applications (including the Kinesis Data Streams scaler)
368-
publish logs to their respective log group (for example,
369-
ecs/kinesis-data-processor-producer) in CloudWatch. You can either check
314+
All applications
315+
publish logs to their respective log group in CloudWatch. You can either check
370316
the CloudWatch logs of the Auto Scaling Application or the data stream
371317
metrics to see the scaling behavior of Kinesis Data Streams.
372318

373319
### Cleaning up
374320

375-
To avoid additional cost, ensure that the provisioned resources are
376-
decommissioned. To do that, delete the images in the [Amazon Elastic
377-
Container Registry](http://aws.amazon.com/ecr/) (Amazon ECR)
378-
repository, the CloudFormation stack, and any remaining resources that
379-
the CloudFormation stack didn't automatically delete. Additionally,
380-
delete the DynamoDB table DataProcessorConsumer, which the KCL created.
321+
Run the command `cdk destroy` from the cdk directory.
381322

382323
## Conclusion
383324

cdk/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out

cdk/.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

cdk/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Welcome to your CDK TypeScript project
2+
3+
This is a blank project for CDK development with TypeScript.
4+
5+
The `cdk.json` file tells the CDK Toolkit how to execute your app.
6+
7+
## Useful commands
8+
9+
* `npm run build` compile typescript to js
10+
* `npm run watch` watch for changes and compile
11+
* `npm run test` perform the jest unit tests
12+
* `cdk deploy` deploy this stack to your default AWS account/region
13+
* `cdk diff` compare deployed stack with current state
14+
* `cdk synth` emits the synthesized CloudFormation template

cdk/bin/cdk.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from 'aws-cdk-lib';
4+
import { CdkStack } from '../lib/cdk-stack';
5+
6+
const app = new cdk.App();
7+
new CdkStack(app, 'CdkStack', {
8+
/* If you don't specify 'env', this stack will be environment-agnostic.
9+
* Account/Region-dependent features and context lookups will not work,
10+
* but a single synthesized template can be deployed anywhere. */
11+
12+
/* Uncomment the next line to specialize this stack for the AWS Account
13+
* and Region that are implied by the current CLI configuration. */
14+
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
15+
16+
/* Uncomment the next line if you know exactly what Account and Region you
17+
* want to deploy the stack to. */
18+
env: {account: '299003995950', region: "eu-west-1" }
19+
20+
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
21+
});

cdk/cdk.context.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"availability-zones:account=809032347958:region=eu-west-1": [
3+
"eu-west-1a",
4+
"eu-west-1b",
5+
"eu-west-1c"
6+
],
7+
"availability-zones:account=299003995950:region=eu-west-1": [
8+
"eu-west-1a",
9+
"eu-west-1b",
10+
"eu-west-1c"
11+
]
12+
}

cdk/cdk.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/cdk.ts",
3+
"requireApproval": "never",
4+
"watch": {
5+
"include": [
6+
"**"
7+
],
8+
"exclude": [
9+
"README.md",
10+
"cdk*.json",
11+
"**/*.d.ts",
12+
"**/*.js",
13+
"tsconfig.json",
14+
"package*.json",
15+
"yarn.lock",
16+
"node_modules",
17+
"test"
18+
]
19+
},
20+
"context": {
21+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
22+
"@aws-cdk/core:checkSecretUsage": true,
23+
"@aws-cdk/core:target-partitions": [
24+
"aws",
25+
"aws-cn"
26+
],
27+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
28+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
29+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
30+
"@aws-cdk/aws-iam:minimizePolicies": true,
31+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
32+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
33+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
34+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
35+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
36+
"@aws-cdk/core:enablePartitionLiterals": true,
37+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
38+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
39+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
40+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
41+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
42+
"@aws-cdk/aws-route53-patters:useCertificate": true,
43+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
44+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
45+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
46+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
47+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
48+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
49+
"@aws-cdk/aws-redshift:columnId": true,
50+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true
51+
}
52+
}

cdk/jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};

0 commit comments

Comments
 (0)