

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# AWS Batch contoh menggunakan AWS CLI
<a name="cli_batch_code_examples"></a>

Contoh kode berikut menunjukkan cara melakukan tindakan dan mengimplementasikan skenario umum dengan menggunakan AWS Command Line Interface with AWS Batch.

*Tindakan* merupakan kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.

Setiap contoh menyertakan tautan ke kode sumber lengkap, di mana Anda dapat menemukan instruksi tentang cara mengatur dan menjalankan kode dalam konteks.

**Topics**
+ [Tindakan](#actions)

## Tindakan
<a name="actions"></a>

### `cancel-job`
<a name="batch_CancelJob_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`cancel-job`.

**AWS CLI**  
**Untuk membatalkan pekerjaan**  
Contoh ini membatalkan pekerjaan dengan ID pekerjaan yang ditentukan.  
Perintah:  

```
aws batch cancel-job --job-id bcf0b186-a532-4122-842e-2ccab8d54efb --reason "Cancelling job."
```
+  Untuk detail API, lihat [CancelJob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/cancel-job.html)di *Referensi AWS CLI Perintah*. 

### `create-compute-environment`
<a name="batch_CreateComputeEnvironment_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`create-compute-environment`.

**AWS CLI**  
**Untuk membuat lingkungan komputasi terkelola dengan instans On-Demand**  
Contoh ini menciptakan lingkungan komputasi terkelola dengan jenis instans C4 tertentu yang diluncurkan sesuai permintaan. Lingkungan komputasi disebut OnDemand C4.  
Perintah:  

```
aws batch create-compute-environment --cli-input-json file://<path_to_json_file>/C4OnDemand.json
```
Format 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"
}
```
**Untuk membuat lingkungan komputasi terkelola dengan Instans Spot**  
Contoh ini menciptakan lingkungan komputasi terkelola dengan tipe instans M4 yang diluncurkan saat harga tawaran Spot berada pada atau di bawah 20% dari harga Sesuai Permintaan untuk jenis instans. Lingkungan komputasi disebut M4Spot.  
Perintah:  

```
aws batch create-compute-environment --cli-input-json file://<path_to_json_file>/M4Spot.json
```
Format 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"
}
```
+  Untuk detail API, lihat [CreateComputeEnvironment](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/create-compute-environment.html)di *Referensi AWS CLI Perintah*. 

### `create-job-queue`
<a name="batch_CreateJobQueue_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`create-job-queue`.

**AWS CLI**  
**Untuk membuat antrian pekerjaan prioritas rendah dengan satu lingkungan komputasi**  
Contoh ini membuat antrian pekerjaan yang disebut LowPriority yang menggunakan lingkungan komputasi M4Spot.  
Perintah:  

```
aws batch create-job-queue --cli-input-json file://<path_to_json_file>/LowPriority.json
```
Format 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"
}
```
**Untuk membuat antrian pekerjaan prioritas tinggi dengan dua lingkungan komputasi**  
Contoh ini membuat antrian pekerjaan HighPriority yang disebut yang menggunakan lingkungan OnDemand komputasi C4 dengan urutan 1 dan lingkungan komputasi M4Spot dengan urutan 2. Penjadwal akan mencoba menempatkan pekerjaan di lingkungan OnDemand komputasi C4 terlebih dahulu.  
Perintah:  

```
aws batch create-job-queue --cli-input-json file://<path_to_json_file>/HighPriority.json
```
Format 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"
}
```
+  Untuk detail API, lihat [CreateJobQueue](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/create-job-queue.html)di *Referensi AWS CLI Perintah*. 

### `delete-compute-environment`
<a name="batch_DeleteComputeEnvironment_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`delete-compute-environment`.

**AWS CLI**  
**Untuk menghapus lingkungan komputasi**  
Contoh ini menghapus lingkungan OnDemand komputasi P2.  
Perintah:  

```
aws batch delete-compute-environment --compute-environment P2OnDemand
```
+  Untuk detail API, lihat [DeleteComputeEnvironment](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/delete-compute-environment.html)di *Referensi AWS CLI Perintah*. 

### `delete-job-queue`
<a name="batch_DeleteJobQueue_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`delete-job-queue`.

**AWS CLI**  
**Untuk menghapus antrian pekerjaan**  
Contoh ini menghapus antrian pekerjaan GPGPU.  
Perintah:  

```
aws batch delete-job-queue --job-queue GPGPU
```
+  Untuk detail API, lihat [DeleteJobQueue](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/delete-job-queue.html)di *Referensi AWS CLI Perintah*. 

### `deregister-job-definition`
<a name="batch_DeregisterJobDefinition_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`deregister-job-definition`.

**AWS CLI**  
**Untuk membatalkan pendaftaran definisi pekerjaan**  
Contoh ini membatalkan pendaftaran definisi pekerjaan yang disebut sleep10.  
Perintah:  

```
aws batch deregister-job-definition --job-definition sleep10
```
+  Untuk detail API, lihat [DeregisterJobDefinition](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/deregister-job-definition.html)di *Referensi AWS CLI Perintah*. 

### `describe-compute-environments`
<a name="batch_DescribeComputeEnvironments_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`describe-compute-environments`.

**AWS CLI**  
**Untuk menggambarkan lingkungan komputasi**  
Contoh ini menjelaskan lingkungan OnDemand komputasi P2.  
Perintah:  

```
aws batch describe-compute-environments --compute-environments P2OnDemand
```
Output:  

```
{
    "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"
        }
    ]
}
```
+  Untuk detail API, lihat [DescribeComputeEnvironments](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/describe-compute-environments.html)di *Referensi AWS CLI Perintah*. 

### `describe-job-definitions`
<a name="batch_DescribeJobDefinitions_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`describe-job-definitions`.

**AWS CLI**  
**Untuk menggambarkan definisi pekerjaan aktif**  
Contoh ini menjelaskan semua definisi pekerjaan aktif Anda.  
Perintah:  

```
aws batch describe-job-definitions --status ACTIVE
```
Output:  

```
{
    "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
        }
    ]
}
```
+  Untuk detail API, lihat [DescribeJobDefinitions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/describe-job-definitions.html)di *Referensi AWS CLI Perintah*. 

### `describe-job-queues`
<a name="batch_DescribeJobQueues_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`describe-job-queues`.

**AWS CLI**  
**Untuk menggambarkan antrian pekerjaan**  
Contoh ini menjelaskan antrian HighPriority pekerjaan.  
Perintah:  

```
aws batch describe-job-queues --job-queues HighPriority
```
Output:  

```
{
    "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"
        }
    ]
}
```
+  Untuk detail API, lihat [DescribeJobQueues](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/describe-job-queues.html)di *Referensi AWS CLI Perintah*. 

### `describe-jobs`
<a name="batch_DescribeJobs_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`describe-jobs`.

**AWS CLI**  
**Untuk menggambarkan pekerjaan**  
`describe-jobs`Contoh berikut menjelaskan pekerjaan dengan ID pekerjaan yang ditentukan.  

```
aws batch describe-jobs \
    --jobs bcf0b186-a532-4122-842e-2ccab8d54efb
```
Output:  

```
{
    "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
        }
    ]
}
```
+  Untuk detail API, lihat [DescribeJobs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/describe-jobs.html)di *Referensi AWS CLI Perintah*. 

### `list-jobs`
<a name="batch_ListJobs_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`list-jobs`.

**AWS CLI**  
**Untuk daftar pekerjaan yang sedang berjalan**  
Contoh ini mencantumkan pekerjaan yang sedang berjalan dalam antrian HighPriority pekerjaan.  
Perintah:  

```
aws batch list-jobs --job-queue HighPriority
```
Output:  

```
{
    "jobSummaryList": [
        {
            "jobName": "example",
            "jobId": "e66ff5fd-a1ff-4640-b1a2-0b0a142f49bb"
        }
    ]
}
```
**Untuk daftar pekerjaan yang dikirimkan**  
Contoh ini mencantumkan pekerjaan dalam antrian HighPriority pekerjaan yang berada dalam status pekerjaan YANG DIKIRIMKAN.  
Perintah:  

```
aws batch list-jobs --job-queue HighPriority --job-status SUBMITTED
```
Output:  

```
{
    "jobSummaryList": [
        {
            "jobName": "example",
            "jobId": "68f0c163-fbd4-44e6-9fd1-25b14a434786"
        }
    ]
}
```
+  Untuk detail API, lihat [ListJobs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/list-jobs.html)di *Referensi AWS CLI Perintah*. 

### `register-job-definition`
<a name="batch_RegisterJobDefinition_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`register-job-definition`.

**AWS CLI**  
**Untuk mendaftarkan definisi pekerjaan**  
Contoh ini mendaftarkan definisi pekerjaan untuk pekerjaan kontainer sederhana.  
Perintah:  

```
aws batch register-job-definition --job-definition-name sleep30 --type container --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
}
```
+  Untuk detail API, lihat [RegisterJobDefinition](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/register-job-definition.html)di *Referensi AWS CLI Perintah*. 

### `submit-job`
<a name="batch_SubmitJob_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`submit-job`.

**AWS CLI**  
**Untuk mengirimkan pekerjaan**  
Contoh ini mengirimkan pekerjaan kontainer sederhana yang disebut contoh ke antrian HighPriority pekerjaan.  
Perintah:  

```
aws batch submit-job --job-name example --job-queue HighPriority  --job-definition sleep60
```
Output:  

```
{
    "jobName": "example",
    "jobId": "876da822-4198-45f2-a252-6cea32512ea8"
}
```
+  Untuk detail API, lihat [SubmitJob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/submit-job.html)di *Referensi AWS CLI Perintah*. 

### `terminate-job`
<a name="batch_TerminateJob_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`terminate-job`.

**AWS CLI**  
**Untuk mengakhiri pekerjaan**  
Contoh ini mengakhiri pekerjaan dengan ID pekerjaan yang ditentukan.  
Perintah:  

```
aws batch terminate-job --job-id 61e743ed-35e4-48da-b2de-5c8333821c84 --reason "Terminating job."
```
+  Untuk detail API, lihat [TerminateJob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/terminate-job.html)di *Referensi AWS CLI Perintah*. 

### `update-compute-environment`
<a name="batch_UpdateComputeEnvironment_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`update-compute-environment`.

**AWS CLI**  
**Untuk memperbarui lingkungan komputasi**  
Contoh ini menonaktifkan lingkungan OnDemand komputasi P2 sehingga dapat dihapus.  
Perintah:  

```
aws batch update-compute-environment --compute-environment P2OnDemand --state DISABLED
```
Output:  

```
{
    "computeEnvironmentName": "P2OnDemand",
    "computeEnvironmentArn": "arn:aws:batch:us-east-1:012345678910:compute-environment/P2OnDemand"
}
```
+  Untuk detail API, lihat [UpdateComputeEnvironment](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/update-compute-environment.html)di *Referensi AWS CLI Perintah*. 

### `update-job-queue`
<a name="batch_UpdateJobQueue_cli_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`update-job-queue`.

**AWS CLI**  
**Untuk memperbarui antrian pekerjaan**  
Contoh ini menonaktifkan antrian pekerjaan sehingga dapat dihapus.  
Perintah:  

```
aws batch update-job-queue --job-queue GPGPU --state DISABLED
```
Output:  

```
{
    "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/GPGPU",
    "jobQueueName": "GPGPU"
}
```
+  Untuk detail API, lihat [UpdateJobQueue](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/batch/update-job-queue.html)di *Referensi AWS CLI Perintah*. 