registerJobDefinition

Registers an Batch job definition.

Samples

// This demonstrates calling the RegisterJobDefinition action, including tags.
val resp = batchClient.registerJobDefinition {
    jobDefinitionName = "sleep30"
    type = JobDefinitionType.fromValue("container")
    containerProperties = ContainerProperties {
        image = "busybox"
        command = listOf<String>(
            "sleep",
            "30"
        )
        resourceRequirements = listOf<ResourceRequirement>(
            ResourceRequirement {
                type = ResourceType.fromValue("MEMORY")
                value = "128"
            },
            ResourceRequirement {
                type = ResourceType.fromValue("VCPU")
                value = "1"
            }                
        )
    }
    tags = mapOf<String, String>(
        "Department" to "Engineering",
        "User" to "JaneDoe"
    )
}
// This example registers a job definition that requests GPU resources on ECS Managed Instances.
val resp = batchClient.registerJobDefinition {
    jobDefinitionName = "my-gpu-managed-instances-job-def"
    type = JobDefinitionType.fromValue("container")
    platformCapabilities = listOf<PlatformCapability>(
        PlatformCapability.fromValue("MANAGED_INSTANCES")
    )
    ecsProperties = EcsProperties {
        taskProperties = listOf<EcsTaskProperties>(
            EcsTaskProperties {
                containers = listOf<TaskContainerProperties>(
                    TaskContainerProperties {
                        image = "123456789012.dkr.ecr.us-east-1.amazonaws.com/my-gpu-image:latest"
                        name = "main"
                        command = listOf<String>(
                            "nvidia-smi"
                        )
                        resourceRequirements = listOf<ResourceRequirement>(
                            ResourceRequirement {
                                type = ResourceType.fromValue("VCPU")
                                value = "4"
                            },
                            ResourceRequirement {
                                type = ResourceType.fromValue("MEMORY")
                                value = "16384"
                            },
                            ResourceRequirement {
                                type = ResourceType.fromValue("GPU")
                                value = "1"
                            }                                
                        )
                    }                        
                )
                executionRoleArn = "arn:aws:iam::123456789012:role/ecsTaskExecutionRole"
            }                
        )
    }
}
// This example registers a job definition for a simple container job.
val resp = batchClient.registerJobDefinition {
    containerProperties = ContainerProperties {
        image = "busybox"
        command = listOf<String>(
            "sleep",
            "10"
        )
        resourceRequirements = listOf<ResourceRequirement>(
            ResourceRequirement {
                type = ResourceType.fromValue("MEMORY")
                value = "128"
            },
            ResourceRequirement {
                type = ResourceType.fromValue("VCPU")
                value = "1"
            }                
        )
    }
    type = JobDefinitionType.fromValue("container")
    jobDefinitionName = "sleep10"
}
// This example registers a job definition that runs on ECS Managed Instances using ecsProperties with
// the MANAGED_INSTANCES platform capability.
val resp = batchClient.registerJobDefinition {
    jobDefinitionName = "my-managed-instances-job-def"
    type = JobDefinitionType.fromValue("container")
    platformCapabilities = listOf<PlatformCapability>(
        PlatformCapability.fromValue("MANAGED_INSTANCES")
    )
    ecsProperties = EcsProperties {
        taskProperties = listOf<EcsTaskProperties>(
            EcsTaskProperties {
                containers = listOf<TaskContainerProperties>(
                    TaskContainerProperties {
                        image = "public.ecr.aws/amazonlinux/amazonlinux:2023"
                        name = "main"
                        command = listOf<String>(
                            "echo",
                            "hello managed instances"
                        )
                        resourceRequirements = listOf<ResourceRequirement>(
                            ResourceRequirement {
                                type = ResourceType.fromValue("VCPU")
                                value = "1"
                            },
                            ResourceRequirement {
                                type = ResourceType.fromValue("MEMORY")
                                value = "1024"
                            }                                
                        )
                    }                        
                )
                executionRoleArn = "arn:aws:iam::123456789012:role/ecsTaskExecutionRole"
            }                
        )
    }
}
// This example registers a job definition with a main container and a sidecar logging container on ECS
// Managed Instances.
val resp = batchClient.registerJobDefinition {
    jobDefinitionName = "my-sidecar-managed-instances-job-def"
    type = JobDefinitionType.fromValue("container")
    platformCapabilities = listOf<PlatformCapability>(
        PlatformCapability.fromValue("MANAGED_INSTANCES")
    )
    ecsProperties = EcsProperties {
        taskProperties = listOf<EcsTaskProperties>(
            EcsTaskProperties {
                containers = listOf<TaskContainerProperties>(
                    TaskContainerProperties {
                        image = "public.ecr.aws/amazonlinux/amazonlinux:2023"
                        name = "main"
                        command = listOf<String>(
                            "echo",
                            "processing data"
                        )
                        essential = true
                        resourceRequirements = listOf<ResourceRequirement>(
                            ResourceRequirement {
                                type = ResourceType.fromValue("VCPU")
                                value = "2"
                            },
                            ResourceRequirement {
                                type = ResourceType.fromValue("MEMORY")
                                value = "4096"
                            }                                
                        )
                    },
                    TaskContainerProperties {
                        image = "public.ecr.aws/amazonlinux/amazonlinux:2023"
                        name = "sidecar"
                        command = listOf<String>(
                            "echo",
                            "logging sidecar"
                        )
                        essential = false
                        resourceRequirements = listOf<ResourceRequirement>(
                            ResourceRequirement {
                                type = ResourceType.fromValue("VCPU")
                                value = "1"
                            },
                            ResourceRequirement {
                                type = ResourceType.fromValue("MEMORY")
                                value = "512"
                            }                                
                        )
                    }                        
                )
                executionRoleArn = "arn:aws:iam::123456789012:role/ecsTaskExecutionRole"
            }                
        )
    }
}