Há mais AWS SDK exemplos disponíveis no GitHub repositório AWS Doc SDK Examples
As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Use RegisterJobDefinition
com um AWS SDK ou CLI
Os exemplos de código a seguir mostram como usar o RegisterJobDefinition
.
Exemplos de ações são trechos de código de programas maiores e devem ser executados em contexto. É possível ver essa ação no contexto no seguinte exemplo de código:
- CLI
-
- AWS CLI
-
Para registrar uma definição de cargo
Este exemplo registra uma definição de tarefa para uma tarefa de contêiner simples.
Comando:
aws batch register-job-definition --job-definition-name
sleep30
--typecontainer
--container-properties '{ "image": "busybox", "vcpus": 1, "memory": 128, "command": [ "sleep", "30"]}
'Saída:
{ "jobDefinitionArn": "arn:aws:batch:us-east-1:012345678910:job-definition/sleep30:1", "jobDefinitionName": "sleep30", "revision": 1 }
-
Para API obter detalhes, consulte RegisterJobDefinition
na Referência de AWS CLI Comandos.
-
- Java
-
- SDKpara Java 2.x
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no Repositório de exemplos de código da AWS
. /** * Registers a new job definition asynchronously in AWS Batch. * <p> * When using Fargate as the compute environment, it is crucial to set the * {@link NetworkConfiguration} with {@link AssignPublicIp#ENABLED} to * ensure proper networking configuration for the Fargate tasks. This * allows the tasks to communicate with external services, access the * internet, or communicate within a VPC. * * @param jobDefinitionName the name of the job definition to be registered * @param executionRoleARN the ARN (Amazon Resource Name) of the execution role * that provides permissions for the containers in the job * @param cpuArch a value of either X86_64 or ARM64 required for the service call * @return a CompletableFuture that completes with the ARN of the registered * job definition upon successful execution, or completes exceptionally with * an error if the registration fails */ public CompletableFuture<String> registerJobDefinitionAsync(String jobDefinitionName, String executionRoleARN, String image, String cpuArch) { NetworkConfiguration networkConfiguration = NetworkConfiguration.builder() .assignPublicIp(AssignPublicIp.ENABLED) .build(); ContainerProperties containerProperties = ContainerProperties.builder() .image(image) .executionRoleArn(executionRoleARN) .resourceRequirements( Arrays.asList( ResourceRequirement.builder() .type(ResourceType.VCPU) .value("1") .build(), ResourceRequirement.builder() .type(ResourceType.MEMORY) .value("2048") .build() ) ) .networkConfiguration(networkConfiguration) .runtimePlatform(b -> b .cpuArchitecture(cpuArch) .operatingSystemFamily("LINUX")) .build(); RegisterJobDefinitionRequest request = RegisterJobDefinitionRequest.builder() .jobDefinitionName(jobDefinitionName) .type(JobDefinitionType.CONTAINER) .containerProperties(containerProperties) .platformCapabilities(PlatformCapability.FARGATE) .build(); CompletableFuture<String> future = new CompletableFuture<>(); getAsyncClient().registerJobDefinition(request) .thenApply(RegisterJobDefinitionResponse::jobDefinitionArn) .whenComplete((result, ex) -> { if (ex != null) { future.completeExceptionally(ex); } else { future.complete(result); } }); return future; }
-
Para API obter detalhes, consulte RegisterJobDefinitionem AWS SDK for Java 2.x APIReferência.
-