-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02-service-api-lambda.yml
169 lines (157 loc) · 5.01 KB
/
02-service-api-lambda.yml
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
EmojiSearchImage:
Type: String
ProjectName:
Type: String
CommitHash:
Type: String
Resources:
ListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- TargetGroupArn: !Ref LoadBalancerTargetGroup
Type: forward
Conditions:
- Field: path-pattern
PathPatternConfig:
Values:
- /emoji-search/recommendations*
ListenerArn: !ImportValue T3chFlicksAPI-LoadBalancerListenerArn
Priority: 2
LoadBalancerTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
TargetType: lambda
Targets:
- AvailabilityZone: all
Id: !GetAtt LambdaFunction.Arn
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Tags:
- Key: Project
Value: !Ref ProjectName
PackageType: "Image"
MemorySize: "1536"
Timeout: 10
Code:
ImageUri: !Sub ${EmojiSearchImage}:${CommitHash}
Role: !GetAtt LambdaRole.Arn
Environment:
Variables:
TABLE_NAME: !ImportValue T3chFlicks-UserTableName
CHARGE_LAMBDA: !ImportValue T3chFlicks-ChargeLambdaName
REFUND_LAMBDA: !ImportValue T3chFlicks-RefundLambdaName
LambdaPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LambdaFunction
Action: 'lambda:InvokeFunction'
Principal: elasticloadbalancing.amazonaws.com
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: [ 'sts:AssumeRole' ]
Effect: Allow
Principal:
Service: [ 'lambda.amazonaws.com' ]
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
Policies:
- PolicyName: "UserTableAccessPolicy"
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'dynamodb:GetItem*'
Resource: !ImportValue T3chFlicks-UserTableArn
- PolicyName: "ChargeAndRefundPolicy"
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'lambda:invoke*'
Resource:
- !ImportValue T3chFlicks-ChargeLambdaArn
- !ImportValue T3chFlicks-RefundLambdaArn
HTTP5xxsAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
AlarmDescription: !Sub Sum Http 500s for ${ProjectName}
AlarmActions:
- !ImportValue AlertSNSTopicArn
MetricName: HTTPCode_Target_5XX_Count
TreatMissingData: notBreaching
Namespace: AWS/ApplicationELB
Statistic: Sum
Period: '60'
EvaluationPeriods: '1'
Threshold: 1
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: TargetGroup
Value: !GetAtt LoadBalancerTargetGroup.TargetGroupFullName
- Name: LoadBalancer
Value: !ImportValue T3chFlicksAPI-LoadBalancerArn
HTTP4xxsAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
AlarmDescription: !Sub Sum Http 400s for ${ProjectName}
AlarmActions:
- !ImportValue AlertSNSTopicArn
MetricName: HTTPCode_Target_4XX_Count
TreatMissingData: notBreaching
Namespace: AWS/ApplicationELB
Statistic: Sum
Period: '60'
EvaluationPeriods: '1'
Threshold: 1
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: TargetGroup
Value: !GetAtt LoadBalancerTargetGroup.TargetGroupFullName
- Name: LoadBalancer
Value: !ImportValue T3chFlicksAPI-LoadBalancerArn
# CPUAlarm:
# Type: "AWS::CloudWatch::Alarm"
# Properties:
# AlarmDescription: !Sub CPU alarm for ${ProjectName}
# AlarmActions:
# - !ImportValue AlertSNSArn
# MetricName: CPUUtilization
# Namespace: AWS/ECS
# Statistic: Average
# Period: '60'
# EvaluationPeriods: '2'
# Threshold: 90
# ComparisonOperator: GreaterThanThreshold
# Dimensions:
# - Name: ServiceName
# Value: !GetAtt Service.Name
# - Name: ClusterName
# Value: !ImportValue ECSCluster
# LatencyAlarm:
# Type: AWS::CloudWatch::Alarm
# Properties:
# AlarmDescription: "Alert if latency is over 1 seconds"
# AlarmActions:
# - !ImportValue AlertSNSArn
# Namespace: AWS/ApplicationELB
# MetricName: TargetResponseTime
# Statistic: Average
# Period: 60
# EvaluationPeriods: 2
# ComparisonOperator: GreaterThanThreshold
# Threshold: 1.0
# Dimensions:
# - Name: TargetGroup
# Value: !GetAtt TargetGroup.TargetGroupFullName
# TreatMissingData: notBreaching