Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to CDK v2 #5

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amazon-msk-java-app-cdk/bin/amazon-msk-java-app-cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import * as cdk from 'aws-cdk-lib';
import {KafkaStack} from '../lib/kafka-stack';
import {VpcStack} from "../lib/vpc-stack";
import {DynamoDbStack} from "../lib/dynamodb-stack";
Expand Down
30 changes: 23 additions & 7 deletions amazon-msk-java-app-cdk/cdk.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
{
"app": "npx ts-node --prefer-ts-exts bin/amazon-msk-java-app-cdk.ts",
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true",
"@aws-cdk/core:stackRelativeExports": "true",
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
"@aws-cdk/aws-kms:defaultKeyPolicies": true,
"@aws-cdk/aws-s3:grantWriteWithoutAcl": true
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false
}
}
10 changes: 5 additions & 5 deletions amazon-msk-java-app-cdk/lib/dynamodb-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import * as dynamodb from "@aws-cdk/aws-dynamodb";
import {AttributeType} from "@aws-cdk/aws-dynamodb";
import * as cdk from "@aws-cdk/core";
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
import * as cdk from 'aws-cdk-lib';
import { Construct } from "constructs";

export class DynamoDbStack extends cdk.Stack {
private tableName = "Accounts";

constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const table = new dynamodb.Table(this, "dynamoDbTable", {
tableName: this.tableName,
partitionKey: {name: "id", type: AttributeType.STRING}
partitionKey: {name: "id", type: dynamodb.AttributeType.STRING}
});
}
}
19 changes: 10 additions & 9 deletions amazon-msk-java-app-cdk/lib/fargate-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import * as cdk from "@aws-cdk/core";
import {CfnParameter} from "@aws-cdk/core";
import * as ecs from "@aws-cdk/aws-ecs";
import * as ec2 from "@aws-cdk/aws-ec2";
import {InstanceClass, InstanceSize} from "@aws-cdk/aws-ec2";
import * as cdk from 'aws-cdk-lib';
import {CfnParameter} from "aws-cdk-lib";
import * as ecs from "aws-cdk-lib/aws-ecs";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import {InstanceClass, InstanceSize} from "aws-cdk-lib/aws-ec2";
import {VpcStack} from "./vpc-stack";
import * as assets from "@aws-cdk/aws-ecr-assets";
import * as iam from "@aws-cdk/aws-iam";
import {Effect} from "@aws-cdk/aws-iam";
import * as assets from "aws-cdk-lib/aws-ecr-assets";
import * as iam from "aws-cdk-lib/aws-iam";
import {Effect} from "aws-cdk-lib/aws-iam";
import { Construct } from 'constructs';

export class FargateStack extends cdk.Stack {
private tableName = "Accounts";
private groupId = "transaction-consumers";

constructor(vpcStack: VpcStack, scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(vpcStack: VpcStack, scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

let bootstrapAddress = new CfnParameter(this, "bootstrapAddress", {
Expand Down
11 changes: 6 additions & 5 deletions amazon-msk-java-app-cdk/lib/kafka-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import * as cdk from '@aws-cdk/core';
import * as msk from '@aws-cdk/aws-msk';
import * as ec2 from '@aws-cdk/aws-ec2'
import * as cdk from 'aws-cdk-lib';
import * as msk from 'aws-cdk-lib/aws-msk';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

import {VpcStack} from "./vpc-stack";
import { Construct } from 'constructs';

export class KafkaStack extends cdk.Stack {
public kafkaCluster: msk.CfnCluster;

constructor(vpcStack: VpcStack, scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(vpcStack: VpcStack, scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
this.kafkaCluster = new msk.CfnCluster(this, "kafkaCluster", {
brokerNodeGroupInfo: {
securityGroups: [vpcStack.kafkaSecurityGroup.securityGroupId],
clientSubnets: [...vpcStack.vpc.selectSubnets({
subnetType: ec2.SubnetType.PRIVATE
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS
}).subnetIds],
instanceType: "kafka.t3.small",
storageInfo: {
Expand Down
17 changes: 9 additions & 8 deletions amazon-msk-java-app-cdk/lib/kafka-topic-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import * as cdk from "@aws-cdk/core";
import {CfnParameter, CustomResource, Duration} from "@aws-cdk/core";
import * as cdk from 'aws-cdk-lib';
import {CfnParameter, CustomResource, Duration} from "aws-cdk-lib";
import {VpcStack} from "./vpc-stack";
import {KafkaStack} from "./kafka-stack";
import {NodejsFunction} from "@aws-cdk/aws-lambda-nodejs";
import {Runtime} from "@aws-cdk/aws-lambda";
import {Effect, PolicyStatement} from "@aws-cdk/aws-iam";
import {Provider} from "@aws-cdk/custom-resources";
import {RetentionDays} from "@aws-cdk/aws-logs";
import {NodejsFunction} from "aws-cdk-lib/aws-lambda-nodejs";
import {Runtime} from "aws-cdk-lib/aws-lambda";
import {Effect, PolicyStatement} from "aws-cdk-lib/aws-iam";
import {Provider} from "aws-cdk-lib/custom-resources";
import {RetentionDays} from "aws-cdk-lib/aws-logs";
import { Construct } from 'constructs';

export class KafkaTopicStack extends cdk.Stack {

constructor(vpcStack: VpcStack, kafkaStack: KafkaStack, scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(vpcStack: VpcStack, kafkaStack: KafkaStack, scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const bootstrapAddress = new CfnParameter(this, "bootstrapAddress", {
Expand Down
13 changes: 7 additions & 6 deletions amazon-msk-java-app-cdk/lib/lambda-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import * as cdk from "@aws-cdk/core";
import {CfnParameter, Duration} from "@aws-cdk/core";
import * as cdk from "aws-cdk-lib";
import {CfnParameter, Duration} from "aws-cdk-lib";
import {VpcStack} from "./vpc-stack";
import {NodejsFunction} from "@aws-cdk/aws-lambda-nodejs";
import {Effect, PolicyStatement} from "@aws-cdk/aws-iam";
import {NodejsFunction} from "aws-cdk-lib/aws-lambda-nodejs";
import {Effect, PolicyStatement} from "aws-cdk-lib/aws-iam";
import {KafkaStack} from "./kafka-stack";
import {Runtime} from "@aws-cdk/aws-lambda"
import {Runtime} from "aws-cdk-lib/aws-lambda"
import { Construct } from "constructs";

export class LambdaStack extends cdk.Stack {
constructor(vpcStack: VpcStack, kafkaStack: KafkaStack, scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(vpcStack: VpcStack, kafkaStack: KafkaStack, scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

let bootstrapAddress = new CfnParameter(this, "bootstrapAddress", {
Expand Down
7 changes: 4 additions & 3 deletions amazon-msk-java-app-cdk/lib/vpc-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import * as cdk from "@aws-cdk/core";
import * as ec2 from "@aws-cdk/aws-ec2";
import * as cdk from "aws-cdk-lib";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import { Construct } from "constructs";

export class VpcStack extends cdk.Stack {
public vpc: ec2.Vpc;
public kafkaSecurityGroup: ec2.SecurityGroup;
public fargateSercurityGroup: ec2.SecurityGroup;
public lambdaSecurityGroup: ec2.SecurityGroup;

constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

this.vpc = new ec2.Vpc(this, 'vpc');
Expand Down
27 changes: 11 additions & 16 deletions amazon-msk-java-app-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@
"cdk": "cdk"
},
"devDependencies": {
"@aws-cdk/assert": "1.96.0",
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
"aws-cdk": "1.96.0",
"jest": "^26.4.2",
"ts-jest": "^26.2.0",
"ts-node": "^9.0.0",
"typescript": "~3.9.7"
"@aws-cdk/assert": "2.63.0",
"@types/jest": "^29.4.0",
"@types/node": "18.11.18",
"jest": "^29.4.1",
"ts-jest": "^29.0.5",
"aws-cdk": "2.63.0",
"ts-node": "^10.9.1",
"typescript": "~4.9.4"
},
"dependencies": {
"@aws-cdk/aws-dynamodb": "1.96.0",
"@aws-cdk/aws-ec2": "1.96.0",
"@aws-cdk/aws-ecs": "1.96.0",
"@aws-cdk/aws-iam": "1.96.0",
"@aws-cdk/aws-lambda-nodejs": "1.96.0",
"@aws-cdk/aws-msk": "1.96.0",
"@aws-cdk/core": "1.96.0",
"source-map-support": "0.5.19"
"aws-cdk-lib": "2.63.0",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
}
3 changes: 2 additions & 1 deletion amazon-msk-java-app-cdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"outDir": "./dist",
"target": "ES2018",
"module": "commonjs",
"lib": ["es2018"],
Expand All @@ -19,5 +20,5 @@
"strictPropertyInitialization": false,
"typeRoots": ["./node_modules/@types"]
},
"exclude": ["cdk.out"]
"exclude": ["cdk.out", "node_modules", "dist"]
}
Empty file modified scripts/deploy.sh
100644 → 100755
Empty file.
Empty file modified scripts/destroy.sh
100644 → 100755
Empty file.