-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloud-formation.yaml
57 lines (52 loc) · 1.99 KB
/
cloud-formation.yaml
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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Resources:
# --------------Lambda Layer containing the Atlas binary --------------- #
AtlasLayer:
Type: AWS::Serverless::LayerVersion
Properties:
Description: Lambda layer to contain the Atlas binary for DB schema migration
ContentUri: atlas_layer
CompatibleRuntimes:
- python3.11
# --------------Schema Migration Lambda triggered by Custom Resource--------------- #
SchemaMigrationLambda:
Type: AWS::Serverless::Function
Properties:
Description: Lambda triggered by custom resource to run DB schema migrations
CodeUri: ../src/
Handler: migration_lambda.aws.lambda_handler
Runtime: python3.12
Layers:
- !Ref AtlasLayer
MemorySize: 256
Tracing: Active
AutoPublishAlias: live
Timeout: 900
Environment:
Variables:
DB_HOST: <SET VALUE>
DB_PORT: <SET VALUE>
DB_NAME: <SET VALUE>
DB_USER: <SET VALUE>
Policies:
- <ARN of policy for allowing RDS proxy connection>
VpcConfig:
SecurityGroupIds:
- <ID of security group to allow connection to DB>
SubnetIds: <List of subnet IDs that DB exists in>
# A custom resource which triggers the Lambda to run the schema migrations
MigrationTrigger:
Type: AWS::CloudFormation::CustomResource
Properties:
ServiceToken: !GetAtt SchemaMigrationLambda.Arn
# 15 minute timeout to correspond with maximum Lambda duration
ServiceTimeout: 900
# When this value changes, it will cause an update to this custom resource and therefore cause migrations to run
MigrationHash: 4M4XVqDlARAEnO10mHon8QQh4yKV5rYIHk+OGarK5Qk=
ForceUpdate: 1 # Change this value to force apply migrations, even if the migration files have not changed
LambdaLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub '/aws/lambda/${SchemaMigrationLambda}'
RetentionInDays: 30