

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.

# CodeConnections contoh menggunakan AWS CLI
<a name="cli_2_codestar-connections_code_examples"></a>

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

*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-connection`
<a name="codestar-connections_CreateConnection_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`create-connection`.

**AWS CLI**  
**Untuk membuat koneksi**  
`create-connection`Contoh berikut menunjukkan cara membuat koneksi ke repositori pihak ketiga. Contoh ini membuat koneksi di mana penyedia pihak ketiga adalah Bitbucket.  
Koneksi yang dibuat melalui AWS CLI atau AWS CloudFormation dalam status Tertunda secara default. Setelah Anda membuat koneksi dengan CLI atau AWS CloudFormation, gunakan konsol untuk mengedit koneksi agar statusnya Tersedia.  

```
aws codestar-connections create-connection \
    --provider-type Bitbucket \
    --connection-name MyConnection
```
Output:  

```
{
    "ConnectionArn": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f"
}
```
Untuk informasi selengkapnya, lihat [Membuat sambungan](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-create.html) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [CreateConnection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/create-connection.html)di *Referensi AWS CLI Perintah*. 

### `create-host`
<a name="codestar-connections_CreateHost_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`create-host`.

**AWS CLI**  
**Untuk membuat host**  
`create-host`Contoh berikut menunjukkan cara membuat host untuk mewakili titik akhir infrastruktur tempat penyedia pihak ketiga Anda diinstal. Contoh ini membuat host di mana penyedia yang diinstal pihak ketiga adalah GitHub Enterprise Server.  
Host yang dibuat melalui AWS CLI berada dalam status Tertunda secara default. Setelah Anda membuat host dengan CLI, gunakan konsol atau CLI untuk mengatur host agar statusnya Tersedia.  

```
aws codestar-connections create-host \
    --name MyHost \
    --provider-type GitHubEnterpriseServer \
    --provider-endpoint "https://my-instance.dev"
```
Output:  

```
{
    "HostArn": "arn:aws:codestar-connections:us-east-1:123456789012:host/My-Host-28aef605"
}
```
Untuk informasi selengkapnya, lihat [Membuat host (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-host-create.html) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [CreateHost](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/create-host.html)di *Referensi AWS CLI Perintah*. 

### `delete-connection`
<a name="codestar-connections_DeleteConnection_cli_2_topic"></a>

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

**AWS CLI**  
**Untuk menghapus koneksi**  
`delete-connection`Contoh berikut menunjukkan cara menghapus koneksi.  

```
aws codestar-connections delete-connection \
    --connection-arn arn:aws:codestar-connections:us-west-2:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f
```
Perintah ini tidak menghasilkan output.  
Untuk informasi selengkapnya, lihat [Menghapus sambungan (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-delete.html#connections-delete-cli) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [DeleteConnection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/delete-connection.html)di *Referensi AWS CLI Perintah*. 

### `delete-host`
<a name="codestar-connections_DeleteHost_cli_2_topic"></a>

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

**AWS CLI**  
**Untuk menghapus host**  
`delete-host`Contoh berikut menunjukkan cara menghapus host. Sebelum Anda dapat menghapus host, Anda harus menghapus semua koneksi yang terkait dengan host.  

```
aws codestar-connections delete-host \
    --host-arn "arn:aws:codestar-connections:us-east-1 :123456789012:host/My-Host-28aef605"
```
Perintah ini tidak menghasilkan output.  
Untuk informasi selengkapnya, lihat [Menghapus host (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-host-delete.html#connections-host-delete-cli) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [DeleteHost](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/delete-host.html)di *Referensi AWS CLI Perintah*. 

### `get-connection`
<a name="codestar-connections_GetConnection_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`get-connection`.

**AWS CLI**  
**Untuk mendapatkan informasi tentang koneksi**  
`get-connection`Contoh berikut menunjukkan rincian tentang koneksi.  

```
aws codestar-connections get-connection \
    --connection-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f
```
Output:  

```
{
    "Connection": {
        "ConnectionName": "MyConnection",
        "ConnectionArn": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f",
        "ProviderType": "Bitbucket",
        "OwnerAccountId": "123456789012",
        "ConnectionStatus": "AVAILABLE"
    }
}
```
Untuk informasi selengkapnya, [lihat Melihat detail koneksi](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-view-details.html) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [GetConnection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/get-connection.html)di *Referensi AWS CLI Perintah*. 

### `get-host`
<a name="codestar-connections_GetHost_cli_2_topic"></a>

Contoh kode berikut menunjukkan cara menggunakan`get-host`.

**AWS CLI**  
**Untuk mendapatkan informasi tentang host**  
`get-host`Contoh berikut menunjukkan rincian tentang host:  

```
aws codestar-connections get-host \
    --host-arn arn:aws:codestar-connections:us-east-1:123456789012:host/MyHost-28aef605
```
Output:  

```
{
    "Name": "MyHost",
    "Status": "AVAILABLE",
    "ProviderType": "GitHubEnterpriseServer",
    "ProviderEndpoint": "https://test-instance-1.dev/"
}
```
Untuk informasi selengkapnya, [lihat Melihat detail host (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-host-view.html#connections-host-view-cli) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [GetHost](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/get-host.html)di *Referensi AWS CLI Perintah*. 

### `list-connections`
<a name="codestar-connections_ListConnections_cli_2_topic"></a>

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

**AWS CLI**  
**Untuk membuat daftar koneksi**  
`list-connections`Contoh berikut mengambil daftar semua koneksi di akun Anda untuk jenis penyedia Bitbucket. :  

```
aws codestar-connections list-connections \
--provider-type Bitbucket \
--max-results 5 \
--next-token: next-token
```
Output:  

```
{
    "Connections": [
        {
            "ConnectionName": "my-connection",
            "ProviderType": "Bitbucket",
            "Status": "PENDING",
            "ARN": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f",
            "OwnerAccountId": "123456789012"
        },
        {
            "ConnectionName": "my-other-connection",
            "ProviderType": "Bitbucket",
            "Status": "AVAILABLE",
            "ARN": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f",
            "OwnerAccountId": "123456789012"
        },
    ],
    "NextToken": "next-token"
}
```
Untuk informasi selengkapnya, lihat [Daftar koneksi (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-list.html#connections-list-cli) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [ListConnections](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/list-connections.html)di *Referensi AWS CLI Perintah*. 

### `list-hosts`
<a name="codestar-connections_ListHosts_cli_2_topic"></a>

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

**AWS CLI**  
**Untuk daftar host**  
`list-hosts`Contoh berikut mengambil daftar semua host di akun Anda.  

```
aws codestar-connections list-hosts
```
Output:  

```
{
    "Hosts": [
        {
            "Name": "My-Host",
            "HostArn": "arn:aws:codestar-connections:us-east-1:123456789012:host/My-Host-28aef605",
            "ProviderType": "GitHubEnterpriseServer",
            "ProviderEndpoint": "https://my-instance.test.dev",
            "Status": "AVAILABLE"
        }
    ]
}
```
Untuk informasi selengkapnya, lihat [Daftar host (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-host-list.html) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [ListHosts](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/list-hosts.html)di *Referensi AWS CLI Perintah*. 

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

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

**AWS CLI**  
**Untuk daftar tag**  
`list-tags-for-resource`Contoh berikut mengambil daftar semua tag yang dilampirkan ke sumber daya koneksi tertentu.  

```
aws codestar-connections list-tags-for-resource \
    --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f
```
Output:  

```
{
    "Tags": [
        {
            "Key": "Project",
            "Value": "ProjectA"
        },
        {
            "Key": "ReadOnly",
            "Value": "true"
        }
    ]
}
```
Untuk informasi selengkapnya, [lihat Melihat tag untuk sumber daya koneksi](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-tag.html#connections-tag-view) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/list-tags-for-resource.html)di *Referensi AWS CLI Perintah*. 

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

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

**AWS CLI**  
**Untuk menandai sumber daya**  
`tag-resource`Contoh berikut mengaitkan satu set tag yang disediakan dengan koneksi. Gunakan perintah ini untuk menambah atau mengedit tag.  

```
aws codestar-connections tag-resource \
    --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f \
    --tags Key=Project,Value=ProjectA Key=IscontainerBased,Value=true
```
Perintah ini tidak menghasilkan output.  
Untuk informasi selengkapnya, lihat [Menambahkan tag ke sumber daya koneksi](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-tag.html#connections-tag-add) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/tag-resource.html)di *Referensi AWS CLI Perintah*. 

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

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

**AWS CLI**  
**Untuk menghapus AWS tag dari sumber daya koneksi**  
Berikut ini `untag-resource` menghapus tag dari sumber daya yang ditentukan.  

```
aws codestar-connections untag-resource \
    --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f \
    --tag-keys Project ReadOnly
```
Output:  

```
{
    "Tags": []
}
```
Untuk informasi selengkapnya, lihat [Menghapus tag dari sumber daya koneksi](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-tag.html#connections-tag-delete) di *Panduan Pengguna konsol Alat Pengembang*.  
+  Untuk detail API, lihat [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/untag-resource.html)di *Referensi AWS CLI Perintah*. 