diff --git a/.dockerignore b/.dockerignore index a602416..8159753 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,3 +10,4 @@ venv .git .envs/ +rds_redis_ec2_config.yml diff --git a/rds_redis_ec2_config.yml b/rds_redis_ec2_config.yml new file mode 100644 index 0000000..d8135b1 --- /dev/null +++ b/rds_redis_ec2_config.yml @@ -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 + diff --git a/yeastregulatorydb/regulatory_data/api/views/CallingCardsBackgroundViewSet.py b/yeastregulatorydb/regulatory_data/api/views/CallingCardsBackgroundViewSet.py index ed2525f..4465df9 100644 --- a/yeastregulatorydb/regulatory_data/api/views/CallingCardsBackgroundViewSet.py +++ b/yeastregulatorydb/regulatory_data/api/views/CallingCardsBackgroundViewSet.py @@ -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 diff --git a/yeastregulatorydb/regulatory_data/api/views/ChrMapViewSet.py b/yeastregulatorydb/regulatory_data/api/views/ChrMapViewSet.py index 9e5427c..1538b39 100644 --- a/yeastregulatorydb/regulatory_data/api/views/ChrMapViewSet.py +++ b/yeastregulatorydb/regulatory_data/api/views/ChrMapViewSet.py @@ -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 diff --git a/yeastregulatorydb/regulatory_data/api/views/DataSourceViewSet.py b/yeastregulatorydb/regulatory_data/api/views/DataSourceViewSet.py index 18e8a97..0c916d7 100644 --- a/yeastregulatorydb/regulatory_data/api/views/DataSourceViewSet.py +++ b/yeastregulatorydb/regulatory_data/api/views/DataSourceViewSet.py @@ -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 diff --git a/yeastregulatorydb/regulatory_data/api/views/ExpressionManualQCViewSet.py b/yeastregulatorydb/regulatory_data/api/views/ExpressionManualQCViewSet.py index babb7c7..18c76cb 100644 --- a/yeastregulatorydb/regulatory_data/api/views/ExpressionManualQCViewSet.py +++ b/yeastregulatorydb/regulatory_data/api/views/ExpressionManualQCViewSet.py @@ -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 diff --git a/yeastregulatorydb/regulatory_data/api/views/ExpressionViewSet.py b/yeastregulatorydb/regulatory_data/api/views/ExpressionViewSet.py index 0b3ab04..3498930 100644 --- a/yeastregulatorydb/regulatory_data/api/views/ExpressionViewSet.py +++ b/yeastregulatorydb/regulatory_data/api/views/ExpressionViewSet.py @@ -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 diff --git a/yeastregulatorydb/regulatory_data/api/views/FileFormatViewSet.py b/yeastregulatorydb/regulatory_data/api/views/FileFormatViewSet.py index a354e1c..1ff7789 100644 --- a/yeastregulatorydb/regulatory_data/api/views/FileFormatViewSet.py +++ b/yeastregulatorydb/regulatory_data/api/views/FileFormatViewSet.py @@ -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 diff --git a/yeastregulatorydb/regulatory_data/api/views/PromoterSetViewSet.py b/yeastregulatorydb/regulatory_data/api/views/PromoterSetViewSet.py index cc27c55..ac9c5d0 100644 --- a/yeastregulatorydb/regulatory_data/api/views/PromoterSetViewSet.py +++ b/yeastregulatorydb/regulatory_data/api/views/PromoterSetViewSet.py @@ -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 diff --git a/yeastregulatorydb/regulatory_data/api/views/RegulatorViewSet.py b/yeastregulatorydb/regulatory_data/api/views/RegulatorViewSet.py index d899c3a..c824961 100644 --- a/yeastregulatorydb/regulatory_data/api/views/RegulatorViewSet.py +++ b/yeastregulatorydb/regulatory_data/api/views/RegulatorViewSet.py @@ -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