-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path3-postgres.yaml
More file actions
109 lines (102 loc) · 2.78 KB
/
3-postgres.yaml
File metadata and controls
109 lines (102 loc) · 2.78 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
AWSTemplateFormatVersion: '2010-09-09'
Description: Create flyway-awslambda function.
# Example demonstrating flyway-awslambda for PostgreSQL using Lambda layers
#
# Assumes the following S3 bucket structure:
# s3://MigrationBucket
# |____ /my-application
# | |____ flyway.conf
# | |____ V1__migrationv1.sql
# |____ flyway-awslambda.jar
# |____ postgres-driver.zip
# |____ java
# |____ lib
# |____ postgresql-42.2.6.jre7.jar
#
Parameters:
JdbcUrl:
Type: String
SubnetA:
Type: AWS::EC2::Subnet::Id
SubnetB:
Type: AWS::EC2::Subnet::Id
SubnetC:
Type: AWS::EC2::Subnet::Id
MigrationBucket:
Type: String
SecurityGroupId:
Type: String
Resources:
PostgresLambdaLayer:
Type: AWS::Lambda::LayerVersion
Properties:
LayerName: postgres-jdbc-driver
CompatibleRuntimes:
- java8
Description: Postgres JDBC drivers
Content:
S3Bucket:
Ref: MigrationBucket
S3Key: postgres-driver.zip
PostgresMigrationLambda:
Type : AWS::Lambda::Function
Properties:
FunctionName: flyway-awslambda
Description: Performs a Flyway migration on a given RDS database. Pulls migration files from S3
Code:
S3Bucket:
Ref: MigrationBucket
S3Key: flyway-awslambda.jar
Layers:
- Ref: PostgresLambdaLayer
Handler: crossroad0201.aws.flywaylambda.InvokeMigrationHandler::handleRequest
Role:
Fn::GetAtt:
- MigrationRole
- Arn
Runtime: java8
MemorySize: 512
Timeout: 30
VpcConfig:
SecurityGroupIds:
- Ref: SecurityGroupId
SubnetIds:
- Ref: SubnetA
- Ref: SubnetB
- Ref: SubnetC
MigrationRole:
Type: AWS::IAM::Role
Properties:
RoleName: flyway-awslambda
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- sts:AssumeRole
Principal:
Service:
- lambda.amazonaws.com
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3FullAccess
- arn:aws:iam::aws:policy/AmazonRDSFullAccess
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
AWSLambdaBasicExecutionPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: AWSLambdaBasicExecutionPolicyFlywayLambda
Roles:
- Ref: MigrationRole
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: logs:CreateLogGroup
Resource: arn:aws:logs:REGION:XXX:*
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- arn:aws:logs:REGION:XXX:log-group:/aws/lambda/flyway-awslambda:*