-
Notifications
You must be signed in to change notification settings - Fork 4
/
serverless.yml
88 lines (87 loc) · 2.75 KB
/
serverless.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
service: serverless-load-balancer
frameworkVersion: ">=1.4.6"
plugins:
- serverless-pseudo-parameters
provider:
name: aws
runtime: nodejs8.10
region: eu-central-1
custom:
file: ${file(./config/serverless.config.yml)}
functions:
handler:
handler: handler.handler
events:
- alb:
listenerArn: { Ref: HTTPListener }
priority: 1
conditions:
path: /
method:
- GET
resources:
Outputs:
LoadBalancerDNSName:
Value: !GetAtt LoadBalancer.DNSName
Resources:
SecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupName: ${self:service}
GroupDescription: 'HTTPS/HTTPS inbound; Nothing outbound'
VpcId: ${self:custom.file.VPC_ID}
SecurityGroupIngress:
-
IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
-
IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
-
IpProtocol: -1
FromPort: '1'
ToPort: '1'
CidrIp: 127.0.0.1/32
LoadBalancer:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
Properties:
Type: 'application'
Name: ${self:service}
IpAddressType: 'ipv4'
Scheme: '${self:custom.file.SCHEME}'
LoadBalancerAttributes:
- { Key: 'deletion_protection.enabled', Value: false }
- { Key: 'routing.http2.enabled', Value: false }
- { Key: 'access_logs.s3.enabled', Value: false }
SecurityGroups:
- { Ref: SecurityGroup }
Subnets:
- ${self:custom.file.SUBNET_ID_A}
- ${self:custom.file.SUBNET_ID_B}
- ${self:custom.file.SUBNET_ID_C}
HTTPListener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
LoadBalancerArn: { Ref: LoadBalancer }
Port: 80
Protocol: 'HTTP'
DefaultActions:
-
Type: 'fixed-response'
Order: 1
FixedResponseConfig:
StatusCode: 404
ContentType: 'application/json'
MessageBody: '{ "not": "found" }'
LoadBalancerParam:
Type: "AWS::SSM::Parameter"
Properties:
Name: "/${self:service}/${self:provider.stage}/LoadBalancerUrl"
Type: "String"
Value: !GetAtt LoadBalancer.DNSName
Description: "loadbalancer url"