You can build this application using AWS SAM. To learn more about creating AWS SAM templates, see AWS SAM template basics in the AWS Serverless Application Model Developer Guide.
Below is a sample AWS SAM template for the Lambda application from the tutorial. Copy the text below to a .yaml file and save it next to the ZIP package you created previously. Note that the Handler
and Runtime
parameter values should match the ones you used when you created the function in the previous section.
Example template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
NotificationEmail:
Type: String
Resources:
CheckWebsitePeriodically:
Type: [AWS::Serverless::Function](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html)
Properties:
Handler: LambdaFunctionOverHttps.handler
Runtime: runtime
Policies: AmazonDynamoDBFullAccess
Events:
CheckWebsiteScheduledEvent:
Type: Schedule
Properties:
Schedule: rate(1 minute)
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Protocol: email
Endpoint: !Ref NotificationEmail
Alarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions:
- !Ref AlarmTopic
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: FunctionName
Value: !Ref CheckWebsitePeriodically
EvaluationPeriods: 1
MetricName: Errors
Namespace: AWS/Lambda
Period: 60
Statistic: Sum
Threshold: '1'
For information on how to package and deploy your serverless application using the package and deploy commands, see Deploying serverless applications in the AWS Serverless Application Model Developer Guide.