Skip to content

Commit 86a03f9

Browse files
committed
Add Batch
1 parent fb64388 commit 86a03f9

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

barrel/barrel_stack.py

+58-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,65 @@
1-
from aws_cdk import (
2-
# Duration,
3-
Stack,
4-
# aws_sqs as sqs,
5-
)
1+
import aws_cdk as cdk
2+
import aws_cdk.aws_ec2 as ec2
3+
import aws_cdk.aws_ecs as ecs
4+
5+
import aws_cdk.aws_batch_alpha as batch
6+
67
from constructs import Construct
78

8-
class BarrelStack(Stack):
99

10+
class BarrelStack(cdk.Stack):
1011
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
1112
super().__init__(scope, construct_id, **kwargs)
1213

13-
# The code that defines your stack goes here
14+
vpc = ec2.Vpc(
15+
self,
16+
"Vpc",
17+
max_azs=1,
18+
subnet_configuration=[
19+
ec2.SubnetConfiguration(
20+
name="Subnet", subnet_type=ec2.SubnetType.PUBLIC
21+
),
22+
],
23+
)
24+
25+
compute_environment = batch.ManagedEc2EcsComputeEnvironment(
26+
self,
27+
"ComputeEnvironment",
28+
vpc=vpc,
29+
instance_classes=[
30+
ec2.InstanceClass.C6A,
31+
ec2.InstanceClass.M6A,
32+
ec2.InstanceClass.R6A,
33+
],
34+
maxv_cpus=768,
35+
)
36+
37+
job_queue = batch.JobQueue(
38+
self,
39+
"JobQueue",
40+
compute_environments=[
41+
batch.OrderedComputeEnvironment(
42+
compute_environment=compute_environment, order=1
43+
),
44+
],
45+
)
46+
47+
worker = batch.EcsJobDefinition(
48+
self,
49+
"Worker",
50+
container=batch.EcsEc2ContainerDefinition(
51+
self,
52+
"WorkerContainer",
53+
image=ecs.ContainerImage.from_registry(
54+
"python:latest",
55+
),
56+
cpu=1,
57+
memory=cdk.Size.mebibytes(512),
58+
),
59+
)
1460

15-
# example resource
16-
# queue = sqs.Queue(
17-
# self, "BarrelQueue",
18-
# visibility_timeout=Duration.seconds(300),
19-
# )
61+
cdk.CfnOutput(
62+
self,
63+
"SubmitJobCommand",
64+
value=f"aws batch submit-job --job-name barrel --job-queue {job_queue.job_queue_arn} --job-definition {worker.job_definition_arn}",
65+
)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
aws-cdk-lib==2.92.0
2+
aws-cdk.aws-batch-alpha==2.92.0a0
23
constructs>=10.0.0,<11.0.0

0 commit comments

Comments
 (0)