

Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh [SDK AWS Doc](https://github.com/awsdocs/aws-doc-sdk-examples). GitHub 

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

# AWS CodeStar Contoh pemberitahuan menggunakan AWS CLI
<a name="cli_2_codestar-notifications_code_examples"></a>

Contoh kode berikut menunjukkan kepada Anda cara melakukan tindakan dan mengimplementasikan skenario umum dengan menggunakan AWS Command Line Interface With AWS CodeStar Notifications.

*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>

### `create-notification-rule`
<a name="codestar-notifications_CreateNotificationRule_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`create-notification-rule`.

**AWS CLI**  
**Untuk membuat aturan notifikasi**  
`create-notification-rule`Contoh berikut menggunakan file JSON bernama `rule.json` untuk membuat aturan notifikasi bernama `MyNotificationRule` untuk repositori bernama `MyDemoRepo` dalam akun tertentu. AWS Pemberitahuan dengan jenis `FULL` detail dikirim ke topik Amazon SNS target yang ditentukan saat cabang dan tag dibuat.  

```
aws codestar-notifications create-notification-rule \
    --cli-input-json file://rule.json
```
Isi dari `rule.json`:  

```
{
    "Name": "MyNotificationRule",
    "EventTypeIds": [
        "codecommit-repository-branches-and-tags-created"
    ],
    "Resource": "arn:aws:codecommit:us-east-1:123456789012:MyDemoRepo",
    "Targets": [
        {
            "TargetType": "SNS",
            "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic"
        }
    ],
    "Status": "ENABLED",
    "DetailType": "FULL"
}
```
Output:  

```
{
    "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE"
}
```
Untuk selengkapnya, lihat [Membuat aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-create.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [CreateNotificationRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/create-notification-rule.html)di *Referensi AWS CLI Perintah*. 

### `delete-notification-rule`
<a name="codestar-notifications_DeleteNotificationRule_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`delete-notification-rule`.

**AWS CLI**  
**Untuk menghapus aturan notifikasi**  
`delete-notification-rule`Contoh berikut menghapus aturan pemberitahuan yang ditentukan.  

```
aws codestar-notifications delete-notification-rule \
    --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE
```
Output:  

```
{
    "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE"
}
```
Untuk informasi selengkapnya, lihat [Menghapus Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-delete.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [DeleteNotificationRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/delete-notification-rule.html)di *Referensi AWS CLI Perintah*. 

### `delete-target`
<a name="codestar-notifications_DeleteTarget_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`delete-target`.

**AWS CLI**  
**Untuk menghapus target aturan notifikasi**  
`delete-target`Contoh berikut menghapus target yang ditentukan dari semua aturan notifikasi yang dikonfigurasi untuk menggunakannya sebagai target, dan kemudian menghapus target.  

```
aws codestar-notifications  delete-target \
    --target-address arn:aws:sns:us-east-1:123456789012:MyNotificationTopic \
    --force-unsubscribe-all
```
Perintah ini tidak menghasilkan output.  
Untuk informasi selengkapnya, lihat [Menghapus Target Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-target-delete.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [DeleteTarget](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/delete-target.html)di *Referensi AWS CLI Perintah*. 

### `describe-notification-rule`
<a name="codestar-notifications_DescribeNotificationRule_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`describe-notification-rule`.

**AWS CLI**  
**Untuk mengambil rincian aturan notifikasi**  
`describe-notification-rule`Contoh berikut mengambil rincian aturan pemberitahuan yang ditentukan.  

```
aws codestar-notifications describe-notification-rule \
    --arn arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/dc82df7a-EXAMPLE
```
Output:  

```
{
    "LastModifiedTimestamp": 1569199844.857,
    "EventTypes": [
        {
            "ServiceName": "CodeCommit",
            "EventTypeName": "Branches and tags: Created",
            "ResourceType": "Repository",
            "EventTypeId": "codecommit-repository-branches-and-tags-created"
        }
    ],
    "Status": "ENABLED",
    "DetailType": "FULL",
    "Resource": "arn:aws:codecommit:us-west-2:123456789012:MyDemoRepo",
    "Arn": "arn:aws:codestar-notifications:us-west-w:123456789012:notificationrule/dc82df7a-EXAMPLE",
    "Targets": [
        {
            "TargetStatus": "ACTIVE",
            "TargetAddress": "arn:aws:sns:us-west-2:123456789012:MyNotificationTopic",
            "TargetType": "SNS"
        }
    ],
    "Name": "MyNotificationRule",
    "CreatedTimestamp": 1569199844.857,
    "CreatedBy": "arn:aws:iam::123456789012:user/Mary_Major"
}
```
Untuk selengkapnya, lihat [Melihat Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-view.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [DescribeNotificationRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/describe-notification-rule.html)di *Referensi AWS CLI Perintah*. 

### `list-event-types`
<a name="codestar-notifications_ListEventTypes_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`list-event-types`.

**AWS CLI**  
**Untuk mendapatkan daftar jenis acara untuk aturan notifikasi**  
`list-event-types`Contoh berikut mengambil daftar yang difilter dari semua jenis acara pemberitahuan yang tersedia untuk CodeDeploy aplikasi. Jika sebaliknya Anda tidak menggunakan filter, perintah mengembalikan semua jenis acara notifikasi untuk semua jenis sumber daya.  

```
aws codestar-notifications list-event-types \
    --filters Name=SERVICE_NAME,Value=CodeDeploy
```
Output:  

```
{
    "EventTypes": [
        {
            "EventTypeId": "codedeploy-application-deployment-succeeded",
            "ServiceName": "CodeDeploy",
            "EventTypeName": "Deployment: Succeeded",
            "ResourceType": "Application"
        },
        {
            "EventTypeId": "codedeploy-application-deployment-failed",
            "ServiceName": "CodeDeploy",
            "EventTypeName": "Deployment: Failed",
            "ResourceType": "Application"
        },
        {
            "EventTypeId": "codedeploy-application-deployment-started",
            "ServiceName": "CodeDeploy",
            "EventTypeName": "Deployment: Started",
            "ResourceType": "Application"
        }
    ]
}
```
Untuk informasi selengkapnya, lihat [Membuat Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-create.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [ListEventTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/list-event-types.html)di *Referensi AWS CLI Perintah*. 

### `list-notification-rules`
<a name="codestar-notifications_ListNotificationRules_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`list-notification-rules`.

**AWS CLI**  
**Untuk mengambil daftar aturan notifikasi**  
`list-notification-rules`Contoh berikut mengambil daftar semua aturan notifikasi di AWS Wilayah tertentu.  

```
aws codestar-notifications list-notification-rules --region us-east-1
```
Output:  

```
{
    "NotificationRules": [
        {
            "Id": "dc82df7a-EXAMPLE",
            "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE"
        },
        {
            "Id": "8d1f0983-EXAMPLE",
            "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/8d1f0983-EXAMPLE"
        }
    ]
}
```
Untuk selengkapnya, lihat [Melihat Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-view.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [ListNotificationRules](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/list-notification-rules.html)di *Referensi AWS CLI Perintah*. 

### `list-tags-for-resource`
<a name="codestar-notifications_ListTagsForResource_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`list-tags-for-resource`.

**AWS CLI**  
**Untuk mendapatkan daftar tag yang dilampirkan pada aturan notifikasi**  
`list-tags-for-resource`Contoh berikut mengambil daftar semua tag yang dilampirkan pada aturan pemberitahuan yang ditentukan. Dalam contoh ini, aturan notifikasi saat ini tidak memiliki tag yang terkait dengannya.  

```
aws codestar-notifications list-tags-for-resource \
    --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE
```
Output:  

```
{
    "Tags": {}
}
```
Untuk informasi selengkapnya, lihat [Membuat Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-create.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/list-tags-for-resource.html)di *Referensi AWS CLI Perintah*. 

### `list-targets`
<a name="codestar-notifications_ListTargets_cli_2_topic"></a>

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

**AWS CLI**  
**Untuk mengambil daftar target aturan notifikasi**  
`list-targets`Contoh berikut mengambil daftar semua target aturan notifikasi di AWS Wilayah tertentu.  

```
aws codestar-notifications list-targets \
    --region us-east-1
```
Output:  

```
{
    "Targets": [
        {
            "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MySNSTopicForNotificationRules",
            "TargetType": "SNS",
            "TargetStatus": "ACTIVE"
        },
        {
            "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MySNSTopicForNotificationsAboutMyDemoRepo",
            "TargetType": "SNS",
            "TargetStatus": "ACTIVE"
        }
    ]
}
```
Untuk informasi selengkapnya, lihat [Melihat Target Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-target-view.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [ListTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/list-targets.html)di *Referensi AWS CLI Perintah*. 

### `subscribe`
<a name="codestar-notifications_Subscribe_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`subscribe`.

**AWS CLI**  
**Untuk menambahkan target ke aturan notifikasi**  
`subscribe`Contoh berikut menambahkan topik Amazon SNS sebagai target untuk aturan notifikasi yang ditentukan.  

```
aws codestar-notifications subscribe \
    --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE \
    --target TargetType=SNS,TargetAddress=arn:aws:sns:us-east-1:123456789012:MyNotificationTopic
```
Output:  

```
{
    "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE"
}
```
Untuk selengkapnya, lihat [Menambahkan atau Menghapus Topik Amazon SNS sebagai Target untuk Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-target-change-rule.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [Berlangganan](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/subscribe.html) di *Referensi AWS CLI Perintah*. 

### `tag-resource`
<a name="codestar-notifications_TagResource_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`tag-resource`.

**AWS CLI**  
**Untuk menambahkan tag ke aturan notifikasi**  
`tag-resource`Contoh berikut menambahkan tag dengan nama kunci `Team` dan nilai `Li_Juan` untuk aturan pemberitahuan yang ditentukan.  

```
aws codestar-notifications tag-resource \
    --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE \
    --tags Team=Li_Juan
```
Output:  

```
{
    "Tags": {
        "Team": "Li_Juan"
    }
}
```
Untuk informasi selengkapnya, lihat [Membuat Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-create.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/tag-resource.html)di *Referensi AWS CLI Perintah*. 

### `unsubscribe`
<a name="codestar-notifications_Unsubscribe_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`unsubscribe`.

**AWS CLI**  
**Untuk menghapus target dari aturan notifikasi**  
`unsubscribe`Contoh berikut menghapus topik Amazon SNS sebagai target dari aturan notifikasi yang ditentukan.  

```
aws codestar-notifications unsubscribe \
    --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE \
    --target TargetType=SNS,TargetAddress=arn:aws:sns:us-east-1:123456789012:MyNotificationTopic
```
Output:  

```
{
    "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE"
    "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic"
}
```
Untuk selengkapnya, lihat [Menambahkan atau Menghapus Topik Amazon SNS sebagai Target untuk Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-target-change-rule.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [Berhenti berlangganan](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/unsubscribe.html) di *Referensi AWS CLI Perintah*. 

### `untag-resource`
<a name="codestar-notifications_UntagResource_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`untag-resource`.

**AWS CLI**  
**Untuk menghapus tag dari aturan pemberitahuan**  
`untag-resource`Contoh berikut menghapus tag dengan nama kunci `Team` dari aturan pemberitahuan yang ditentukan.  

```
aws codestar-notifications untag-resource \
    --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE \
    --tag-keys Team
```
Perintah ini tidak menghasilkan output.  
Untuk informasi selengkapnya, lihat [Mengedit Aturan Pemberitahuan](https://docs.aws.amazon.com/codestar-notifications/latest/userguide/notification-rule-edit.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/untag-resource.html)di *Referensi AWS CLI Perintah*. 

### `update-notification-rule`
<a name="codestar-notifications_UpdateNotificationRule_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`update-notification-rule`.

**AWS CLI**  
**Untuk memperbarui aturan notifikasi**  
`update-notification-rule`Contoh berikut memperbarui aturan notifikasi bernama `MyNotificationRule` di AWS akun `123456789012` menggunakan file JSON bernama`update.json`.  

```
aws codestar-notifications update-notification-rule \
    --cli-input-json file://update.json
```
Isi dari `update.json`:  

```
{
    "Name": "MyUpdatedNotificationRule",
    "EventTypeIds": [
        "codecommit-repository-branches-and-tags-created"
    ],
    "Resource": "arn:aws:codecommit:us-east-1:123456789012:MyDemoRepo",
    "Targets": [
        {
            "TargetType": "SNS",
            "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic"
        }
    ],
    "Status": "ENABLED",
    "DetailType": "FULL"
}
```
Output:  

```
{
    "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE"
}
```
Untuk informasi selengkapnya, lihat [Mengedit aturan pemberitahuan](https://docs.aws.amazon.com/dtconsole/latest/userguide/notification-rule-edit.html) di *Panduan Pengguna Konsol Alat AWS Pengembang*.  
+  Untuk detail API, lihat [UpdateNotificationRule](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-notifications/update-notification-rule.html)di *Referensi AWS CLI Perintah*. 