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

index.mddocs/

AWS Serverless Application Model (SAM) Construct Library

The AWS CDK construct library for AWS Serverless Application Model (SAM) resources provides L1 (CloudFormation level) constructs for deploying serverless applications using SAM syntax within CDK stacks. This library automatically generates TypeScript constructs from CloudFormation AWS::Serverless resource specifications, enabling developers to define serverless functions, APIs, and applications using familiar SAM patterns.

Package Information

  • Package Name: @aws-cdk/aws-sam
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @aws-cdk/aws-sam
  • Status: End-of-Support (CDK v1)

Core Imports

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

For specific constructs:

import { CfnFunction, CfnApi, CfnApplication } from '@aws-cdk/aws-sam';

Basic Usage

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

const stack = new cdk.Stack();

// Create a serverless function
new sam.CfnFunction(stack, 'MyFunction', {
  codeUri: {
    bucket: 'my-deployment-bucket',
    key: 'function.zip',
  },
  runtime: 'nodejs14.x',
  handler: 'index.handler',
  events: {
    Api: {
      type: 'Api',
      properties: {
        path: '/hello',
        method: 'get',
      },
    },
  },
});

Architecture

This library follows AWS CDK's standard L1 construct pattern:

  • Auto-Generated Constructs: All constructs are generated from AWS::Serverless CloudFormation specifications
  • L1 Level: Direct mapping to CloudFormation resources without higher-level abstractions
  • Property Interfaces: Each construct has corresponding Props interface defining all available properties
  • Nested Properties: Complex configuration options exposed as nested property interfaces
  • JSII Compatible: Multi-language support for .NET, Java, Python through JSII

Capabilities

Serverless Functions

Core Lambda function construct with SAM enhancements including automatic event source mapping, IAM role creation, and deployment preferences.

class CfnFunction extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnFunctionProps
  );
}

interface CfnFunctionProps {
  codeUri?: any;
  runtime?: string;
  handler?: string;
  events?: { [key: string]: any };
  policies?: any;
  environment?: any;
  // ... additional properties
}

Serverless Functions

API Gateway Integration

REST and HTTP API Gateway constructs with SAM-specific configuration for CORS, authentication, and custom domains.

class CfnApi extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnApiProps
  );
}

class CfnHttpApi extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnHttpApiProps
  );
}

API Gateway Integration

Serverless Applications

Deploy pre-built serverless applications from the AWS Serverless Application Repository.

class CfnApplication extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnApplicationProps
  );
}

interface CfnApplicationProps {
  location: any;
  parameters?: { [key: string]: string };
  tags?: { [key: string]: string };
}

Serverless Applications

Data and State Management

DynamoDB table and Step Functions state machine constructs for serverless data storage and workflow orchestration.

class CfnSimpleTable extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnSimpleTableProps
  );
}

class CfnStateMachine extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnStateMachineProps
  );
}

Data and State Management

Lambda Layers

Lambda layer version construct for sharing code and dependencies across functions.

class CfnLayerVersion extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnLayerVersionProps
  );
}

interface CfnLayerVersionProps {
  contentUri?: any;
  compatibleRuntimes?: string[];
  description?: string;
}

Lambda Layers

Common Types

// Base CDK construct and properties
import * as cdk from '@aws-cdk/core';

// Common property patterns used across constructs
interface TagsProperty {
  [key: string]: string;
}

interface ParametersProperty {
  [key: string]: string;
}

// Location specification for applications and code
interface LocationProperty {
  applicationId?: string;
  semanticVersion?: string;
  bucket?: string;
  key?: string;
  version?: string;
}