-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserverless.yml
175 lines (166 loc) · 5.06 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
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
170
171
172
173
174
175
service: serverless-django
plugins:
- serverless-python-requirements
- serverless-wsgi
custom:
wsgi:
app: serverless_django.wsgi.application
packRequirements: false
pythonRequirements:
dockerizePip: non-linux
AURORA:
DB_NAME: aurora${opt:stage, self:provider.stage}
USERNAME: master
PASSWORD: password
HOST:
Fn::GetAtt: [AuroraRDSCluster, Endpoint.Address]
PORT:
Fn::GetAtt: [AuroraRDSCluster, Endpoint.Port]
VPC_CIDR: 10
provider:
name: aws
runtime: python3.7
stage: dev
region: us-west-2
environment:
AURORA_HOST: ${self:custom.AURORA.HOST}
AURORA_PORT: ${self:custom.AURORA.PORT}
AURORA_DB_NAME: ${self:custom.AURORA.DB_NAME}
AURORA_USERNAME: ${self:custom.AURORA.USERNAME}
AURORA_PASSWORD: ${self:custom.AURORA.PASSWORD}
iamRoleStatements:
- Effect: "Allow"
Action:
- s3:GetObject
- s3:PutObject
Resource: "arn:aws:s3:::*"
functions:
app:
handler: wsgi.handler
vpc:
securityGroupIds:
- Fn::GetAtt: ServerlessVPC.DefaultSecurityGroup
subnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
- Ref: ServerlessSubnetC
events:
- http: ANY /
- http: 'ANY {proxy+}'
stack-deployment-function:
handler: stack_deployment_function.handler
vpc:
securityGroupIds:
- Fn::GetAtt: ServerlessVPC.DefaultSecurityGroup
subnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
- Ref: ServerlessSubnetC
description: Lambda function triggered by Stack changes/deployments
timeout: 300
environment:
FOO: bar
events:
- cloudwatchEvent:
name: ${self:service}-${opt:stage, self:provider.stage}-stack-deployment-function
description: 'Updates XYZ after CloudFormation update'
event:
source:
- "aws.cloudformation"
detail-type:
- "AWS API Call via CloudTrail"
detail:
eventName:
# Need to call DescribeStacks in Lambda to confirm successful deployment before making any changes
- "UpdateStack"
- "CreateStack"
resources:
Resources:
ServerlessVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: ${self:custom.AURORA.VPC_CIDR}.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
ServerlessSubnetA:
DependsOn: ServerlessVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: ServerlessVPC
AvailabilityZone: ${self:provider.region}a
CidrBlock: ${self:custom.AURORA.VPC_CIDR}.0.0.0/24
ServerlessSubnetB:
DependsOn: ServerlessVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: ServerlessVPC
AvailabilityZone: ${self:provider.region}b
CidrBlock: ${self:custom.AURORA.VPC_CIDR}.0.1.0/24
ServerlessSubnetC:
DependsOn: ServerlessVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: ServerlessVPC
AvailabilityZone: ${self:provider.region}c
CidrBlock: ${self:custom.AURORA.VPC_CIDR}.0.2.0/24
# Aurora DB config
AuroraSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: "Aurora Subnet Group"
SubnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
- Ref: ServerlessSubnetC
AuroraRDSClusterParameter:
Type: AWS::RDS::DBClusterParameterGroup
Properties:
Description: Parameter group for the Serverless Aurora RDS DB.
Family: aurora-postgresql10
Parameters:
application_name: 'test'
AuroraRDSInstanceParameter:
Type: AWS::RDS::DBParameterGroup
Properties:
Description: Parameter group for the Serverless Aurora RDS DB.
Family: aurora-postgresql10
Parameters:
application_name: 'test'
AuroraRDSCluster:
Type: "AWS::RDS::DBCluster"
Properties:
MasterUsername: ${self:custom.AURORA.USERNAME}
MasterUserPassword: ${self:custom.AURORA.PASSWORD}
DBSubnetGroupName:
Ref: AuroraSubnetGroup
Engine: aurora-postgresql
EngineVersion: "10.7"
# EngineMode: serverless
# ScalingConfiguration:
# AutoPause: true
# MaxCapacity: 16
# MinCapacity: 2
# SecondsUntilAutoPause: 300
DatabaseName: ${self:custom.AURORA.DB_NAME}
BackupRetentionPeriod: 3
DBClusterParameterGroupName:
Ref: AuroraRDSClusterParameter
VpcSecurityGroupIds:
- Fn::GetAtt: ServerlessVPC.DefaultSecurityGroup
AuroraRDSInstance:
Type: "AWS::RDS::DBInstance"
Properties:
DBInstanceClass: db.t3.medium
DBSubnetGroupName:
Ref: AuroraSubnetGroup
Engine: aurora-postgresql
EngineVersion: "10.7"
PubliclyAccessible: false
DBParameterGroupName:
Ref: AuroraRDSInstanceParameter
DBClusterIdentifier:
Ref: AuroraRDSCluster