Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
AWS Batch esempi utilizzando AWS CLI
I seguenti esempi di codice mostrano come eseguire azioni e implementare scenari comuni utilizzando AWS Command Line Interface with AWS Batch.
Le azioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le azioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.
Ogni esempio include un link al codice sorgente completo, in cui vengono fornite le istruzioni su come configurare ed eseguire il codice nel contesto.
Argomenti
Azioni
Il seguente esempio di codice mostra come usare. cancel-job
- AWS CLI
-
Come annullare un processo
Questo esempio annulla un processo con l’ID del processo specificato.
Comando:
aws batch cancel-job --job-idbcf0b186-a532-4122-842e-2ccab8d54efb--reason"Cancelling job."-
Per i dettagli sull'API, consulta CancelJob AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. create-compute-environment
- AWS CLI
-
Per creare un ambiente di elaborazione gestito con istanze On-Demand
Questo esempio crea un ambiente di calcolo gestito con istanze di tipo C4 specifiche che vengono avviate on demand. Viene chiamato l'ambiente di calcolo. C4OnDemand
Comando:
aws batch create-compute-environment --cli-input-jsonfile://<path_to_json_file>/C4OnDemand.jsonFormato del file JSON:
{ "computeEnvironmentName": "C4OnDemand", "type": "MANAGED", "state": "ENABLED", "computeResources": { "type": "EC2", "minvCpus": 0, "maxvCpus": 128, "desiredvCpus": 48, "instanceTypes": [ "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge" ], "subnets": [ "subnet-220c0e0a", "subnet-1a95556d", "subnet-978f6dce" ], "securityGroupIds": [ "sg-cf5093b2" ], "ec2KeyPair": "id_rsa", "instanceRole": "ecsInstanceRole", "tags": { "Name": "Batch Instance - C4OnDemand" } }, "serviceRole": "arn:aws:iam::012345678910:role/AWSBatchServiceRole" }Output:
{ "computeEnvironmentName": "C4OnDemand", "computeEnvironmentArn": "arn:aws:batch:us-east-1:012345678910:compute-environment/C4OnDemand" }Come creare un ambiente di calcolo gestito con istanze spot
Questo esempio crea un ambiente di calcolo gestito con il tipo di istanza M4 che viene lanciato quando il prezzo dell'offerta Spot è pari o inferiore al 20% del On-Demand prezzo del tipo di istanza. L’ambiente di calcolo è denominato M4Spot.
Comando:
aws batch create-compute-environment --cli-input-jsonfile://<path_to_json_file>/M4Spot.jsonFormato del file JSON:
{ "computeEnvironmentName": "M4Spot", "type": "MANAGED", "state": "ENABLED", "computeResources": { "type": "SPOT", "spotIamFleetRole": "arn:aws:iam::012345678910:role/aws-ec2-spot-fleet-role", "minvCpus": 0, "maxvCpus": 128, "desiredvCpus": 4, "instanceTypes": [ "m4" ], "bidPercentage": 20, "subnets": [ "subnet-220c0e0a", "subnet-1a95556d", "subnet-978f6dce" ], "securityGroupIds": [ "sg-cf5093b2" ], "ec2KeyPair": "id_rsa", "instanceRole": "ecsInstanceRole", "tags": { "Name": "Batch Instance - M4Spot" } }, "serviceRole": "arn:aws:iam::012345678910:role/AWSBatchServiceRole" }Output:
{ "computeEnvironmentName": "M4Spot", "computeEnvironmentArn": "arn:aws:batch:us-east-1:012345678910:compute-environment/M4Spot" }-
Per i dettagli sull'API, consulta AWS CLI Command CreateComputeEnvironment
Reference.
-
Il seguente esempio di codice mostra come usare. create-job-queue
- AWS CLI
-
Come creare una coda di processi a bassa priorità con un unico ambiente di calcolo
Questo esempio crea una coda di lavoro chiamata LowPriority che utilizza l'ambiente di calcolo M4Spot.
Comando:
aws batch create-job-queue --cli-input-jsonfile://<path_to_json_file>/LowPriority.jsonFormato del file JSON:
{ "jobQueueName": "LowPriority", "state": "ENABLED", "priority": 10, "computeEnvironmentOrder": [ { "order": 1, "computeEnvironment": "M4Spot" } ] }Output:
{ "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/LowPriority", "jobQueueName": "LowPriority" }Come creare una coda di processi ad alta priorità con due ambienti di calcolo
Questo esempio crea una coda di lavoro chiamata HighPriority che utilizza l'ambiente di C4OnDemand calcolo con un ordine di 1 e l'ambiente di calcolo M4Spot con un ordine di 2. Lo scheduler tenterà innanzitutto di inserire i lavori nell'ambiente di calcolo. C4OnDemand
Comando:
aws batch create-job-queue --cli-input-jsonfile://<path_to_json_file>/HighPriority.jsonFormato del file JSON:
{ "jobQueueName": "HighPriority", "state": "ENABLED", "priority": 1, "computeEnvironmentOrder": [ { "order": 1, "computeEnvironment": "C4OnDemand" }, { "order": 2, "computeEnvironment": "M4Spot" } ] }Output:
{ "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/HighPriority", "jobQueueName": "HighPriority" }-
Per i dettagli sull'API, consulta AWS CLI Command CreateJobQueue
Reference.
-
Il seguente esempio di codice mostra come usare. delete-compute-environment
- AWS CLI
-
Come eliminare un ambiente di calcolo
Questo esempio elimina l'ambiente di P2OnDemand calcolo.
Comando:
aws batch delete-compute-environment --compute-environmentP2OnDemand-
Per i dettagli sull'API, consulta AWS CLI Command DeleteComputeEnvironment
Reference.
-
Il seguente esempio di codice mostra come usare. delete-job-queue
- AWS CLI
-
Come eliminare una coda di processi
Questo esempio elimina la coda dei processi GPGPU.
Comando:
aws batch delete-job-queue --job-queueGPGPU-
Per i dettagli sull'API, consulta DeleteJobQueue AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. deregister-job-definition
- AWS CLI
-
Come annullare la registrazione di una definizione di processo
Questo esempio annulla la registrazione di una definizione di processo denominata sleep10.
Comando:
aws batch deregister-job-definition --job-definitionsleep10-
Per i dettagli sull'API, consulta DeregisterJobDefinition AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. describe-compute-environments
- AWS CLI
-
Come eliminare un ambiente di calcolo
Questo esempio descrive l'ambiente di P2OnDemand calcolo.
Comando:
aws batch describe-compute-environments --compute-environmentsP2OnDemandOutput:
{ "computeEnvironments": [ { "status": "VALID", "serviceRole": "arn:aws:iam::012345678910:role/AWSBatchServiceRole", "computeEnvironmentArn": "arn:aws:batch:us-east-1:012345678910:compute-environment/P2OnDemand", "computeResources": { "subnets": [ "subnet-220c0e0a", "subnet-1a95556d", "subnet-978f6dce" ], "tags": { "Name": "Batch Instance - P2OnDemand" }, "desiredvCpus": 48, "minvCpus": 0, "instanceTypes": [ "p2" ], "securityGroupIds": [ "sg-cf5093b2" ], "instanceRole": "ecsInstanceRole", "maxvCpus": 128, "type": "EC2", "ec2KeyPair": "id_rsa" }, "statusReason": "ComputeEnvironment Healthy", "ecsClusterArn": "arn:aws:ecs:us-east-1:012345678910:cluster/P2OnDemand_Batch_2c06f29d-d1fe-3a49-879d-42394c86effc", "state": "ENABLED", "computeEnvironmentName": "P2OnDemand", "type": "MANAGED" } ] }-
Per i dettagli sull'API, consulta DescribeComputeEnvironments AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. describe-job-definitions
- AWS CLI
-
Come descrivere le definizioni dei processi attivi
In questo esempio vengono descritte le definizioni di tutti i processi attivi.
Comando:
aws batch describe-job-definitions --statusACTIVEOutput:
{ "jobDefinitions": [ { "status": "ACTIVE", "jobDefinitionArn": "arn:aws:batch:us-east-1:012345678910:job-definition/sleep60:1", "containerProperties": { "mountPoints": [], "parameters": {}, "image": "busybox", "environment": {}, "vcpus": 1, "command": [ "sleep", "60" ], "volumes": [], "memory": 128, "ulimits": [] }, "type": "container", "jobDefinitionName": "sleep60", "revision": 1 } ] }-
Per i dettagli sull'API, consulta DescribeJobDefinitions AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. describe-job-queues
- AWS CLI
-
Come descrivere una coda di processi
Questo esempio descrive la coda dei HighPriority lavori.
Comando:
aws batch describe-job-queues --job-queuesHighPriorityOutput:
{ "jobQueues": [ { "status": "VALID", "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/HighPriority", "computeEnvironmentOrder": [ { "computeEnvironment": "arn:aws:batch:us-east-1:012345678910:compute-environment/C4OnDemand", "order": 1 } ], "statusReason": "JobQueue Healthy", "priority": 1, "state": "ENABLED", "jobQueueName": "HighPriority" } ] }-
Per i dettagli sull'API, vedere DescribeJobQueues
in AWS CLI Command Reference.
-
Il seguente esempio di codice mostra come usare. describe-jobs
- AWS CLI
-
Come descrivere un processo
L’esempio
describe-jobsseguente descrive un processo con l’ID processo specificato.aws batch describe-jobs \ --jobsbcf0b186-a532-4122-842e-2ccab8d54efbOutput:
{ "jobs": [ { "status": "SUBMITTED", "container": { "mountPoints": [], "image": "busybox", "environment": [], "vcpus": 1, "command": [ "sleep", "60" ], "volumes": [], "memory": 128, "ulimits": [] }, "parameters": {}, "jobDefinition": "arn:aws:batch:us-east-1:012345678910:job-definition/sleep60:1", "jobQueue": "arn:aws:batch:us-east-1:012345678910:job-queue/HighPriority", "jobId": "bcf0b186-a532-4122-842e-2ccab8d54efb", "dependsOn": [], "jobName": "example", "createdAt": 1480483387803 } ] }-
Per i dettagli sull'API, consulta DescribeJobs AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. list-jobs
- AWS CLI
-
Come elencare i processi in esecuzione
Questo esempio elenca i lavori in esecuzione nella coda dei HighPriority processi.
Comando:
aws batch list-jobs --job-queueHighPriorityOutput:
{ "jobSummaryList": [ { "jobName": "example", "jobId": "e66ff5fd-a1ff-4640-b1a2-0b0a142f49bb" } ] }Come elencare i processi inviati
Questo esempio elenca i lavori nella coda dei HighPriority lavori che si trovano nello stato di processo INVIATO.
Comando:
aws batch list-jobs --job-queueHighPriority--job-statusSUBMITTEDOutput:
{ "jobSummaryList": [ { "jobName": "example", "jobId": "68f0c163-fbd4-44e6-9fd1-25b14a434786" } ] }-
Per i dettagli sull'API, consulta ListJobs AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. register-job-definition
- AWS CLI
-
Come registrare una definizione di processo
Questo esempio registra una definizione di processo per un processo container semplice.
Comando:
aws batch register-job-definition --job-definition-namesleep30--typecontainer--container-properties '{ "image": "busybox", "vcpus": 1, "memory": 128, "command": [ "sleep", "30"]}'Output:
{ "jobDefinitionArn": "arn:aws:batch:us-east-1:012345678910:job-definition/sleep30:1", "jobDefinitionName": "sleep30", "revision": 1 }-
Per i dettagli sull'API, consulta RegisterJobDefinition AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. submit-job
- AWS CLI
-
Come inviare un processo
Questo esempio invia un semplice processo contenitore chiamato example alla coda dei HighPriority lavori.
Comando:
aws batch submit-job --job-nameexample--job-queueHighPriority--job-definitionsleep60Output:
{ "jobName": "example", "jobId": "876da822-4198-45f2-a252-6cea32512ea8" }-
Per i dettagli sull'API, consulta AWS CLI Command SubmitJob
Reference.
-
Il seguente esempio di codice mostra come usare. terminate-job
- AWS CLI
-
Come terminare un processo
Questo esempio termina un processo con l’ID del processo specificato.
Comando:
aws batch terminate-job --job-id61e743ed-35e4-48da-b2de-5c8333821c84--reason"Terminating job."-
Per i dettagli sull'API, consulta TerminateJob AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come usare. update-compute-environment
- AWS CLI
-
Come aggiornare un ambiente di calcolo
Questo esempio disabilita l'ambiente di P2OnDemand calcolo in modo che possa essere eliminato.
Comando:
aws batch update-compute-environment --compute-environmentP2OnDemand--stateDISABLEDOutput:
{ "computeEnvironmentName": "P2OnDemand", "computeEnvironmentArn": "arn:aws:batch:us-east-1:012345678910:compute-environment/P2OnDemand" }-
Per i dettagli sull'API, consulta AWS CLI Command UpdateComputeEnvironment
Reference.
-
Il seguente esempio di codice mostra come usare. update-job-queue
- AWS CLI
-
Come creare una coda di processi
Questo esempio disabilita una coda di processi in modo che possa essere eliminata.
Comando:
aws batch update-job-queue --job-queueGPGPU--stateDISABLEDOutput:
{ "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/GPGPU", "jobQueueName": "GPGPU" }-
Per i dettagli sull'API, consulta UpdateJobQueue AWS CLI
Command Reference.
-