Skip to content

Commit 0b0b502

Browse files
authored
Merge pull request #30 from AllenInstitute/feature/DT-8749-add-support-for-job-def-role
Add support for job_role_arn in the demand execution lambda functions
2 parents 7c37b91 + c857447 commit 0b0b502

File tree

8 files changed

+148
-132
lines changed

8 files changed

+148
-132
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ dynamic = [
1818
"version",
1919
]
2020
dependencies = [
21-
"aibs-informatics-aws-utils>=0.0.8,<1",
22-
"aibs-informatics-core>=0.2.4,<1",
21+
"aibs-informatics-aws-utils>=0.0.12,<1",
22+
"aibs-informatics-core>=0.2.6,<1",
2323
"aws-lambda-powertools ~= 2.35",
2424
"pydantic >= 2.0.3, < 3",
2525
"aws-lambda-typing",

src/aibs_informatics_aws_lambda/handlers/batch/create.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def handle(
6363
mount_points=request.mount_points,
6464
volumes=request.volumes,
6565
privileged=request.privileged,
66+
job_role_arn=request.job_role_arn,
6667
)
6768

6869
response = register_job_definition(

src/aibs_informatics_aws_lambda/handlers/batch/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class CreateDefinitionAndPrepareArgsRequest(SchemaModel):
2929
image: str = custom_field()
3030
job_definition_name: str = custom_field()
3131
job_queue_name: str = custom_field()
32+
job_role_arn: Optional[str] = custom_field(default=None)
3233
job_name: Optional[str] = custom_field(default=None)
3334
command: List[str] = custom_field(default_factory=list)
3435
environment: Dict[str, str] = custom_field(default_factory=dict)

src/aibs_informatics_aws_lambda/handlers/demand/context_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ def generate_batch_job_builder( # noqa: C901
636636
if tmp_mount_point:
637637
vol_configurations.append(BatchEFSConfiguration(tmp_mount_point, read_only=False))
638638
logger.info("Constructing BatchJobBuilder instance...")
639+
assert demand_execution.execution_platform.aws_batch is not None
639640
return BatchJobBuilder(
640641
image=demand_execution.execution_image,
641642
job_definition_name=env_base.get_job_name(
@@ -657,6 +658,9 @@ def generate_batch_job_builder( # noqa: C901
657658
env_base=env_base,
658659
# TODO: need to make this configurable
659660
privileged=True,
661+
job_role_arn=demand_execution.execution_platform.aws_batch.job_role
662+
if demand_execution.execution_platform.aws_batch
663+
else None,
660664
)
661665

662666

src/aibs_informatics_aws_lambda/handlers/demand/model.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22
from enum import Enum
3-
from typing import Any, Dict, List, Optional, Union
3+
from typing import List, Optional, Union
44

55
from aibs_informatics_core.models.aws.s3 import S3Path
66
from aibs_informatics_core.models.base import (
@@ -17,15 +17,6 @@
1717
from aibs_informatics_aws_lambda.handlers.data_sync.model import RemoveDataPathsRequest
1818

1919

20-
@dataclass
21-
class CreateDefinitionAndPrepareArgsResponse(SchemaModel):
22-
job_name: str = custom_field()
23-
job_definition_arn: Optional[str] = custom_field()
24-
job_queue_arn: str = custom_field()
25-
parameters: Dict[str, Any] = custom_field()
26-
container_overrides: Dict[str, Any] = custom_field()
27-
28-
2920
@dataclass
3021
class FileSystemConfiguration(SchemaModel):
3122
file_system: Optional[str] = None

src/aibs_informatics_aws_lambda/handlers/demand/scaffolding.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def handle(self, request: PrepareDemandScaffoldingRequest) -> PrepareDemandScaff
101101
volumes=batch_job_builder.volumes,
102102
retry_strategy=build_retry_strategy(num_retries=5),
103103
privileged=batch_job_builder.privileged,
104+
job_role_arn=batch_job_builder.job_role_arn,
104105
),
105106
)
106107

test/aibs_informatics_aws_lambda/handlers/demand/test_scaffolding.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def test__handle__simple_case(self, mock_construct_batch_efs_configuration) -> N
203203
batch_job_builder.mount_points = []
204204
batch_job_builder.volumes = []
205205
batch_job_builder.privileged = False
206+
batch_job_builder.job_role_arn = None
206207

207208
expected = PrepareDemandScaffoldingResponse(
208209
demand_execution=self.demand_execution,
@@ -299,6 +300,7 @@ def test__handle__file_system_overrides(self, mock_construct_batch_efs_configura
299300
batch_job_builder.mount_points = []
300301
batch_job_builder.volumes = []
301302
batch_job_builder.privileged = False
303+
batch_job_builder.job_role_arn = None
302304

303305
expected = PrepareDemandScaffoldingResponse(
304306
demand_execution=self.demand_execution,

uv.lock

Lines changed: 136 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)