Service Constructs¶
Complete service infrastructure including compute and storage.
service
¶
Modules¶
compute
¶
Compute service constructs for AWS Batch.
This module provides high-level constructs for creating Batch compute environments with various configurations.
Classes¶
BaseBatchComputeConstruct
¶
BaseBatchComputeConstruct(
scope: Construct,
id: str | None,
env_base: EnvBase,
vpc: Vpc,
batch_name: str,
buckets: Iterable[Bucket] | None = None,
file_systems: Iterable[FileSystem | IFileSystem]
| None = None,
mount_point_configs: Iterable[MountPointConfiguration]
| None = None,
instance_role_name: str | None = None,
instance_role_policy_statements: list[PolicyStatement]
| None = None,
**kwargs
)
Bases: EnvBaseConstruct
Base class for Batch compute constructs.
Abstract base class that provides common functionality for creating and managing AWS Batch compute environments.
Initialize a Batch compute construct.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
The construct scope. |
required |
id
|
Optional[str]
|
The construct ID. |
required |
env_base
|
EnvBase
|
Environment base for resource naming. |
required |
vpc
|
Vpc
|
VPC for the compute environments. |
required |
batch_name
|
str
|
Name for the batch infrastructure. |
required |
buckets
|
Optional[Iterable[Bucket]]
|
S3 buckets to grant access to. |
None
|
file_systems
|
Optional[Iterable[Union[FileSystem, IFileSystem]]]
|
EFS file systems to grant access to. |
None
|
mount_point_configs
|
Optional[Iterable[MountPointConfiguration]]
|
Mount point configurations for EFS. |
None
|
instance_role_name
|
Optional[str]
|
Name for the instance role. |
None
|
instance_role_policy_statements
|
Optional[List[PolicyStatement]]
|
Additional IAM policy statements. |
None
|
**kwargs
|
Additional arguments passed to parent. |
{}
|
Source code in src/aibs_informatics_cdk_lib/constructs_/service/compute.py
primary_batch_environment
abstractmethod
property
¶primary_batch_environment: BatchEnvironment
Get the primary batch environment.
Returns:
| Type | Description |
|---|---|
BatchEnvironment
|
The primary BatchEnvironment for this compute construct. |
name
property
¶Get the batch name.
Returns:
| Type | Description |
|---|---|
str
|
The batch infrastructure name. |
create_batch_environments
abstractmethod
¶Create the batch environments.
Subclasses must implement this to create their specific batch environment configurations.
Source code in src/aibs_informatics_cdk_lib/constructs_/service/compute.py
grant_storage_access
¶Grant access to storage resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*resources
|
Union[Bucket, FileSystem, IFileSystem]
|
Variable number of storage resources to grant access to. |
()
|
Source code in src/aibs_informatics_cdk_lib/constructs_/service/compute.py
BatchCompute
¶
BatchCompute(
scope: Construct,
id: str | None,
env_base: EnvBase,
vpc: Vpc,
batch_name: str,
buckets: Iterable[Bucket] | None = None,
file_systems: Iterable[FileSystem | IFileSystem]
| None = None,
mount_point_configs: Iterable[MountPointConfiguration]
| None = None,
instance_role_name: str | None = None,
instance_role_policy_statements: list[PolicyStatement]
| None = None,
**kwargs
)
Bases: BaseBatchComputeConstruct
Standard Batch compute construct with on-demand, spot, and Fargate environments.
Provides a complete Batch compute setup with three environment types: on-demand, spot, and Fargate.
Attributes:
| Name | Type | Description |
|---|---|---|
on_demand_batch_environment |
On-demand compute environment. |
|
spot_batch_environment |
Spot compute environment. |
|
fargate_batch_environment |
Fargate compute environment. |
Source code in src/aibs_informatics_cdk_lib/constructs_/service/compute.py
primary_batch_environment
property
¶primary_batch_environment: BatchEnvironment
Get the primary batch environment.
Returns:
| Type | Description |
|---|---|
BatchEnvironment
|
The on-demand batch environment. |
create_batch_environments
¶Create on-demand, spot, and Fargate batch environments.
Source code in src/aibs_informatics_cdk_lib/constructs_/service/compute.py
LambdaCompute
¶
LambdaCompute(
scope: Construct,
id: str | None,
env_base: EnvBase,
vpc: Vpc,
batch_name: str,
buckets: Iterable[Bucket] | None = None,
file_systems: Iterable[FileSystem | IFileSystem]
| None = None,
mount_point_configs: Iterable[MountPointConfiguration]
| None = None,
instance_role_name: str | None = None,
instance_role_policy_statements: list[PolicyStatement]
| None = None,
**kwargs
)
Bases: BatchCompute
Lambda-optimized Batch compute construct.
Provides Batch environments optimized for Lambda-like workloads with small, medium, and large instance type configurations.
Source code in src/aibs_informatics_cdk_lib/constructs_/service/compute.py
primary_batch_environment
property
¶primary_batch_environment: BatchEnvironment
Get the primary batch environment.
Returns:
| Type | Description |
|---|---|
BatchEnvironment
|
The main Lambda batch environment. |
create_batch_environments
¶Create Lambda-optimized batch environments.
Source code in src/aibs_informatics_cdk_lib/constructs_/service/compute.py
debug
¶
Classes¶
DebugInstanceConstruct
¶
DebugInstanceConstruct(
scope: Construct,
id: str | None,
env_base: EnvBase,
vpc: Vpc,
name: str = "DebugInstance",
efs_filesystems: list[IFileSystem | EnvBaseFileSystem]
| None = None,
instance_type: InstanceType = InstanceType("t3.medium"),
machine_image: IMachineImage | None = None,
instance_name: str | None = None,
instance_role_name: str | None = None,
instance_role_policy_statements: list[PolicyStatement]
| None = None,
**kwargs
)
Bases: EnvBaseConstruct
DebugInstanceConstruct is a CDK construct that creates an EC2 instance pre-configured for debugging and troubleshooting purposes within a given VPC. This instance is designed primarily to facilitate runtime inspection, diagnostics, and interactions with attached resources, including optional file system mounts (EFS) for scenarios such as shared storage debugging or configuration verification.
The construct provisions
- A dedicated security group for the instance.
- An IAM role with necessary policies (including AmazonSSMManagedInstanceCore and AmazonS3ReadOnlyAccess), optionally supplemented by user-specified inline policies.
- A Linux-based EC2 instance (defaulting to the latest Amazon Linux 2) with user data commands to perform system updates, install EFS utilities, and debugging tools (e.g., jq, tree).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- scope
|
Construct
|
The scope in which this construct is defined. |
required |
- id
|
Optional[str]
|
The unique identifier for the construct. |
required |
- env_base
|
EnvBase
|
The environment configuration required for the construct. |
required |
- vpc
|
Vpc
|
The VPC within which the instance is launched. |
required |
- name
|
str
|
Base name for resources. Defaults to "DebugInstance". |
required |
- efs_filesystems
|
Optional[List[Union[IFileSystem, EnvBaseFileSystem]]]
|
A list of EFS file systems to mount on the instance. If provided, each file system is mounted at a dedicated path under /mnt/efs/. |
required |
- instance_type
|
InstanceType
|
The EC2 instance type for the debug instance. Defaults to t3.medium. |
required |
- machine_image
|
Optional[IMachineImage]
|
The machine image used for the instance. Defaults to the latest Amazon Linux 2 image. |
required |
- instance_name
|
Optional[str]
|
A custom name for the EC2 instance. If not provided, a name is generated based on the base name. |
required |
- instance_role_name
|
Optional[str]
|
The name of the IAM role assigned to the instance. If not provided, a default name derived from the base name is used. |
required |
- instance_role_policy_statements
|
Optional[List[PolicyStatement]]
|
Additional IAM policy statements to attach inline to the instance role. |
required |
Usage Examples
-
Minimal usage:
instance = DebugInstanceConstruct( scope=app, id="DebugInstance", env_base=env, vpc=my_vpc ) This creates an EC2 instance with default parameters and without mounting any EFS file systems.
-
Advanced usage with custom instance details and EFS mounting:
instance = DebugInstanceConstruct( scope=app, id="CustomDebugInstance", env_base=env, vpc=my_vpc, name="CustomDebug", instance_type=ec2.InstanceType("t3.large"), instance_name="CustomDebugEC2", instance_role_policy_statements=[custom_policy_statement], efs_filesystems=[my_efs] ) This creates an EC2 instance with a custom instance type, a specified instance name, an inline policy, and mounts the provided EFS file system.
-
Using a custom machine image:
custom_image = ec2.MachineImage.from_lookup(name="MyCustomAMI") instance = DebugInstanceConstruct( scope=app, id="CustomImageInstance", env_base=env, vpc=my_vpc, machine_image=custom_image ) This example shows how to specify a custom machine image instead of using the default Amazon Linux 2 image.
Source code in src/aibs_informatics_cdk_lib/constructs_/service/debug.py
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
Functions¶
lims2_connection
¶
Classes¶
LimsConnectionConstruct
¶
LimsConnectionConstruct(
scope: Construct,
id: str | None,
env_base: EnvBase,
target_vpc: Vpc,
vpc_endpoint_service_name: str,
**kwargs
)
Bases: EnvBaseConstruct
This construct takes as input an AWS ec2.VPC and attaches a "VPC interface endpoint" that allows connections to another account/vpc with an on-prem LIMS2 connection.
vpc_endpoint_service_name should be the DNS name of the service running the LIMS2 connection and should look something like: "com.amazonaws.vpce.{region}.vpce-svc-{service_id}"
Source code in src/aibs_informatics_cdk_lib/constructs_/service/lims2_connection.py
add_lims_vpc_endpoint
¶Add a VPC endpont to our target_vpc that connects to the LIMS2 endpoint service (located in another AWS account/VPC managed by the cloud infra team).
Useful documentation: https://alleninstitute.atlassian.net/wiki/spaces/IT/pages/740360228/Accessing+LIMS2+from+AWS https://docs.aws.amazon.com/vpc/latest/privatelink/create-endpoint-service.html#connect-to-endpoint-service https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2-readme.html#vpc-endpoints
Pricing: https://aws.amazon.com/privatelink/pricing/ (see: Interface Endpoint pricing section)
Source code in src/aibs_informatics_cdk_lib/constructs_/service/lims2_connection.py
add_lims_vpc_endpoint_dns_alias
¶Add a route53 private hosted zone DNS resolver that will allow us to contact the LIMS2 VPC endpoint service using a less unwieldy DNS name.
Useful documentation: https://stackoverflow.com/a/78258885
Pricing: https://aws.amazon.com/route53/pricing/