AWS Serverless Application Model (SAM) is a template driven tool for creating and managing serverless applications. In just a few lines of code you can define complex AWS Lambda based serverless applications, security permissions, and advanced configuration capabilities. Join us as we dive deep into best practices and tricks for using SAM at scale, including how to make the most of the dynamic template capabilities of SAM, how to use advanced features such as deployment preferences and policy templates, and how to debug serverless applications with SAM CLI.
Speaker: Chris Munns - Principal Developer Advocate, AWS Serverless Applications, AWS
8. SAM Template
Tells AWS CloudFormation this is a SAM
template it needs to “transform”
Creates a AWS Lambda function with
the referenced managed AWS IAM
policy, runtime, code at the referenced
zip location, and handler as defined.
Also creates an Amazon API Gateway
and takes care of all
mapping/permissions necessary
Creates a Amazon DynamoDB table with
5 Read & Write units
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.gethtml
Runtime: nodejs6.10
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
ListTable:
Type: AWS::Serverless::SimpleTable
11. AWS SAM Template Properties
StageName: prod
DefinitionUri: swagger.yml
CacheClusterEnabled: true
CacheClusterSize: 28.4
EndpointConfiguration: REGIONAL
Variables:
VarName: VarValue
From SAM Version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
AWS::Serverless::LayerVersion
AWS::Serverless::Application
12. AWS SAM Template Properties
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Tags:
Department: Engineering
AppType: Serverless
SSESpecification:
SSEEnabled: true
From SAM Version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
AWS::Serverless::LayerVersion
AWS::Serverless::Application
13. AWS SAM Template Properties
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
From SAM Version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
AWS::Serverless::LayerVersion
AWS::Serverless::Application
NEW!
14. AWS SAM Template Properties
Resources:
MyApplication:
Properties:
Location:
ApplicationId:
'arn:aws:serverlessrepo:us-east-
1:012345678901:applications/my-
application'
SemanticVersion: 1.0.0
Parameters:
StringParameter: parameter-value
IntegerParameter: 2
From SAM Version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
AWS::Serverless::LayerVersion
AWS::Serverless::Application
NEW!
15. Note: Events are a map of string to Event Source
Object
Event Source Objects have the following structure:
Type:
Properties:
For Example:
Events:
MyEventName:
Type: S3
Properties:
Bucket: my-photo-bucket
AWS::Serverless::Function Event source types
S3
SNS
Kinesis | DynamoDB
Api
Schedule
CloudWatchEvent
IoTRule
AlexaSkill
From SAM Version 2016-10-31