Skip to content

Commit

Permalink
Merge pull request #16 from buddhike/ft/remove-references-to-kda
Browse files Browse the repository at this point in the history
Cosmetic updates to remove the word 'KDA'
  • Loading branch information
jeremyber-aws authored Aug 24, 2023
2 parents ab33cac + 73eb930 commit 23f7fcc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { CdkInfraKdaKdsToS3Stack } from '../lib/cdk-infra-kda-kds-to-s3-stack';
import { CdkInfraKdsToS3Stack } from '../lib/cdk-infra-kds-to-s3-stack';
import { BootstraplessStackSynthesizer } from 'cdk-bootstrapless-synthesizer';

const app = new cdk.App();
Expand All @@ -28,7 +28,7 @@ const app = new cdk.App();
// expect there to be a pre-existing bucket. You can modify this stack
// to also create a bucket instead.
// Same goes for the bucket that this app will be writing to.
new CdkInfraKdaKdsToS3Stack(app, 'CdkInfraKdaKdsToS3Stack', {
new CdkInfraKdsToS3Stack(app, 'CdkInfraKdaKdsToS3Stack', {
synthesizer: new BootstraplessStackSynthesizer({
templateBucketName: 'cfn-template-bucket',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@ import { Construct } from 'constructs';
import * as iam from 'aws-cdk-lib/aws-iam';
import { aws_logs as logs } from 'aws-cdk-lib';
import { aws_kinesis as kinesis } from 'aws-cdk-lib';
import { KDAConstruct } from '../../../../../cdk-infra/shared/lib/kda-construct';
import { KdaJavaApp, KdaJavaAppRuntimeEnvironment } from '../../../../../cdk-infra/shared/lib/kda-java-app-construct';
import { MsfJavaApp, MsfRuntimeEnvironment } from '../../../../../cdk-infra/shared/lib/msf-java-app-construct';
import { StreamMode } from 'aws-cdk-lib/aws-kinesis';
import { AppStartLambdaConstruct } from '../../../../../cdk-infra/shared/lib/app-start-lambda-construct';
import { KdsDataGenLambdaConstruct } from '../../../../../cdk-infra/shared/lib/kds-datagen-lambda-construct'
import { Bucket } from 'aws-cdk-lib/aws-s3';

export interface GlobalProps extends StackProps {
}

export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {
export class CdkInfraKdsToS3Stack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: GlobalProps) {
super(scope, id, props);

// we'll be generating a CFN script so we need CFN params
let cfnParams = this.getParams(props);

// create cw log group and log stream
// so it can be used when creating kda app
const logGroup = new logs.LogGroup(this, 'KDALogGroup', {
// so it can be used when creating the Flink app
const logGroup = new logs.LogGroup(this, 'LogGroup', {
logGroupName: cfnParams.get("CloudWatchLogGroupName")!.valueAsString,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const logStream = new logs.LogStream(this, 'KDALogStream', {
const logStream = new logs.LogStream(this, 'LogStream', {
logStreamName: cfnParams.get("CloudWatchLogStreamName")!.valueAsString,
logGroup: logGroup,
removalPolicy: cdk.RemovalPolicy.DESTROY,
Expand All @@ -57,7 +55,7 @@ export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {
retentionPeriod: cdk.Duration.hours(cfnParams.get("RetentionPeriodHours")!.valueAsNumber)
});

// our KDA app needs to be able to log
// our Flink app needs to be able to log
const accessCWLogsPolicy = new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
Expand All @@ -70,7 +68,7 @@ export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {
],
});

// our KDA app needs to be able to write metrics
// our Flink app needs to be able to write metrics
const accessCWMetricsPolicy = new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
Expand All @@ -80,7 +78,7 @@ export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {
],
});

// our KDA app needs access to read application jar from S3
// our Flink app needs access to read application jar from S3
// as well as to write to S3 (from FileSink)
const accessS3Policy = new iam.PolicyDocument({
statements: [
Expand All @@ -95,7 +93,7 @@ export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {
],
});

// our KDA app needs to be able to read from the source Kinesis Data Stream
// our Flink app needs to be able to read from the source Kinesis Data Stream
const accessKdsPolicy = new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
Expand All @@ -110,10 +108,10 @@ export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {
],
});

const kdaAppRole = new iam.Role(this, 'kda-app-role', {
const appRole = new iam.Role(this, 'flink-app-role', {
roleName: cfnParams.get("RoleName")!.valueAsString,
assumedBy: new iam.ServicePrincipal('kinesisanalytics.amazonaws.com'),
description: 'KDA app role',
description: 'Flink application role',
inlinePolicies: {
AccessKDSPolicy: accessKdsPolicy,
AccessCWLogsPolicy: accessCWLogsPolicy,
Expand All @@ -133,21 +131,21 @@ export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {
"BootstrapStackName": cfnParams.get("BootstrapStackName")!.valueAsString,
};

const app = new KdaJavaApp(this, "kds-to-s3-java-app-test", {
const app = new MsfJavaApp(this, "kds-to-s3-java-app-test", {
account: this.account,
region: this.region,
partition: this.partition,
appName: cfnParams.get("AppName")!.valueAsString,
runtimeEnvironment: KdaJavaAppRuntimeEnvironment.FLINK_1_15,
serviceExecutionRole: kdaAppRole.roleArn,
runtimeEnvironment: MsfRuntimeEnvironment.FLINK_1_15,
serviceExecutionRole: appRole.roleArn,
bucketName: cfnParams.get("BucketName")!.valueAsString,
jarFile: cfnParams.get("JarFile")!.valueAsString,
logStreamName: logStream.logStreamName,
logGroupName: logGroup.logGroupName,
applicationProperties: flinkApplicationProps,
});

// Configure app start lambda to automatically start KDA app
// Configure app start lambda to automatically start the Flink app
const appStartLambdaFnConstruct = new AppStartLambdaConstruct(this, 'AppStartLambda', {
account: this.account,
region: this.region,
Expand Down Expand Up @@ -186,7 +184,7 @@ export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {

params.set("AppName", new cdk.CfnParameter(this, "AppName", {
type: "String",
description: "The name of the Kinesis Data Analytics application"
description: "Flink application name"
}));

params.set("BucketName", new cdk.CfnParameter(this, "BucketName", {
Expand All @@ -201,17 +199,17 @@ export class CdkInfraKdaKdsToS3Stack extends cdk.Stack {

params.set("RoleName", new cdk.CfnParameter(this, "RoleName", {
type: "String",
description: "Name of IAM role used to run KDA app"
description: "Name of IAM role used to run the Flink application"
}));

params.set("CloudWatchLogGroupName", new cdk.CfnParameter(this, "CloudWatchLogGroupName", {
type: "String",
description: "The log group name for the KDA app"
description: "The log group name for the Flink application"
}));

params.set("CloudWatchLogStreamName", new cdk.CfnParameter(this, "CloudWatchLogStreamName", {
type: "String",
description: "The log stream name for the KDA app"
description: "The log stream name for the Flink application"
}));

params.set("BootstrapStackName", new cdk.CfnParameter(this, "BootstrapStackName", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ cd ..
aws s3 cp target/$JAR_FILE s3://$BUCKET_NAME/$JAR_FILE

# Create CFN stack
aws cloudformation deploy --stack-name $APP_NAME --parameter-overrides "AppName=${APP_NAME}" "BucketName=${BUCKET_NAME}" "StreamName=${APP_NAME}" "RoleName=${APP_NAME}" "GlueDatabaseName=default" "CloudWatchLogGroupName=blueprints/kinesis-analytics/${APP_NAME}" "CloudWatchLogStreamName=kinesis-analytics-log-stream" "BootstrapStackName=test-script" --capabilities CAPABILITY_NAMED_IAM --template-file target/$APP_NAME.json
aws cloudformation deploy --stack-name $APP_NAME --parameter-overrides "AppName=${APP_NAME}" "BucketName=${BUCKET_NAME}" "StreamName=${APP_NAME}" "RoleName=${APP_NAME}" "GlueDatabaseName=default" "CloudWatchLogGroupName=blueprints/msf/${APP_NAME}" "CloudWatchLogStreamName=log-stream-${APP_NAME}" "BootstrapStackName=test-script" --capabilities CAPABILITY_NAMED_IAM --template-file target/$APP_NAME.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as iam from 'aws-cdk-lib/aws-iam';

export enum KdaJavaAppRuntimeEnvironment {
export enum MsfRuntimeEnvironment {
FLINK_1_11 = "FLINK-1_11",
FLINK_1_13 = "FLINK-1_13",
FLINK_1_15 = "FLINK-1_15",
FLINK_1_6 = "FLINK-1_6",
FLINK_1_8 = "FLINK-1_8",

}
export interface KdaJavaAppProps extends StackProps {
export interface MsfJavaAppProps extends StackProps {
account: string;
region: string;
partition: string;
appName: string;
runtimeEnvironment: KdaJavaAppRuntimeEnvironment,
runtimeEnvironment: MsfRuntimeEnvironment,
serviceExecutionRole: string;
bucketName: string;
jarFile: string;
Expand All @@ -34,19 +34,19 @@ export interface KdaJavaAppProps extends StackProps {
applicationProperties?: Object;
}

// KdaJavaApp construct is used to create a new Java blueprint application.
// MsfJavaApp construct is used to create a new Java blueprint application.
// This construct is used instead of official CDK construct because official
// CDK construct does not support configuring CW logs during creation.
// Configuring CW logs with official CDK construct results in an update
// to the application which changes its initial version to 2. This is not
// desired for blueprints functionality in AWS console.
export class KdaJavaApp extends Construct {
constructor(scope: Construct, id: string, props: KdaJavaAppProps) {
export class MsfJavaApp extends Construct {
constructor(scope: Construct, id: string, props: MsfJavaAppProps) {
super(scope, id);

const fn = new lambda.SingletonFunction(this, 'KdaJavaAppCustomResourceHandler', {
const fn = new lambda.SingletonFunction(this, 'MsfJavaAppCustomResourceHandler', {
uuid: 'c4e1d42d-595a-4bd6-99e9-c299b61f2358',
lambdaPurpose: "CloudFormation custom resource handler to manage the deployment lifecycle of a KDA Java app",
lambdaPurpose: "Deploy an MSF app created created with Java",
code: lambda.Code.fromInline(readFileSync(`${__dirname}/../../../python/kda_java_app_custom_resource_handler.py`, "utf-8")),
handler: "index.handler",
initialPolicy: [
Expand Down Expand Up @@ -92,7 +92,7 @@ export class KdaJavaApp extends Construct {

const logStreamArn = `arn:${props.partition}:logs:${props.region}:${props.account}:log-group:${props.logGroupName}:log-stream:${props.logStreamName}`;
const bucketArn = `arn:${props.partition}:s3:::${props.bucketName}`;
new cdk.CustomResource(this, `KdaJavaApp${id}`, {
new cdk.CustomResource(this, `MSFJavaApp${id}`, {
serviceToken: fn.functionArn,
properties:
{
Expand Down

0 comments on commit 23f7fcc

Please sign in to comment.