mirror of
https://github.com/autistic-symposium/backend-and-orchestration-toolkit.git
synced 2025-06-08 15:02:55 -04:00
merge files from the blockchain infra repo (#59)
This commit is contained in:
parent
23f56ef195
commit
2a6449bb85
346 changed files with 29097 additions and 132 deletions
61
code/kubernetes/python-cdk/ts/MSK_example/README.md
Normal file
61
code/kubernetes/python-cdk/ts/MSK_example/README.md
Normal file
|
@ -0,0 +1,61 @@
|
|||
# CDK MSK Example
|
||||
|
||||
|
||||
|
||||
### Deploy VPC
|
||||
|
||||
[Amazon VPC](https://aws.amazon.com/vpc/) lets you provision a logically isolated section of the AWS Cloud where you can all the resources as in a virtual network.
|
||||
|
||||
These are the default values in `cdk.json`:
|
||||
|
||||
```
|
||||
"vpc.cidr": "10.0.0.0/16",
|
||||
"vpc.maxAzs": 3,
|
||||
```
|
||||
|
||||
Deploy with:
|
||||
|
||||
```
|
||||
cdk deploy VPCStack
|
||||
```
|
||||
|
||||
### Deploy MSK
|
||||
|
||||
[Amazon MSK](https://aws.amazon.com/msk/) is a managed service that makes it easy for you to build and run applications that use Apache Kafka to process streaming data.
|
||||
|
||||
These are the default values in `cdk.json`:
|
||||
|
||||
```
|
||||
"msk.DevMskCluster": "MskCluster",
|
||||
"msk.ClusterTag": "MSK cluster",
|
||||
"msk.brokerNodeGroupBrokerAzDistribution": "DEFAULT",
|
||||
"msk.enhancedMonitoring": "PER_BROKER",
|
||||
"msk.brokerNodeGroupEBSVolumeSize": 100,
|
||||
"msk.brokerNodeGroupInstanceType": "kafka.m5.large",
|
||||
"msk.brokerPort": 9092,
|
||||
"msk.kafkaVersion": "2.2.1",
|
||||
"msk.numberOfBrokerNodes": 3
|
||||
```
|
||||
|
||||
Deploy with:
|
||||
|
||||
```
|
||||
cdk deploy MskClusterStack
|
||||
```
|
||||
|
||||
#### Kafka CLI
|
||||
|
||||
Note that the CLI commands for MKS are given by the keyword `kafka`, for example:
|
||||
|
||||
```
|
||||
aws kafka list-clusters
|
||||
```
|
||||
|
||||
To retrieve `BootstrapBrokerStringTls`, run:
|
||||
|
||||
```
|
||||
aws kafka get-bootstrap-brokers --cluster-arn <cluster ARN>
|
||||
```
|
||||
|
||||
However, access and development within the cluster (e.g. creating topics, accessing brokers) need to be done while connected to the VPN.
|
||||
|
15
code/kubernetes/python-cdk/ts/MSK_example/bin/example.ts
Normal file
15
code/kubernetes/python-cdk/ts/MSK_example/bin/example.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env node
|
||||
import 'source-map-support/register';
|
||||
import cdk = require('@aws-cdk/core');
|
||||
|
||||
import { VPCStack } from "../lib/Vpc";
|
||||
import { MskClusterStack } from "../lib/MskCluster";
|
||||
|
||||
const app = new cdk.App();
|
||||
const app_env = {
|
||||
region: <account region>,
|
||||
account: <account number>
|
||||
};
|
||||
|
||||
const vpcStack = new VPCStack(app, 'VPCStack', {env: app_env});
|
||||
new MskClusterStack(app, 'MskClusterStack',{env: app_env, vpc: vpcStack.Vpc});
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"availability-zones:account=<ACOUNT NUMBER>:region=us-west-1": [
|
||||
"us-west-1a",
|
||||
"us-west-1b",
|
||||
"us-west-1c"
|
||||
]
|
||||
}
|
17
code/kubernetes/python-cdk/ts/MSK_example/cdk.json
Normal file
17
code/kubernetes/python-cdk/ts/MSK_example/cdk.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"app": "npx ts-node bin/example.ts",
|
||||
"context": {
|
||||
"env.type": "dev",
|
||||
"vpc.cidr": "10.0.0.0/16",
|
||||
"vpc.maxAzs": 3,
|
||||
"msk.DevMskCluster": "MskCluster",
|
||||
"msk.ClusterTag": "MSK cluster",
|
||||
"msk.brokerNodeGroupBrokerAzDistribution": "DEFAULT",
|
||||
"msk.enhancedMonitoring": "PER_BROKER",
|
||||
"msk.brokerNodeGroupEBSVolumeSize": 100,
|
||||
"msk.brokerNodeGroupInstanceType": "kafka.m5.large",
|
||||
"msk.brokerPort": 9092,
|
||||
"msk.kafkaVersion": "2.2.1",
|
||||
"msk.numberOfBrokerNodes": 3
|
||||
}
|
||||
}
|
75
code/kubernetes/python-cdk/ts/MSK_example/lib/MskCluster.ts
Normal file
75
code/kubernetes/python-cdk/ts/MSK_example/lib/MskCluster.ts
Normal file
|
@ -0,0 +1,75 @@
|
|||
import cdk = require("@aws-cdk/core");
|
||||
import ec2 = require("@aws-cdk/aws-ec2");
|
||||
import msk = require("@aws-cdk/aws-msk");
|
||||
|
||||
|
||||
interface MSKStackProps extends cdk.StackProps {
|
||||
vpc: ec2.IVpc;
|
||||
}
|
||||
export class MskClusterStack extends cdk.Stack {
|
||||
private vpc: ec2.IVpc;
|
||||
|
||||
constructor(scope: cdk.Construct, id: string, props?: MSKStackProps) {
|
||||
super(scope, id, props);
|
||||
const current_env = this.node.tryGetContext("env.type");
|
||||
|
||||
//****************************** Context variables **************************************//
|
||||
const clusterName = this.node.tryGetContext("msk.DevMskCluster");
|
||||
const clusterTag = this.node.tryGetContext("msk.mskClusterTag");
|
||||
const brokerNodeGroupBrokerAzDistribution = this.node.tryGetContext("msk.brokerNodeGroupBrokerAzDistribution");
|
||||
const brokerNodeGroupEBSVolumeSize = this.node.tryGetContext("msk.brokerNodeGroupEBSVolumeSize");
|
||||
const brokerNodeGroupInstanceType = this.node.tryGetContext("msk.brokerNodeGroupInstanceType");
|
||||
const brokerPort = this.node.tryGetContext("msk.brokerPort");
|
||||
const kafkaVersion = this.node.tryGetContext("msk.kafkaVersion");
|
||||
const numberOfBrokerNodes = this.node.tryGetContext("msk.numberOfBrokerNodes");
|
||||
const enhancedMonitoring = this.node.tryGetContext("msk.enhancedMonitoring");
|
||||
|
||||
//**************************************** VPC
|
||||
if (props)
|
||||
this.vpc = props.vpc;
|
||||
else
|
||||
this.vpc = ec2.Vpc.fromLookup(this, current_env+"Vpc", {
|
||||
vpcName: "VPCStack/"+current_env+"Vpc"
|
||||
});
|
||||
|
||||
//**************************************** SG
|
||||
const description = "Allow access to "+current_env+" MSK Cluster";
|
||||
const SecurityGroup = new ec2.SecurityGroup(
|
||||
this,
|
||||
current_env+"MskClusterSG",
|
||||
{
|
||||
vpc: this.vpc,
|
||||
securityGroupName: current_env+"MskClusterSG",
|
||||
description: description,
|
||||
allowAllOutbound: true
|
||||
}
|
||||
);
|
||||
SecurityGroup.addIngressRule(
|
||||
ec2.Peer.anyIpv4(),
|
||||
ec2.Port.tcp(brokerPort),
|
||||
description
|
||||
);
|
||||
|
||||
//******************************* MSK Cluster **************************//
|
||||
const cluster = new msk.CfnCluster(this, "MskCluster", {
|
||||
brokerNodeGroupInfo: {
|
||||
clientSubnets: this.vpc.privateSubnets.map(x => x.subnetId),
|
||||
instanceType: brokerNodeGroupInstanceType,
|
||||
brokerAzDistribution: brokerNodeGroupBrokerAzDistribution,
|
||||
storageInfo: {
|
||||
ebsStorageInfo: {
|
||||
volumeSize: brokerNodeGroupEBSVolumeSize
|
||||
}
|
||||
}
|
||||
},
|
||||
clusterName: clusterName,
|
||||
kafkaVersion: kafkaVersion,
|
||||
numberOfBrokerNodes: numberOfBrokerNodes,
|
||||
enhancedMonitoring: enhancedMonitoring,
|
||||
tags: {
|
||||
name: current_env+clusterTag,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
19
code/kubernetes/python-cdk/ts/MSK_example/lib/Vpc.ts
Normal file
19
code/kubernetes/python-cdk/ts/MSK_example/lib/Vpc.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import cdk = require('@aws-cdk/core');
|
||||
import ec2 = require("@aws-cdk/aws-ec2");
|
||||
|
||||
export class VPCStack extends cdk.Stack {
|
||||
readonly Vpc: ec2.IVpc;
|
||||
|
||||
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
|
||||
super(scope, id, props);
|
||||
const current_env = this.node.tryGetContext("env.type");
|
||||
|
||||
const vpc_cidr = this.node.tryGetContext("vpc.cidr");
|
||||
const vpc_maxAzs = this.node.tryGetContext("vpc.maxAzs");
|
||||
const vpc = new ec2.Vpc(this, current_env+"Vpc", {
|
||||
cidr: vpc_cidr,
|
||||
maxAzs: vpc_maxAzs
|
||||
});
|
||||
this.Vpc = vpc;
|
||||
}
|
||||
}
|
3331
code/kubernetes/python-cdk/ts/MSK_example/package-lock.json
generated
Normal file
3331
code/kubernetes/python-cdk/ts/MSK_example/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
28
code/kubernetes/python-cdk/ts/MSK_example/package.json
Normal file
28
code/kubernetes/python-cdk/ts/MSK_example/package.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "dev",
|
||||
"version": "0.1.0",
|
||||
"bin": {
|
||||
"dev": "bin/dev.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"watch": "tsc -w",
|
||||
"test": "jest",
|
||||
"cdk": "cdk"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@aws-cdk/assert": "^2.68.0",
|
||||
"@types/jest": "^24.0.18",
|
||||
"aws-cdk": "^1.176.0",
|
||||
"jest": "^29.6.1",
|
||||
"ts-jest": "^29.0.3",
|
||||
"ts-node": "^8.4.1",
|
||||
"typescript": "~3.6.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-cdk/aws-ec2": "^1.12.0",
|
||||
"@aws-cdk/aws-msk": "^1.12.0",
|
||||
"@aws-cdk/core": "^1.12.0",
|
||||
"source-map-support": "^0.5.13"
|
||||
}
|
||||
}
|
23
code/kubernetes/python-cdk/ts/MSK_example/tsconfig.json
Normal file
23
code/kubernetes/python-cdk/ts/MSK_example/tsconfig.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target":"ES2018",
|
||||
"module": "commonjs",
|
||||
"lib": ["es2016", "es2017.object", "es2017.string"],
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"noImplicitThis": true,
|
||||
"alwaysStrict": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": false,
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"experimentalDecorators": true,
|
||||
"strictPropertyInitialization":false,
|
||||
"typeRoots": ["./node_modules/@types"]
|
||||
},
|
||||
"exclude": ["cdk.out"]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue