-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from hallieswan/AG-1591_AG-1592
AG-1591, AG-1592, IT-4241: don't deploy unused containers, create DocumentDB cluster, allow connection from API container
- Loading branch information
Showing
8 changed files
with
190 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* @Sage-Bionetworks-IT/sagebio-it @Sage-Bionetworks-IT/infra-oversight-committee @Sage-Bionetworks-IT/agora-admin | ||
* @Sage-Bionetworks-IT/infra-oversight-committee @Sage-Bionetworks-IT/agora-admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
aws-cdk-lib~=2.139 | ||
aws-cdk-lib~=2.176 | ||
constructs~=10.0 | ||
boto3~=1.34 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from aws_cdk import aws_ec2 as ec2 | ||
|
||
|
||
class DocdbProps: | ||
""" | ||
DocumentDB properties | ||
instance_type: What type of instance to start for the replicas | ||
master_username: The database admin account username | ||
port: The MongoDB port | ||
""" | ||
|
||
def __init__( | ||
self, instance_type: ec2.InstanceType, master_username: str, port: int | ||
) -> None: | ||
self.instance_type = instance_type | ||
self.master_username = master_username | ||
self.port = port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import aws_cdk as cdk | ||
from aws_cdk import ( | ||
aws_docdb as docdb, | ||
aws_ec2 as ec2, | ||
aws_secretsmanager as sm, | ||
) | ||
from src.docdb_props import DocdbProps | ||
|
||
from constructs import Construct | ||
|
||
|
||
class DocdbStack(cdk.Stack): | ||
""" | ||
DocumentDB cluster | ||
""" | ||
|
||
def __init__( | ||
self, | ||
scope: Construct, | ||
construct_id: str, | ||
vpc: ec2.Vpc, | ||
props: DocdbProps, | ||
**kwargs, | ||
) -> None: | ||
super().__init__(scope, construct_id, **kwargs) | ||
|
||
self.master_password_secret = sm.Secret( | ||
self, | ||
"DocDbMasterPassword", | ||
generate_secret_string=sm.SecretStringGenerator( | ||
password_length=32, exclude_punctuation=True | ||
), | ||
) | ||
|
||
cluster_parameter_group = docdb.ClusterParameterGroup( | ||
self, | ||
"DocDbClusterParameterGroup", | ||
family="docdb5.0", | ||
parameters={ | ||
"audit_logs": "disabled", | ||
"profiler": "enabled", | ||
"profiler_sampling_rate": "1.0", | ||
"profiler_threshold_ms": "50", | ||
"change_stream_log_retention_duration": "10800", | ||
"tls": "disabled", | ||
"ttl_monitor": "disabled", | ||
}, | ||
) | ||
|
||
# https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_docdb/DatabaseCluster.html | ||
self.cluster = docdb.DatabaseCluster( | ||
self, | ||
"DocDbCluster", | ||
master_user=docdb.Login( | ||
username=props.master_username, | ||
password=self.master_password_secret.secret_value, | ||
), | ||
instance_type=props.instance_type, | ||
vpc=vpc, | ||
vpc_subnets=ec2.SubnetSelection( | ||
subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS | ||
), | ||
parameter_group=cluster_parameter_group, | ||
removal_policy=cdk.RemovalPolicy.DESTROY, | ||
storage_encrypted=True, | ||
preferred_maintenance_window="sat:06:54-sat:07:24", | ||
port=props.port, | ||
export_profiler_logs_to_cloud_watch=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import aws_cdk as cdk | ||
from aws_cdk import aws_ec2 as ec2, assertions as assertions | ||
|
||
from src.network_stack import NetworkStack | ||
from src.docdb_stack import DocdbStack | ||
from src.docdb_props import DocdbProps | ||
|
||
|
||
def test_docdb_created(): | ||
cdk_app = cdk.App() | ||
master_username = "myuser" | ||
port = 27017 | ||
vpc_cidr = "10.254.192.0/24" | ||
network_stack = NetworkStack(cdk_app, "NetworkStack", vpc_cidr=vpc_cidr) | ||
|
||
docdb_props = DocdbProps( | ||
instance_type=ec2.InstanceType.of( | ||
ec2.InstanceClass.MEMORY5, ec2.InstanceSize.LARGE | ||
), | ||
master_username=master_username, | ||
port=port, | ||
) | ||
docdb_stack = DocdbStack( | ||
scope=cdk_app, | ||
construct_id="docdb", | ||
vpc=network_stack.vpc, | ||
props=docdb_props, | ||
) | ||
|
||
template = assertions.Template.from_stack(docdb_stack) | ||
template.has_resource_properties( | ||
"AWS::DocDB::DBClusterParameterGroup", | ||
{ | ||
"Parameters": { | ||
"audit_logs": "disabled", | ||
"profiler": "enabled", | ||
"profiler_sampling_rate": "1.0", | ||
"profiler_threshold_ms": "50", | ||
"change_stream_log_retention_duration": "10800", | ||
"tls": "disabled", | ||
"ttl_monitor": "disabled", | ||
} | ||
}, | ||
) | ||
template.has_resource_properties( | ||
"AWS::DocDB::DBCluster", | ||
{ | ||
"MasterUsername": master_username, | ||
"MasterUserPassword": assertions.Match.any_value(), | ||
"DBSubnetGroupName": assertions.Match.any_value(), | ||
"DBClusterParameterGroupName": assertions.Match.any_value(), | ||
"StorageEncrypted": True, | ||
"PreferredMaintenanceWindow": "sat:06:54-sat:07:24", | ||
"Port": port, | ||
"EnableCloudwatchLogsExports": ["profiler"], | ||
"VpcSecurityGroupIds": [ | ||
assertions.Match.any_value(), | ||
], | ||
}, | ||
) | ||
template.resource_properties_count_is( | ||
"AWS::EC2::SecurityGroup", assertions.Match.any_value(), 1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters