-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
156 lines (143 loc) · 5.72 KB
/
template.yaml
File metadata and controls
156 lines (143 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-test-ec
Sample SAM Template for sam-test-ec
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Resources:
# CFDistribution:
# Type: AWS::CloudFront::Distribution
# Properties:
# DistributionConfig:
# Enabled: 'true'
# Comment: Lambda@Edge SAM Sample
# DefaultRootObject: index.html
# Origins:
# -
# Id: MyOrigin
# DomainName: aws.amazon.com # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-origin.html
# CustomOriginConfig:
# HTTPPort: 80
# OriginProtocolPolicy: match-viewer
# DefaultCacheBehavior:
# TargetOriginId: MyOrigin
# # Lambda@Edge configuration requires a function version not alias
# LambdaFunctionAssociations:
# -
# EventType: origin-request
# # <SAM-Function.Version> provides {FunctionARN}:{Version} which is exactly what Cloudfront expects
# # SAM Benefit here is upon function changes this function version will also be updated in Cloudfront
# LambdaFunctionARN: !Ref HelloWorldFunction.Version
# ForwardedValues:
# QueryString: 'false'
# Headers:
# - Origin
# Cookies:
# Forward: none
# ViewerProtocolPolicy: allow-all
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Layers:
- !Ref HelloWorldDepLayer
Runtime: python3.7
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get
AutoPublishAlias: live
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action: "sts:AssumeRole"
Principal:
Service:
- "lambda.amazonaws.com"
- "edgelambda.amazonaws.com"
DeploymentPreference:
Type: Linear10PercentEvery1Minute
Alarms:
# A list of alarms that you want to monitor
- !Ref AliasErrorMetricGreaterThanZeroAlarm
- !Ref LatestVersionErrorMetricGreaterThanZeroAlarm
# Hooks:
# Validation Lambda functions that are run before & after traffic shifting
# PreTraffic: !Ref PreTrafficLambdaFunction
# PostTraffic: !Ref PostTrafficLambdaFunction
HelloWorldDepLayer:
Type: AWS::Serverless::LayerVersion
Properties:
Description: Dependencies for sam app
ContentUri: 'dependencies/'
CompatibleRuntimes:
- python3.7
Metadata:
BuildMethod: python3.7
# CW Alarm to monitor the new Lambda version for errors
AliasErrorMetricGreaterThanZeroAlarm:
Type: AWS::CloudWatch::Alarm
DependsOn: HelloWorldFunction
Properties:
AlarmName: !Sub sam-test-ec-AliasErrorMetricGreaterThanZeroAlarm-${HelloWorldFunction}
AlarmDescription: "pre-deployment alarm to check for errors in the function"
#AlarmActions:
# - !Ref AlarmTopic
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: FunctionName
Value: !Ref HelloWorldFunction
EvaluationPeriods: 1
MetricName: Errors
Namespace: AWS/Lambda
Period: '60'
Statistic: Sum
Threshold: '1'
# CW Alarm to monitor the new Lambda version for errors
LatestVersionErrorMetricGreaterThanZeroAlarm:
Type: AWS::CloudWatch::Alarm
DependsOn: HelloWorldFunction
Properties:
AlarmName: !Sub sam-test-ec-LatestVersionErrorMetricGreaterThanZeroAlarm-${HelloWorldFunction}
AlarmDescription: "pre-deployment alarm to check for errors in the function"
#AlarmActions:
# - !Ref AlarmTopic
ComparisonOperator: GreaterThanOrEqualToThreshold
TreatMissingData: missing
Dimensions:
- Name: FunctionName
Value: !Ref HelloWorldFunction
- Name: Resource
Value: !Join [":", [!Ref HelloWorldFunction, !Select ["7", !Split [":", !Ref HelloWorldFunction.Version]]]]
EvaluationPeriods: 1
MetricName: Errors
Namespace: AWS/Lambda
Period: '60'
Statistic: Sum
Threshold: '1'
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionSampleVersion:
Description: Lambda@Edge Sample Function ARN with Version
Value: !Ref HelloWorldFunction.Version
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
# CFDistribution:
# Description: Cloudfront Distribution Domain Name
# Value: !GetAtt CFDistribution.DomainName