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

serverless-functions.mddocs/

Serverless Functions

AWS SAM Function construct for creating Lambda functions with serverless-specific features including automatic event source mapping, IAM policies, and deployment configurations.

Capabilities

CfnFunction

Creates a Lambda function with SAM enhancements.

/**
 * AWS::Serverless::Function - Lambda function with SAM enhancements
 */
class CfnFunction extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnFunctionProps
  );
}

interface CfnFunctionProps {
  /** Function code location */
  codeUri?: any;
  /** Runtime environment for the function */
  runtime?: string;
  /** Entry point handler for the function */
  handler?: string; 
  /** Function description */
  description?: string;
  /** Memory allocation in MB (128-10240) */
  memorySize?: number;
  /** Function timeout in seconds (1-900) */
  timeout?: number;
  /** IAM role ARN for the function */
  role?: string;
  /** Managed policy ARNs or policy documents */
  policies?: any;
  /** Environment variables */
  environment?: CfnFunction.FunctionEnvironmentProperty;
  /** Event sources that trigger the function */
  events?: { [key: string]: any };
  /** VPC configuration */
  vpcConfig?: CfnFunction.VpcConfigProperty;
  /** Dead letter queue configuration */
  deadLetterQueue?: CfnFunction.DeadLetterQueueProperty;
  /** Deployment preferences for gradual deployments */
  deploymentPreference?: CfnFunction.DeploymentPreferenceProperty;
  /** Lambda layers */
  layers?: string[];
  /** X-Ray tracing configuration */
  tracing?: string;
  /** Function name override */
  functionName?: string;
  /** IAM permissions boundary */
  permissionsBoundary?: string;
  /** Reserved concurrency limit */
  reservedConcurrencyLimit?: number;
  /** Provisioned concurrency configuration */
  provisionedConcurrencyConfig?: CfnFunction.ProvisionedConcurrencyConfigProperty;
  /** IAM assume role policy document */
  assumeRolePolicyDocument?: any;
  /** Event invoke configuration */
  eventInvokeConfig?: CfnFunction.EventInvokeConfigProperty;
  /** File system configurations */
  fileSystemConfigs?: CfnFunction.FileSystemConfigProperty[];
  /** Code signing configuration ARN */
  codeSigningConfigArn?: string;
  /** Processor architectures */
  architectures?: string[];
  /** Ephemeral storage configuration */
  ephemeralStorage?: CfnFunction.EphemeralStorageProperty;
  /** SnapStart configuration */
  snapStart?: CfnFunction.SnapStartProperty;
  /** Runtime management configuration */
  runtimeManagementConfig?: CfnFunction.RuntimeManagementConfigProperty;
  /** Logging configuration */
  loggingConfig?: CfnFunction.LoggingConfigProperty;
}

Usage Examples:

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

const stack = new cdk.Stack();

// Basic function
new sam.CfnFunction(stack, 'BasicFunction', {
  codeUri: './src',
  runtime: 'nodejs14.x',
  handler: 'index.handler',
});

// Function with API event
new sam.CfnFunction(stack, 'ApiFunction', {
  codeUri: {
    bucket: 'my-bucket',
    key: 'function.zip',
  },
  runtime: 'python3.9',
  handler: 'app.lambda_handler',
  events: {
    HelloWorld: {
      type: 'Api',
      properties: {
        path: '/hello',
        method: 'get',
      },
    },
  },
});

// Function with policies and environment
new sam.CfnFunction(stack, 'EnhancedFunction', {
  codeUri: './dist',
  runtime: 'nodejs14.x', 
  handler: 'index.handler',
  policies: ['AWSLambdaExecute'],
  environment: {
    variables: {
      TABLE_NAME: 'MyTable',
      REGION: 'us-east-1',
    },
  },
  timeout: 30,
  memorySize: 512,
});

Property Types

Environment Configuration

interface FunctionEnvironmentProperty {
  /** Environment variables */
  variables?: { [key: string]: string };
}

VPC Configuration

interface VpcConfigProperty {
  /** Security group IDs */
  securityGroupIds?: string[];
  /** Subnet IDs */
  subnetIds?: string[];
}

Dead Letter Queue

interface DeadLetterQueueProperty {
  /** Target ARN for failed invocations */
  targetArn?: string;
  /** Type of dead letter queue (SNS or SQS) */
  type?: string;
}

Deployment Preferences

interface DeploymentPreferenceProperty {
  /** Enable deployment preferences */
  enabled?: boolean;
  /** Deployment type (Canary10Percent30Minutes, Linear10PercentEvery10Minutes, etc.) */
  type?: string;
  /** CloudWatch alarms for monitoring */
  alarms?: string[];
  /** Pre-traffic and post-traffic hooks */
  hooks?: DeploymentPreferenceHooksProperty;
  /** Rollback trigger configuration */
  triggerConfigurations?: TriggerConfigurationProperty[];
}

interface DeploymentPreferenceHooksProperty {
  /** Pre-traffic hook function ARN */
  preTraffic?: string;
  /** Post-traffic hook function ARN */
  postTraffic?: string;
}

interface TriggerConfigurationProperty {
  /** Trigger events */
  triggerEvents?: string[];
  /** Trigger name */
  triggerName?: string;
  /** Trigger target ARN */
  triggerTargetArn?: string;
}

Provisioned Concurrency

interface ProvisionedConcurrencyConfigProperty {
  /** Provisioned concurrency capacity */
  provisionedConcurrencyCapacity?: number;
}

Event Invoke Configuration

interface EventInvokeConfigProperty {
  /** Destination configuration */
  destinationConfig?: DestinationConfigProperty;
  /** Maximum event age in seconds */
  maximumEventAgeInSeconds?: number;
  /** Maximum retry attempts */
  maximumRetryAttempts?: number;
}

interface DestinationConfigProperty {
  /** On failure destination */
  onFailure?: DestinationProperty;
  /** On success destination */
  onSuccess?: DestinationProperty;
}

interface DestinationProperty {
  /** Destination ARN */
  destination: string;
  /** Destination type */
  type?: string;
}

File System Configuration

interface FileSystemConfigProperty {
  /** EFS access point ARN */
  arn?: string;
  /** Local mount path */
  localMountPath?: string;
}

Storage Configuration

interface EphemeralStorageProperty {
  /** Size in MB (512-10240) */
  size?: number;
}

SnapStart Configuration

interface SnapStartProperty {
  /** Apply SnapStart optimization */
  applyOn?: string;
}

Runtime Management

interface RuntimeManagementConfigProperty {
  /** Runtime update mode */
  updateRuntimeOn?: string;
  /** Runtime version ARN */
  runtimeVersionArn?: string;
}

Logging Configuration

interface LoggingConfigProperty {
  /** Application log level */
  applicationLogLevel?: string;
  /** Log format */
  logFormat?: string;
  /** Log group name */
  logGroup?: string;
  /** System log level */
  systemLogLevel?: string;
}

Event Source Types

API Event

interface ApiEventProperty {
  /** API path */
  path?: string;
  /** HTTP method */
  method?: string;
  /** API Gateway REST API reference */
  restApiId?: string;
  /** Request parameters */
  requestParameters?: any;
}

Schedule Event

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

S3 Event

interface S3EventProperty {
  /** S3 bucket name */
  bucket?: string;
  /** S3 event types */
  events?: string[];
  /** Object key filter */
  filter?: S3NotificationFilterProperty;
}

interface S3NotificationFilterProperty {
  /** S3 key filter */
  s3Key?: S3KeyFilterProperty;
}

interface S3KeyFilterProperty {
  /** Filter rules */
  rules?: S3KeyFilterRuleProperty[];
}

interface S3KeyFilterRuleProperty {
  /** Rule name (prefix or suffix) */
  name?: string;
  /** Rule value */
  value?: string;
}

DynamoDB Event

interface DynamoDBEventProperty {
  /** DynamoDB stream ARN */
  stream?: string;
  /** Starting position (TRIM_HORIZON or LATEST) */
  startingPosition?: string;
  /** Batch size */
  batchSize?: number;
  /** Maximum batching window in seconds */
  maximumBatchingWindowInSeconds?: number;
  /** Event source mapping enabled */
  enabled?: boolean;
}

Kinesis Event

interface KinesisEventProperty {
  /** Kinesis stream ARN */
  stream?: string;  
  /** Starting position */
  startingPosition?: string;
  /** Batch size */
  batchSize?: number;
  /** Maximum batching window in seconds */
  maximumBatchingWindowInSeconds?: number;
  /** Parallelization factor */
  parallelizationFactor?: number;
}

SQS Event

interface SqsEventProperty {
  /** SQS queue ARN */
  queue?: string;
  /** Batch size */
  batchSize?: number;
  /** Maximum batching window in seconds */
  maximumBatchingWindowInSeconds?: number;
  /** Event source mapping enabled */
  enabled?: boolean;
}

SNS Event

interface SnsEventProperty {
  /** SNS topic ARN */
  topic?: string;
  /** Subscription region */
  region?: string;
  /** Subscription filter policy */
  filterPolicy?: any;
}

CloudWatch Events

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

CloudWatch Logs Event

interface CloudWatchLogsEventProperty {
  /** Log group name */
  logGroup?: string;
  /** Filter name */
  filterName?: string;
  /** Filter pattern */
  filterPattern?: string;
}

EventBridge Rule Event

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

interface EventBridgeRuleEventInputTransformerProperty {
  /** Input paths map */
  inputPathsMap?: { [key: string]: string };
  /** Input template */
  inputTemplate?: string;
}