Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wq
  • Loading branch information
Ubuntu committed Feb 5, 2024
2 parents 850c2c7 + 0d4a730 commit 2281032
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 8 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
venv
.git
.envs/
rds_redis_ec2_config.yml
153 changes: 153 additions & 0 deletions rds_redis_ec2_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template for PostgreSQL RDS, Redis ElastiCache, and Ubuntu EC2 instance.

Resources:
MyCustomParameterGroup:
Type: AWS::RDS::DBParameterGroup
Properties:
Description: Custom parameter group for my DB
Family: postgres13 # Adjust based on your PostgreSQL version
Parameters:
max_connections: "200" # Example: Increase max connections

MyDBInstance:
Type: AWS::RDS::DBInstance
DependsOn:
- MyDBSecurityGroup
Properties:
DBName: mydatabase
AllocatedStorage: 20
DBInstanceClass: db.t3.micro
Engine: postgres
MasterUsername: postgres
MasterUserPassword: Jex19UIFCmM2u6ZhRKZd
BackupRetentionPeriod: 3
VPCSecurityGroups:
- !Ref MyDBSecurityGroup
DBParameterGroupName: !Ref MyCustomParameterGroup # Associate the custom parameter group

MyDBProxy:
Type: AWS::RDS::DBProxy
Properties:
DBProxyName: mydbproxy
EngineFamily: POSTGRESQL
Auth:
- AuthScheme: SECRETS
IAMAuth: DISABLED
SecretArn: !GetAtt MyDBSecret.Arn
RoleArn: !GetAtt MyDBProxyRole.Arn
VpcSecurityGroupIds:
- !Ref MyDBSecurityGroup
VpcSubnetIds:
- !Ref MySubnet1
- !Ref MySubnet2
RequireTLS: false

MyDBProxyRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: rds.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: RDSProxyPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
- secretsmanager:DescribeSecret
Resource: '*'

MyDBSecret:
Type: AWS::SecretsManager::Secret
Properties:
Name: MyDBSecret
Description: "RDS database credentials"
SecretString: !Sub '{"username":"${MyDBInstance.MasterUsername}","password":"Jex19UIFCmM2u6ZhRKZd","engine":"postgres","host":"${MyDBInstance.Endpoint.Address}","port":"5432","dbClusterIdentifier":"${MyDBInstance.DBInstanceIdentifier}"}'


MyElastiCacheRedis:
Type: AWS::ElastiCache::CacheCluster
DependsOn:
- MyCacheSecurityGroup
Properties:
CacheNodeType: cache.t2.micro
Engine: redis
NumCacheNodes: 1
VpcSecurityGroupIds:
- !Ref MyCacheSecurityGroup

MyEC2Instance:
Type: AWS::EC2::Instance
DependsOn:
- MyInstanceSecurityGroup
Properties:
ImageId: ami-05fb0b8c1424f266b
InstanceType: t2.micro
SecurityGroupIds:
- !GetAtt MyInstanceSecurityGroup.GroupId
KeyName: general_strides

MyDBSecurityGroup:
Type: AWS::EC2::SecurityGroup
DependsOn:
- MyInstanceSecurityGroup
Properties:
GroupDescription: Allow access to PostgreSQL
VpcId: vpc-0e2c306eb7a371817
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 5432
ToPort: 5432
SourceSecurityGroupId: !Ref MyInstanceSecurityGroup

MyCacheSecurityGroup:
Type: AWS::EC2::SecurityGroup
DependsOn: MyInstanceSecurityGroup
Properties:
GroupDescription: Allow access to Redis
VpcId: vpc-0e2c306eb7a371817
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 6379
ToPort: 6379
SourceSecurityGroupId: !Ref MyInstanceSecurityGroup

MyInstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for EC2 instance
VpcId: vpc-0e2c306eb7a371817
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 107.200.64.20/32
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0

Outputs:
RDSInstanceEndpoint:
Description: Endpoint of the RDS instance
Value: !GetAtt MyDBInstance.Endpoint.Address

RDSProxyEndpoint:
Description: Endpoint of the RDS Proxy
Value: !GetAtt MyDBProxy.Endpoint

RedisEndpoint:
Description: Endpoint of the Redis ElastiCache instance
Value: !GetAtt MyElastiCacheRedis.RedisEndpoint.Address

EC2InstancePublicIP:
Description: Public IP of the EC2 instance
Value: !GetAtt MyEC2Instance.PublicIp

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CallingCardsBackgroundViewSet(UpdateModifiedMixin, viewsets.ModelViewSet):
A viewset for viewing and editing CallingCardsBackground instances.
"""

queryset = CallingCardsBackground.objects.select_related("uploader", "fileformat").all()
queryset = CallingCardsBackground.objects.select_related("uploader", "fileformat").all().order_by("-id")
authentication_classes = [SessionAuthentication, TokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = CallingCardsBackgroundSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ChrMapViewSet(UpdateModifiedMixin, viewsets.ModelViewSet):
A viewset for viewing and editing ChrMap instances.
"""

queryset = ChrMap.objects.select_related("uploader").all()
queryset = ChrMap.objects.select_related("uploader").all().order_by("id")
authentication_classes = [SessionAuthentication, TokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = ChrMapSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DataSourceViewSet(UpdateModifiedMixin, ExportTableAsGzipFileMixin, viewset
A viewset for viewing and editing DataSource instances.
"""

queryset = DataSource.objects.select_related("uploader", "fileformat").all()
queryset = DataSource.objects.select_related("uploader", "fileformat").all().order_by("id")
authentication_classes = [SessionAuthentication, TokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = DataSourceSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ExpressionManualQCViewSet(UpdateModifiedMixin, viewsets.ModelViewSet):
"expression__regulator__genomicfeature",
"expression__source",
"expression__source__fileformat",
).all()
).all().order_by("-id")
authentication_classes = [SessionAuthentication, TokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = ExpressionManualQCSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ExpressionViewSet(

queryset = Expression.objects.select_related(
"uploader", "regulator", "regulator__genomicfeature", "source", "source__fileformat"
).all()
).all().order_by("-id")
authentication_classes = [SessionAuthentication, TokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = ExpressionSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FileFormatViewSet(UpdateModifiedMixin, ExportTableAsGzipFileMixin, viewset
A viewset for viewing and editing FileFormat instances.
"""

queryset = FileFormat.objects.select_related("uploader").all()
queryset = FileFormat.objects.select_related("uploader").all().order_by("id")
authentication_classes = [SessionAuthentication, TokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = FileFormatSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PromoterSetViewSet(UpdateModifiedMixin, viewsets.ModelViewSet):
A viewset for viewing and editing PromoterSet instances.
"""

queryset = PromoterSet.objects.select_related("uploader").all()
queryset = PromoterSet.objects.select_related("uploader").all().order_by("id")
authentication_classes = [SessionAuthentication, TokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = PromoterSetSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RegulatorViewSet(UpdateModifiedMixin, ExportTableAsGzipFileMixin, viewsets
A viewset for viewing and editing Regulator instances.
"""

queryset = Regulator.objects.annotated().all()
queryset = Regulator.objects.annotated().all().order_by("id")
authentication_classes = [SessionAuthentication, TokenAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = RegulatorSerializer
Expand Down

0 comments on commit 2281032

Please sign in to comment.