Created
February 4, 2023 22:11
-
-
Save cagdas1/ff483944a487443efe25a6617a61cee9 to your computer and use it in GitHub Desktop.
Cassandra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as cdk from "aws-cdk-lib"; | |
import * as cassandra from "aws-cdk-lib/aws-cassandra" | |
import { config } from "dotenv"; | |
import { Construct } from "constructs"; | |
config(); | |
class CassandraStack extends cdk.Stack { | |
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
// You need to create a keyspace first | |
const keyspace = new cassandra.CfnKeyspace(this, "keyspace", { | |
keyspaceName: "cdkkeyspace" | |
}); | |
// Creating a table | |
const table = new cassandra.CfnTable(this, "table", { | |
keyspaceName: keyspace.keyspaceName as string, | |
tableName: "cdktable", | |
partitionKeyColumns: [ | |
{columnName: "id", columnType: "text"}, | |
{columnName: "name", columnType: "text"}, | |
{columnName: "region", columnType: "text"}, | |
{columnName: "role", columnType: "text"} | |
] | |
}); | |
// table resource is depending keyspace | |
table.addDependsOn(keyspace); | |
new cdk.CfnOutput(this, "keyspace-name", { | |
value: keyspace.keyspaceName as string | |
}); | |
new cdk.CfnOutput(this, "table-name", { | |
value: table.tableName as string | |
}); | |
} | |
} | |
const app = new cdk.App(); | |
new CassandraStack(app, "CassandraStack", { | |
env: { | |
account: process.env.AWS_ACCOUNT_ID, | |
region: process.env.AWS_REGION | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment