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-applications.mddocs/

Serverless Applications

AWS SAM construct for deploying pre-built serverless applications from the AWS Serverless Application Repository.

Capabilities

CfnApplication

Deploy serverless applications from the AWS Serverless Application Repository.

/**
 * AWS::Serverless::Application - Serverless application from AWS Serverless Application Repository
 */
class CfnApplication extends cdk.CfnResource {
  constructor(
    scope: cdk.Construct,
    id: string,
    props: CfnApplicationProps
  );
}

interface CfnApplicationProps {
  /** Application location specification */
  location: CfnApplication.ApplicationLocationProperty;
  /** Application parameters */
  parameters?: { [key: string]: string };
  /** CloudFormation notification ARNs */
  notificationArns?: string[];
  /** Resource tags */
  tags?: { [key: string]: string };
  /** Deployment timeout in minutes */
  timeoutInMinutes?: number;
}

Usage Examples:

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

const stack = new cdk.Stack();

// Deploy application from Serverless Application Repository
new sam.CfnApplication(stack, 'TwitterEventSource', {
  location: {
    applicationId: 'arn:aws:serverlessrepo:us-east-1:077246666028:applications/aws-serverless-twitter-event-source',
    semanticVersion: '2.0.0',
  },
  parameters: {
    SearchText: '#serverless -filter:nativeretweets',
    TweetProcessorFunctionName: 'ProcessTweets',
    StreamModeEnabled: 'true',
  },
});

// Deploy application with custom timeout and notifications
new sam.CfnApplication(stack, 'DataProcessor', {
  location: {
    applicationId: 'arn:aws:serverlessrepo:us-west-2:123456789012:applications/data-processing-pipeline',
    semanticVersion: '1.5.2', 
  },
  parameters: {
    BucketName: 'my-data-bucket',
    ProcessingMemory: '1024',
    MaxConcurrentExecutions: '100',
  },
  notificationArns: [
    'arn:aws:sns:us-west-2:123456789012:deployment-notifications'
  ],
  timeoutInMinutes: 60,
  tags: {
    Environment: 'production',
    Team: 'data-engineering',
    CostCenter: 'analytics',
  },
});

// Deploy nested application template from S3
new sam.CfnApplication(stack, 'CustomApp', {
  location: {
    templateUrl: 'https://s3.amazonaws.com/my-bucket/templates/app.yaml',
  },
  parameters: {
    Stage: 'prod',
    Region: 'us-east-1',
  },
});

Property Types

Application Location

interface ApplicationLocationProperty {
  /** Serverless Application Repository application ID */
  applicationId?: string;
  /** Application semantic version */
  semanticVersion?: string;
  /** Template URL from S3 */
  templateUrl?: string;
}

Common Use Cases

Serverless Application Repository Applications

Deploy pre-built applications from the AWS Serverless Application Repository:

// Event processing applications
new sam.CfnApplication(stack, 'S3EventProcessor', {
  location: {
    applicationId: 'arn:aws:serverlessrepo:us-east-1:123456789012:applications/s3-image-processor',
    semanticVersion: '1.0.0',
  },
  parameters: {
    SourceBucket: 'source-images',
    DestinationBucket: 'processed-images',
    ImageFormat: 'jpeg',
    Quality: '85',
  },
});

// Monitoring and logging applications  
new sam.CfnApplication(stack, 'LogAnalyzer', {
  location: {
    applicationId: 'arn:aws:serverlessrepo:us-east-1:123456789012:applications/cloudwatch-log-analyzer',
    semanticVersion: '2.1.0',
  },
  parameters: {
    LogGroupPattern: '/aws/lambda/*',
    AlertEmail: 'alerts@company.com',
    ThresholdErrors: '10',
  },
});

Custom Application Templates

Deploy your own application templates stored in S3:

// Deploy custom multi-service application
new sam.CfnApplication(stack, 'MicroservicesApp', {
  location: {
    templateUrl: 'https://s3.amazonaws.com/my-templates/microservices.yaml',
  },
  parameters: {
    VpcId: 'vpc-12345678',
    SubnetIds: 'subnet-12345678,subnet-87654321',
    DatabasePassword: 'secure-password-from-secrets-manager',
    ApiDomainName: 'api.mycompany.com',
  },
  timeoutInMinutes: 120, // Extended timeout for complex deployments
});

// Deploy environment-specific configurations
new sam.CfnApplication(stack, 'StagingEnvironment', {
  location: {
    templateUrl: 'https://s3.amazonaws.com/my-templates/environment.yaml',
  },
  parameters: {
    Environment: 'staging',
    InstanceType: 't3.small',
    MinCapacity: '2',
    MaxCapacity: '10',
    AlertingEnabled: 'false',
  },
  tags: {
    Environment: 'staging',
    AutoShutdown: 'true',
    Owner: 'dev-team',
  },
});

Application Dependencies

Chain applications that depend on each other:

// Base infrastructure application
const infrastructure = new sam.CfnApplication(stack, 'Infrastructure', {
  location: {
    applicationId: 'arn:aws:serverlessrepo:us-east-1:123456789012:applications/base-infrastructure',
    semanticVersion: '1.2.0',
  },
  parameters: {
    VpcCidr: '10.0.0.0/16',
    EnableNatGateway: 'true',
  },
});

// Application that depends on the infrastructure
new sam.CfnApplication(stack, 'WebApplication', {
  location: {
    applicationId: 'arn:aws:serverlessrepo:us-east-1:123456789012:applications/web-app-stack',
    semanticVersion: '2.0.1',
  },
  parameters: {
    VpcId: infrastructure.getAtt('Outputs.VpcId').toString(),
    PrivateSubnetIds: infrastructure.getAtt('Outputs.PrivateSubnetIds').toString(),
    DatabaseEndpoint: infrastructure.getAtt('Outputs.DatabaseEndpoint').toString(),
  },
});

Best Practices

Parameter Management

Use AWS Systems Manager Parameter Store or AWS Secrets Manager for sensitive parameters:

new sam.CfnApplication(stack, 'SecureApp', {
  location: {
    applicationId: 'arn:aws:serverlessrepo:us-east-1:123456789012:applications/secure-api',
    semanticVersion: '1.0.0',
  },
  parameters: {
    // Reference parameter store values
    DatabasePassword: '{{resolve:secretsmanager:prod/db/password:SecretString:password}}',
    ApiKey: '{{resolve:ssm:/prod/api/key}}',
    
    // Static configuration
    Environment: 'production',
    LogLevel: 'INFO',
  },
});

Error Handling

Configure appropriate timeouts and notification ARNs for deployment monitoring:

new sam.CfnApplication(stack, 'MonitoredApp', {
  location: {
    applicationId: 'arn:aws:serverlessrepo:us-east-1:123456789012:applications/complex-app',
    semanticVersion: '3.0.0',
  },
  parameters: {
    ComponentCount: '25',
    ProcessingMode: 'batch',
  },
  
  // Extended timeout for complex applications
  timeoutInMinutes: 180,
  
  // Get notified of deployment status
  notificationArns: [
    'arn:aws:sns:us-east-1:123456789012:deployment-success',
    'arn:aws:sns:us-east-1:123456789012:deployment-failure',
  ],
  
  tags: {
    Complexity: 'high',
    MonitoringLevel: 'detailed',
  },
});