forked from didhd/aws-gpu-ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch.tf
More file actions
79 lines (66 loc) · 1.86 KB
/
batch.tf
File metadata and controls
79 lines (66 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
resource "aws_batch_compute_environment" "example" {
compute_environment_name = "example"
type = "MANAGED"
compute_resources {
instance_type = ["g4dn.xlarge"]
max_vcpus = 16
min_vcpus = 0
desired_vcpus = 4
type = "EC2"
subnets = aws_subnet.public_subnet[*].id
security_group_ids = [
aws_security_group.ecs_tasks_sg.id,
]
instance_role = aws_iam_instance_profile.ecs_instance_profile.arn
}
service_role = aws_iam_role.aws_batch_service_role.arn
}
resource "aws_iam_role" "aws_batch_service_role" {
name = "awsBatchServiceRole"
assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = "sts:AssumeRole",
Effect = "Allow",
Principal = {
Service = "batch.amazonaws.com",
},
},
],
})
managed_policy_arns = ["arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"]
}
resource "aws_batch_job_queue" "example" {
name = "g4dn-queue"
state = "ENABLED"
priority = 1
compute_environments = [aws_batch_compute_environment.example.arn]
}
resource "aws_batch_job_definition" "example" {
name = "example"
type = "container"
container_properties = jsonencode({
command = ["sh", "-c", "nvidia-smi"],
image = "nvidia/cuda:11.0.3-base",
memory = 8192,
vcpus = 4,
resourceRequirements = [
{
type = "GPU",
value = "1"
},
],
executionRoleArn = aws_iam_role.ecs_tasks_execution_role.arn
})
}
output "submit_job_command" {
value = <<EOT
aws batch submit-job \
--job-name example-job \
--job-queue ${aws_batch_job_queue.example.name} \
--job-definition ${aws_batch_job_definition.example.name} \
--region us-east-2
EOT
description = "Use this command to submit a job to AWS Batch."
}