or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api-gateway.mddata-state.mdindex.mdlambda-layers.mdserverless-applications.mdserverless-functions.md
tile.json

data-state.mddocs/

Data and State Management

AWS SAM constructs for DynamoDB tables and Step Functions state machines that provide serverless data storage and workflow orchestration capabilities.

Capabilities

CfnSimpleTable

Creates a DynamoDB table with simplified configuration optimized for serverless applications.

/**
 * AWS::Serverless::SimpleTable - DynamoDB table with simplified configuration
 */
class CfnSimpleTable extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnSimpleTableProps
  );
}

interface CfnSimpleTableProps {
  /** Primary key specification */
  primaryKey?: CfnSimpleTable.PrimaryKeyProperty;
  /** Provisioned throughput settings */
  provisionedThroughput?: CfnSimpleTable.ProvisionedThroughputProperty;
  /** Server-side encryption settings */
  sseSpecification?: CfnSimpleTable.SSESpecificationProperty;
  /** Table name override */
  tableName?: string;
  /** Enable point-in-time recovery */
  pointInTimeRecoveryEnabled?: boolean;
  /** Resource tags */
  tags?: { [key: string]: string };
}

Usage Examples:

import * as cdk from '@aws-cdk/core';
import * as sam from '@aws-cdk/aws-sam';

const stack = new cdk.Stack();

// Basic table with default primary key
new sam.CfnSimpleTable(stack, 'BasicTable', {
  // Uses default primary key: 'id' (String)
});

// Table with custom primary key
new sam.CfnSimpleTable(stack, 'UsersTable', {
  primaryKey: {
    name: 'userId',
    type: 'String',
  },
  tableName: 'UserProfiles',
});

// Table with provisioned throughput
new sam.CfnSimpleTable(stack, 'HighThroughputTable', {
  primaryKey: {
    name: 'requestId',
    type: 'String',
  },
  provisionedThroughput: {
    readCapacityUnits: 100,
    writeCapacityUnits: 50,
  },
  pointInTimeRecoveryEnabled: true,
  sseSpecification: {
    sseEnabled: true,
  },
  tags: {
    Environment: 'production',
    BackupRequired: 'true',
  },
});

CfnStateMachine

Creates a Step Functions state machine for serverless workflow orchestration.

/**
 * AWS::Serverless::StateMachine - Step Functions state machine
 */
class CfnStateMachine extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnStateMachineProps
  );
}

interface CfnStateMachineProps {
  /** State machine definition (Amazon States Language) */
  definition?: any;
  /** State machine definition from S3 */
  definitionUri?: any;
  /** Logging configuration */
  logging?: CfnStateMachine.LoggingConfigurationProperty;
  /** State machine name override */
  name?: string;
  /** IAM permissions boundary */
  permissionsBoundary?: string;
  /** Managed policy ARNs or policy documents */  
  policies?: any;
  /** IAM role ARN */
  role?: string;
  /** Resource tags */
  tags?: { [key: string]: string };
  /** State machine type (STANDARD or EXPRESS) */
  type?: string;
  /** Event sources that trigger the state machine */
  events?: { [key: string]: any };
  /** Definition substitutions */
  definitionSubstitutions?: { [key: string]: any };
  /** X-Ray tracing configuration */
  tracing?: CfnStateMachine.TracingConfigurationProperty;
}

Usage Examples:

// Basic state machine with inline definition
new sam.CfnStateMachine(stack, 'SimpleWorkflow', {
  definition: {
    Comment: 'A Hello World example',
    StartAt: 'HelloWorld',
    States: {
      HelloWorld: {
        Type: 'Pass',
        Result: 'Hello World!',
        End: true,
      },
    },
  },
  role: 'arn:aws:iam::123456789012:role/StepFunctionsExecutionRole',
});

// Express state machine for high-volume processing
new sam.CfnStateMachine(stack, 'DataProcessingWorkflow', {
  type: 'EXPRESS',
  definitionUri: {
    bucket: 'my-definitions-bucket',
    key: 'workflows/data-processing.json',
  },
  logging: {
    level: 'ALL',
    includeExecutionData: true,
    destinations: [{
      cloudWatchLogsLogGroup: {
        logGroupArn: 'arn:aws:logs:us-east-1:123456789012:log-group:/aws/stepfunctions/DataProcessing',
      },
    }],
  },
  tracing: {
    enabled: true,
  },
  events: {
    DataUploadEvent: {
      type: 'S3',
      properties: {
        bucket: 'data-upload-bucket',
        events: ['s3:ObjectCreated:*'],
        filter: {
          s3Key: {
            rules: [{
              name: 'prefix',
              value: 'incoming/',
            }],
          },
        },
      },
    },
  },
});

// State machine with scheduled execution
new sam.CfnStateMachine(stack, 'DailyReportWorkflow', {
  definition: {
    Comment: 'Daily report generation workflow',
    StartAt: 'GenerateReport',
    States: {
      GenerateReport: {
        Type: 'Task',
        Resource: 'arn:aws:lambda:us-east-1:123456789012:function:GenerateReport',
        End: true,
      },
    },
  },
  policies: ['AWSLambdaExecute'],
  events: {
    DailySchedule: {
      type: 'Schedule',
      properties: {
        schedule: 'cron(0 8 * * ? *)', // Daily at 8 AM
        input: JSON.stringify({
          reportType: 'daily',
          format: 'pdf',
        }),
      },
    },
  },
});

Simple Table Property Types

Primary Key Configuration

interface PrimaryKeyProperty {
  /** Primary key attribute name */
  name?: string;
  /** Primary key data type (String, Number, or Binary) */
  type?: string;
}

Provisioned Throughput

interface ProvisionedThroughputProperty {
  /** Read capacity units per second */
  readCapacityUnits?: number;
  /** Write capacity units per second */
  writeCapacityUnits?: number;
}

Server-Side Encryption

interface SSESpecificationProperty {
  /** Enable server-side encryption */
  sseEnabled?: boolean;
}

State Machine Property Types

Logging Configuration

interface LoggingConfigurationProperty {
  /** Logging level (OFF, ALL, ERROR, FATAL) */
  level?: string;
  /** Include execution data in logs */
  includeExecutionData?: boolean;
  /** Log destinations */
  destinations?: LogDestinationProperty[];
}

interface LogDestinationProperty {
  /** CloudWatch Logs configuration */
  cloudWatchLogsLogGroup?: CloudWatchLogsLogGroupProperty;
}

interface CloudWatchLogsLogGroupProperty {
  /** Log group ARN */
  logGroupArn?: string;
}

Tracing Configuration

interface TracingConfigurationProperty {
  /** Enable X-Ray tracing */
  enabled?: boolean;
}

Event Source Types

Schedule Event

interface ScheduleEventProperty {
  /** Schedule expression (rate or cron) */
  schedule?: string;
  /** Event name */
  name?: string;
  /** Event description */
  description?: string;
  /** Input data for the execution */
  input?: string;
  /** Enable/disable the event */
  enabled?: boolean;
}

CloudWatch Events

interface CloudWatchEventProperty {
  /** Event pattern */
  pattern?: any;
  /** Input data for the execution */
  input?: string;
  /** Input path for transforming event data */
  inputPath?: string;
}

EventBridge Rule Event

interface EventBridgeRuleEventProperty {
  /** Event pattern */
  pattern?: any;
  /** Event bus name */
  eventBusName?: string;
  /** Input data for the execution */
  input?: string;
  /** Input path */
  inputPath?: string;
}

Advanced Usage Patterns

DynamoDB Integration Patterns

// Table for user sessions with TTL
new sam.CfnSimpleTable(stack, 'UserSessions', {
  primaryKey: {
    name: 'sessionId',
    type: 'String',
  },
  // Note: TTL configuration requires full DynamoDB construct
  // SimpleTable provides basic functionality only
});

// Multiple related tables
const usersTable = new sam.CfnSimpleTable(stack, 'Users', {
  primaryKey: { name: 'userId', type: 'String' },
});

const ordersTable = new sam.CfnSimpleTable(stack, 'Orders', {
  primaryKey: { name: 'orderId', type: 'String' },
  // Foreign key relationship managed in application logic
});

State Machine Workflow Patterns

// Error handling workflow
new sam.CfnStateMachine(stack, 'ErrorHandlingWorkflow', {
  definition: {
    Comment: 'Workflow with error handling',
    StartAt: 'ProcessData',
    States: {
      ProcessData: {
        Type: 'Task',
        Resource: 'arn:aws:lambda:us-east-1:123456789012:function:ProcessData',
        Catch: [{
          ErrorEquals: ['States.ALL'],
          Next: 'HandleError',
        }],
        Next: 'Success',
      },
      HandleError: {
        Type: 'Task',
        Resource: 'arn:aws:lambda:us-east-1:123456789012:function:HandleError',
        End: true,
      },
      Success: {
        Type: 'Pass',
        Result: 'Processing completed successfully',
        End: true,
      },
    },
  },
  policies: ['AWSLambdaExecute'],
});

// Parallel processing workflow
new sam.CfnStateMachine(stack, 'ParallelProcessing', {
  definition: {
    Comment: 'Parallel data processing',
    StartAt: 'ParallelProcessing',
    States: {
      ParallelProcessing: {
        Type: 'Parallel',
        Branches: [
          {
            StartAt: 'ProcessTypeA',
            States: {
              ProcessTypeA: {
                Type: 'Task',
                Resource: 'arn:aws:lambda:us-east-1:123456789012:function:ProcessTypeA',
                End: true,
              },
            },
          },
          {
            StartAt: 'ProcessTypeB',
            States: {
              ProcessTypeB: {
                Type: 'Task',
                Resource: 'arn:aws:lambda:us-east-1:123456789012:function:ProcessTypeB',
                End: true,
              },
            },
          },
        ],
        Next: 'CombineResults',
      },
      CombineResults: {
        Type: 'Task',
        Resource: 'arn:aws:lambda:us-east-1:123456789012:function:CombineResults',
        End: true,
      },
    },
  },
  type: 'STANDARD',
});

Integration Patterns

// State machine that writes to SimpleTable
new sam.CfnStateMachine(stack, 'DataPersistenceWorkflow', {
  definition: {
    Comment: 'Store processed data in DynamoDB',
    StartAt: 'ProcessData',
    States: {
      ProcessData: {
        Type: 'Task',
        Resource: 'arn:aws:lambda:us-east-1:123456789012:function:ProcessData',
        Next: 'StoreInDynamoDB',
      },
      StoreInDynamoDB: {
        Type: 'Task',
        Resource: 'arn:aws:states:::dynamodb:putItem',
        Parameters: {
          TableName: 'ProcessedDataTable',
          Item: {
            'id': { 'S.$': '$.id' },
            'data': { 'S.$': '$.processedData' },
            'timestamp': { 'S.$': '$.timestamp' },
          },
        },
        End: true,
      },
    },
  },
  policies: [
    'AWSLambdaExecute',
    {
      Version: '2012-10-17',
      Statement: [{
        Effect: 'Allow',
        Action: ['dynamodb:PutItem'],
        Resource: 'arn:aws:dynamodb:us-east-1:123456789012:table/ProcessedDataTable',
      }],
    },
  ],
});