

# AWS CLI를 사용한 CodeConnections 예제
<a name="cli_codestar-connections_code_examples"></a>

다음 코드 예제에서는 CodeConnections에서 AWS Command Line Interface를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여 줍니다.

*작업*은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

각 예시에는 전체 소스 코드에 대한 링크가 포함되어 있으며, 여기에서 컨텍스트에 맞춰 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있습니다.

**Topics**
+ [작업](#actions)

## 작업
<a name="actions"></a>

### `create-connection`
<a name="codestar-connections_CreateConnection_cli_topic"></a>

다음 코드 예시는 `create-connection`의 사용 방법을 보여줍니다.

**AWS CLI**  
**연결을 생성하는 방법**  
다음 `create-connection` 예제에서는 타사 리포지토리에 대한 연결을 생성하는 방법을 보여줍니다. 이 예제에서는 타사 공급자가 Bitbucket인 연결을 만듭니다.  
AWS CLI 또는 AWS CloudFormation을 통해 생성된 연결은 기본적으로 Pending 상태입니다. CLI 또는 AWS CloudFormation으로 연결을 만든 후 콘솔을 사용하여 연결을 편집하여 Available 상태로 설정합니다.  

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

```
{
    "ConnectionArn": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f"
}
```
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [Create a connection](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-create.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [CreateConnection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/create-connection.html)을 참조하세요.

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

다음 코드 예시는 `create-host`의 사용 방법을 보여줍니다.

**AWS CLI**  
**호스트를 생성하는 방법**  
다음 `create-host` 예제에서는 타사 제공업체가 설치된 인프라의 엔드포인트를 나타내는 호스트를 만드는 방법을 보여 줍니다. 이 예제에서는 타사에 설치된 공급자가 GitHub Enterprise Server인 호스트를 생성합니다.  
AWS CLI를 통해 생성된 호스트는 기본적으로 Pending 상태입니다. CLI를 사용하여 호스트를 생성한 후 콘솔 또는 CLI를 통해 호스트를 설정하여 호스트를 상태를 Available로 전환합니다.  

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

```
{
    "HostArn": "arn:aws:codestar-connections:us-east-1:123456789012:host/My-Host-28aef605"
}
```
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [Create a host (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-host-create.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [CreateHost](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/create-host.html)를 참조하세요.

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

다음 코드 예시는 `delete-connection`의 사용 방법을 보여줍니다.

**AWS CLI**  
**연결을 삭제하려면**  
다음 `delete-connection` 예제는 연결을 삭제하는 방법을 보여줍니다.  

```
aws codestar-connections delete-connection \
    --connection-arn arn:aws:codestar-connections:us-west-2:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f
```
이 명령은 출력을 생성하지 않습니다.  
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [Delete a connection (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-delete.html#connections-delete-cli)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DeleteConnection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/delete-connection.html)을 참조하세요.

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

다음 코드 예시는 `delete-host`의 사용 방법을 보여줍니다.

**AWS CLI**  
**호스트를 삭제하는 방법**  
다음 `delete-host` 예제는 호스트를 삭제하는 방법을 보여줍니다. 호스트를 삭제하려면 먼저 호스트와 연결된 모든 연결을 삭제해야 합니다.  

```
aws codestar-connections delete-host \
    --host-arn "arn:aws:codestar-connections:us-east-1 :123456789012:host/My-Host-28aef605"
```
이 명령은 출력을 생성하지 않습니다.  
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [Delete a host (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-host-delete.html#connections-host-delete-cli)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DeleteHost](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/delete-host.html)를 참조하세요.

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

다음 코드 예시는 `get-connection`의 사용 방법을 보여줍니다.

**AWS CLI**  
**연결에 대한 정보를 가져오는 방법**  
다음 `get-connection` 예제에서는 연결에 대한 세부 정보를 보여줍니다.  

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

```
{
    "Connection": {
        "ConnectionName": "MyConnection",
        "ConnectionArn": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f",
        "ProviderType": "Bitbucket",
        "OwnerAccountId": "123456789012",
        "ConnectionStatus": "AVAILABLE"
    }
}
```
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [View connection details](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-view-details.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [GetConnection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/get-connection.html)을 참조하세요.

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

다음 코드 예시는 `get-host`의 사용 방법을 보여줍니다.

**AWS CLI**  
**호스트에 대한 정보를 가져오는 방법**  
다음 `get-host` 예제에서는 호스트에 대한 세부 정보를 보여줍니다.  

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

```
{
    "Name": "MyHost",
    "Status": "AVAILABLE",
    "ProviderType": "GitHubEnterpriseServer",
    "ProviderEndpoint": "https://test-instance-1.dev/"
}
```
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [View host details (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-host-view.html#connections-host-view-cli)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [GetHost](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/get-host.html)를 참조하세요.

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

다음 코드 예시는 `list-connections`의 사용 방법을 보여줍니다.

**AWS CLI**  
**연결을 나열하는 방법**  
다음 `list-connections` 예제에서는 Bitbucket 공급자 유형에 대한 계정의 모든 연결 목록을 검색합니다.  

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

```
{
    "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"
}
```
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [List connections (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-list.html#connections-list-cli)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListConnections](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/list-connections.html)를 참조하세요.

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

다음 코드 예시는 `list-hosts`의 사용 방법을 보여줍니다.

**AWS CLI**  
**호스트를 나열하는 방법**  
다음 `list-hosts` 예제에서는 계정에서 모든 호스트 목록을 검색합니다.  

```
aws codestar-connections list-hosts
```
출력:  

```
{
    "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"
        }
    ]
}
```
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [List hosts (CLI)](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-host-list.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListHosts](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/list-hosts.html)를 참조하세요.

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

다음 코드 예시는 `list-tags-for-resource`의 사용 방법을 보여줍니다.

**AWS CLI**  
**태그를 나열하는 방법**  
다음 `list-tags-for-resource` 예제에서는 지정된 연결 리소스에 연결된 모든 태그 목록을 검색합니다.  

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

```
{
    "Tags": [
        {
            "Key": "Project",
            "Value": "ProjectA"
        },
        {
            "Key": "ReadOnly",
            "Value": "true"
        }
    ]
}
```
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [View tags for a connections resource](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-tag.html#connections-tag-view)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/list-tags-for-resource.html)를 참조하세요.

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

다음 코드 예시에서는 `tag-resource`의 사용 방법을 보여줍니다.

**AWS CLI**  
**리소스에 태그를 지정하려면**  
다음 `tag-resource` 예제에서는 제공된 태그 세트를 연결과 연결합니다. 태그를 추가하거나 편집하려면 이 명령을 사용합니다.  

```
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
```
이 명령은 출력을 생성하지 않습니다.  
자세한 내용은 **개발자 도구 콘솔 사용 설명서의 [Add tags to a connections resource](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-tag.html#connections-tag-add)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/tag-resource.html)를 참조하세요.

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

다음 코드 예시는 `untag-resource`의 사용 방법을 보여줍니다.

**AWS CLI**  
**연결 리소스에서 AWS 태그를 제거하는 방법**  
다음 `untag-resource`에서는 지정된 리소스에서 태그를 제거합니다.  

```
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
```
출력:  

```
{
    "Tags": []
}
```
자세한 내용은 *개발자 도구 콘솔 사용 설명서*의 [Remove tags from a connections resource](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-tag.html#connections-tag-delete)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codestar-connections/untag-resource.html)를 참조하세요.