AWS Serverless Application Model
Developer Guide

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Declaring Serverless Resources

AWS SAM defines the following resources that are specifically designed for serverless applications:

AWS::Serverless::Api

This resource type describes an API Gateway resource. It's useful for advanced use cases where you want full control and flexibility when you configure your APIs. For most scenarios, we recommend that you create APIs by specifying this resource type as an event source of your AWS::Serverless::Function resource.

Type: AWS::Serverless::Api Properties: StageName: prod DefinitionUri: swagger.yml

For a list of properties, see AWS::Serverless::Api in the AWS SAM GitHub repository.

AWS::Serverless::Application

This resource type embeds a serverless application from the AWS Serverless Application Repository or from an Amazon S3 bucket as a nested application. Nested applications are deployed as nested stacks, which can contain multiple other resources. For more information about nested applications, see Nested Applications.

The following is an example of a nested application from the AWS Serverless Application Repository:

Type: AWS::Serverless::Application Properties: Location: ApplicationId: arn:aws:serverlessrepo:region:account-id:applications/application-name SemanticVersion: 1.0.0 Parameters: StringParameter: parameter-value IntegerParameter: 2

The following is an example of a nested application that's hosted in an Amazon S3 bucket. In this example, sam-template-object is the name of a packaged AWS SAM template:

Type: AWS::Serverless::Application Properties: Location: https://s3.region.amazonaws.com/bucket-name/sam-template-object Parameters: StringParameter: parameter-value IntegerParameter: 2

For a list of properties, see AWS::Serverless::Application in the AWS SAM GitHub repository.

For details about how to obtain the required values of an application that you want to nest, see Nested Applications.

AWS::Serverless::Function

This resource type describes configuration information for creating a Lambda function. You can describe any event source that you want to attach to the Lambda function—such as Amazon S3, Amazon DynamoDB Streams, and Amazon Kinesis Data Streams.

The following is an example of a serverless function:

Type: AWS::Serverless::Function Properties: Handler: index.js Runtime: nodejs8.10 CodeUri: 's3://my-code-bucket/my-function.zip' Description: Creates thumbnails of uploaded images MemorySize: 1024 Timeout: 15 Policies: - AWSLambdaExecute # Managed Policy - Version: '2012-10-17' # Policy Document Statement: - Effect: Allow Action: - s3:GetObject - s3:GetObjectACL Resource: 'arn:aws:s3:::my-bucket/*' Environment: Variables: TABLE_NAME: my-table Events: PhotoUpload: Type: S3 Properties: Bucket: my-photo-bucket Tags: AppNameTag: ThumbnailApp DepartmentNameTag: ThumbnailDepartment

For a list of properties, see AWS::Serverless::Function in the AWS SAM GitHub repository.

AWS::Serverless::LayerVersion

This resource type creates a Lambda layer version (LayerVersion) that contains library or runtime code that's needed by a Lambda function. When a serverless layer version is transformed, AWS SAM also transforms the logical ID of the resource so that old layer versions aren't automatically deleted by AWS CloudFormation when the resource is updated.

The following is an example of a layer version:

Type: AWS::Serverless::LayerVersion Properties: LayerName: MyLayer Description: Layer description ContentUri: 's3://my-bucket/my-layer.zip' CompatibleRuntimes: - nodejs6.10 - nodejs8.10 LicenseInfo: 'Available under the MIT-0 license.' RetentionPolicy: Retain

For a list of properties, see AWS::Serverless::LayerVersion in the AWS SAM GitHub repository.

AWS::Serverless::SimpleTable

This resource type provides simple syntax for describing how to create DynamoDB tables. Here's an example:

Type: AWS::Serverless::SimpleTable Properties: PrimaryKey: Name: id Type: String ProvisionedThroughput: ReadCapacityUnits: 5 WriteCapacityUnits: 5

For a list of properties, see AWS::Serverless::SimpleTable in the AWS SAM GitHub repository.

For reference documentation for SAM template resources, see AWS SAM Specification on GitHub.