-
Notifications
You must be signed in to change notification settings - Fork 3
/
postgres.yaml
99 lines (86 loc) · 2.8 KB
/
postgres.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
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
AWSTemplateFormatVersion: '2010-09-09'
Description: >
Postgres Cluster Creator
Creates Smallest Postgres Auora Cluster with 1 serverless node
Allow Public access and let RDS call any Lambda Function
Parameters:
DBNAMEPARAM:
Description: The DB Name
Type: String
DBUSERPARAM:
Description: The DB User Name
Type: String
Resources:
VPCStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: vpc.yaml
TimeoutInMinutes: '60'
DBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: !Sub ${AWS::StackName} DB Subnet group
SubnetIds:
- !GetAtt VPCStack.Outputs.PublicSubnet1
- !GetAtt VPCStack.Outputs.PublicSubnet2
Tags:
- Key: Name
Value: !Sub ${AWS::StackName} DB Subnet group
RDSSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Sub ${AWS::StackName} DB Security Group
VpcId: !GetAtt VPCStack.Outputs.VPC
SecurityGroupIngress: # Allow all Postgres Traffic in from anywhere
- IpProtocol: tcp
FromPort: 5432
ToPort: 5432
CidrIp: 0.0.0.0/0
RDSLambdaRole:
Type: AWS::IAM::Role
Properties:
Description: Allow RDS to call Lambda Functions
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- rds.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaRole
ServerlessV2Cluster:
Type: 'AWS::RDS::DBCluster'
DeletionPolicy: Delete
Properties:
Engine: aurora-postgresql
Port: 5432
EngineVersion: '15.8'
DatabaseName: !Ref DBNAMEPARAM
ManageMasterUserPassword: true
MasterUsername: !Ref DBUSERPARAM
DBSubnetGroupName: !Ref DBSubnetGroup
VpcSecurityGroupIds:
- !Ref RDSSecurityGroup
ServerlessV2ScalingConfiguration:
MinCapacity: 0.5
MaxCapacity: 1.0
AssociatedRoles:
- FeatureName: Lambda
RoleArn: !GetAtt RDSLambdaRole.Arn
ServerlessInstance:
Type: AWS::RDS::DBInstance
Properties:
Engine: aurora-postgresql
DBClusterIdentifier: !Ref ServerlessV2Cluster
DBInstanceClass: db.serverless
PubliclyAccessible: true
Outputs:
SecretArn:
Description: The Managed Secret ARN
Value: !GetAtt ServerlessV2Cluster.MasterUserSecret.SecretArn
Endpoint:
Description: The Endpoint for the DB Cluster
Value: !GetAtt ServerlessV2Cluster.Endpoint.Address