diff --git a/lib/stacks/my-stack/database/items/create-items-dynamodb.ts b/lib/stacks/my-stack/database/items/create-items-dynamodb.ts new file mode 100644 index 0000000..291f41c --- /dev/null +++ b/lib/stacks/my-stack/database/items/create-items-dynamodb.ts @@ -0,0 +1,16 @@ +import { RemovalPolicy } from 'aws-cdk-lib'; +import * as dynamodb from 'aws-cdk-lib/aws-dynamodb'; +import { Construct } from 'constructs'; + +export function createItemsDynamoDB(scope: Construct): dynamodb.Table { + const table = new dynamodb.Table(scope, 'turbogate-example-items', { + tableName: 'items', + partitionKey: { + name: "id", + type: dynamodb.AttributeType.STRING, + }, + billingMode: dynamodb.BillingMode.PAY_PER_REQUEST, + removalPolicy: RemovalPolicy.DESTROY, + }); + return table; +} \ No newline at end of file diff --git a/lib/stacks/my-stack/database/items/item-record.ts b/lib/stacks/my-stack/database/items/item-record.ts new file mode 100644 index 0000000..befbbf8 --- /dev/null +++ b/lib/stacks/my-stack/database/items/item-record.ts @@ -0,0 +1,17 @@ +import z from "zod"; + +export const zItemRecord = z + .strictObject({ + id: z.string().uuid().openapi({ description: 'The ID of the item. Generated by the backend upon creation.' }), + name: z.string().min(5).max(20).openapi({ + description: 'The name of the item. Does not have to be unique and can be changed at any given time.', + example: 'Excellent Item', + }), + description: z.string().optional().openapi({ + description: 'The description of the item. Can be changed at any given time.', + example: 'This item is of exceptional excellence.', + }), + }) + .openapi('Item', { description: 'An item.' }); + +export type ItemRecord = z.infer; \ No newline at end of file diff --git a/lib/stacks/my-stack/index.ts b/lib/stacks/my-stack/index.ts index bcb745c..0d5385d 100644 --- a/lib/stacks/my-stack/index.ts +++ b/lib/stacks/my-stack/index.ts @@ -1,8 +1,11 @@ import * as cdk from 'aws-cdk-lib'; import { Construct } from 'constructs'; +import { createItemsDynamoDB } from './database/items/create-items-dynamodb'; export class MyStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); + + const itemsTable = createItemsDynamoDB(this); } }