Created
September 22, 2023 21:06
-
-
Save fl0wo/925ccf9a4a5dd8b1366b09e1b187fd1e to your computer and use it in GitHub Desktop.
Utility method to create an AWS Timestream Database
This file contains hidden or 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 { RemovalPolicy } from 'aws-cdk-lib'; | |
| import { CfnDatabase, CfnTable } from 'aws-cdk-lib/aws-timestream'; | |
| import { Construct } from 'constructs'; | |
| export interface TimeStreamConstructProps { | |
| databaseName: string; | |
| tableName: string; | |
| } | |
| export class TimeStreamConstruct extends Construct { | |
| public readonly database: CfnDatabase; | |
| public readonly table: CfnTable; | |
| constructor(scope: Construct, id: string, props: TimeStreamConstructProps) { | |
| super(scope, id); | |
| this.database = new CfnDatabase(this, props.databaseName+'Cfn', { | |
| databaseName: props.databaseName, | |
| }); | |
| this.database.applyRemovalPolicy(RemovalPolicy.DESTROY); | |
| this.table = new CfnTable(this, props.tableName+'Cfn', { | |
| tableName: props.tableName, | |
| databaseName: props.databaseName, | |
| retentionProperties: { | |
| memoryStoreRetentionPeriodInHours: (24 * 60).toString(10), | |
| magneticStoreRetentionPeriodInDays: (60 * 10).toString(10), | |
| }, | |
| }); | |
| this.table.node.addDependency(this.database); | |
| this.table.applyRemovalPolicy(RemovalPolicy.DESTROY); | |
| } | |
| } | |
| export const addTimeStreamDB = ( | |
| scope: Construct, | |
| id: string, | |
| databaseName: string, | |
| tableName:string) => { | |
| return new TimeStreamConstruct(scope, id, { | |
| databaseName: databaseName, | |
| tableName: tableName, | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment