

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# AWS CLI を使用した開始方法
<a name="getting-started-cli"></a>

 AWS Command Line Interface (AWS CLI) を使用して CodeArtifactを開始するには、以下のステップを実行します。詳細については、「[をインストールまたはアップグレードしてから設定する AWS CLI](get-set-up-install-cli.md)」を参照してください。このガイドでは、`npm` パッケージマネージャーを使用します。別のパッケージマネージャーを使用している場合は、次のステップの一部を変更する必要があります。

1.  AWS CLI を使用して **create-domain** コマンドを実行します。

   ```
   aws codeartifact create-domain --domain {{my-domain}}
   ```

    JSON 形式のデータが、新しいドメインの詳細とともに出力に表示されます。

   ```
   {
       "domain": {
           "name": "{{my-domain}}",
           "owner": "{{111122223333}}",
           "arn": "arn:aws:codeartifact:{{us-west-2}}:{{111122223333}}:domain/{{my-domain}}",
           "status": "Active",
           "createdTime": "2020-10-07T15:36:35.194000-04:00",
           "encryptionKey": "arn:aws:kms:{{us-west-2}}:{{111122223333}}:key/{{your-kms-key}}",
           "repositoryCount": 0,
           "assetSizeBytes": 0
       }
   }
   ```

   エラー `Could not connect to the endpoint URL` が発生した場合は、AWS CLI が設定されており、**[デフォルトリージョン名]** がリポジトリを作成したのと同じリージョンに設定されていることを確認してください。「[Configuring the AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)」を参照してください。

1.  **create-repository**コマンドを使用して、ドメインにリポジトリを作成します。

   ```
   aws codeartifact create-repository --domain {{my-domain}} --domain-owner {{111122223333}} --repository {{my-repo}}
   ```

    JSON 形式のデータが、新しいリポジトリの詳細とともに出力に表示されます。

   ```
   {
       "repository": {
           "name": "{{my-repo}}",
           "administratorAccount": "111122223333",
           "domainName": "{{my-domain}}",
           "domainOwner": "{{111122223333}}",
           "arn": "arn:aws:codeartifact:{{us-west-2}}:{{111122223333}}:repository/{{my-domain}}/{{my-repo}}",
           "upstreams": [],
           "externalConnections": []
       }
   }
   ```

1. **create-repository** コマンドを使用して、`my-repo` リポジトリのアップストリームリポジトリを作成します。

   ```
   aws codeartifact create-repository --domain {{my-domain}} --domain-owner {{111122223333}} --repository {{npm-store}}
   ```

    JSON 形式のデータが、新しいリポジトリの詳細とともに出力に表示されます。

   ```
   {
       "repository": {
           "name": "npm-store",
           "administratorAccount": "111122223333",
           "domainName": "{{my-domain}}",
           "domainOwner": "{{111122223333}}",
           "arn": "arn:aws:codeartifact:{{us-west-2}}:{{111122223333}}:repository/{{my-domain}}/{{npm-store}}",
           "upstreams": [],
           "externalConnections": []
       }
   }
   ```

1.  **associate-external-connection** コマンドを使用して、npm 公開リポジトリへの外部接続を`npm-store` リポジトリに追加します。

   ```
   aws codeartifact associate-external-connection --domain {{my-domain}} --domain-owner {{111122223333}} --repository {{npm-store}} --external-connection {{"public:npmjs"}}
   ```

    JSON 形式のデータが、リポジトリとその新しい外部接続についての詳細とともに出力に表示されます。

   ```
   {
       "repository": {
           "name": "{{npm-store}}",
           "administratorAccount": "111122223333",
           "domainName": "{{my-domain}}",
           "domainOwner": "{{111122223333}}",
           "arn": "arn:aws:codeartifact:{{us-west-2}}:{{111122223333}}:repository/{{my-domain}}/{{npm-store}}",
           "upstreams": [],
           "externalConnections": [
               {
                   "externalConnectionName": "{{public:npmjs}}",
                   "packageFormat": "npm",
                   "status": "AVAILABLE"
               }
           ]
       }
   }
   ```

    詳細については、「[CodeArtifact リポジトリをパブリックリポジトリに接続する](external-connection.md)」を参照してください。

1.  **update-repository** コマンドを使用して、`npm-store` リポジトリを `my-repo` リポジトリへのアップストリームリポジトリとして関連付けます。

   ```
   aws codeartifact update-repository --repository {{my-repo}} --domain {{my-domain}} --domain-owner {{111122223333}} --upstreams repositoryName={{npm-store}}
   ```

    JSON 形式のデータが、新しいアップストリームリポジトリを含む、更新されたリポジトリの詳細とともに出力に表示されます。

   ```
   {
       "repository": {
           "name": "{{my-repo}}",
           "administratorAccount": "111122223333",
           "domainName": "{{my-domain}}",
           "domainOwner": "{{111122223333}}",
           "arn": "arn:aws:codeartifact:{{us-west-2}}:{{111122223333}}:repository/{{my-domain}}/{{my-repo}}",
           "upstreams": [
               {
                   "repositoryName": "{{npm-store}}"
               }
           ],
           "externalConnections": []
       }
   }
   ```

    詳細については、「[アップストリームリポジトリを追加または削除する (AWS CLI)](repo-upstream-add.md#repo-upstream-add-cli)」を参照してください。

1. **login** コマンドを使用して、`my-repo` リポジトリに npm パッケージマネージャーを設定します。

   ```
   aws codeartifact login --tool npm --repository {{my-repo}} --domain {{my-domain}} --domain-owner {{111122223333}}
   ```

   ログインが成功したことを確認する出力が表示されます。

   ```
   Successfully configured npm to use AWS CodeArtifact repository https://my-domain-{{111122223333}}.d.codeartifact.{{us-east-2}}.amazonaws.com/npm/{{my-repo}}/
   Login expires in 12 hours at 2020-10-08 02:45:33-04:00
   ```

    詳細については、「[CodeArtifact で npm を設定して使用する](npm-auth.md)」を参照してください。

1.  npm CLI を使用して npm パッケージをインストールします。例えば、一般的な npm パッケージ `lodash` をインストールするには、以下のコマンドを使用します。

   ```
   npm install {{lodash}}
   ```

1.  **list-packages** コマンドを使用して、`my-repo` リポジトリでインストールしたばかりのパッケージを表示します。
**注記**  
`npm install` インストールコマンドが完了してからリポジトリに表示するまでの間に遅延が生じる場合があります。パブリックリポジトリからパッケージを取得するときの一般的なレイテンシーの詳細については、「[外部接続のレイテンシー](external-connection-requesting-packages.md#external-connection-latency)」を参照してください。

   ```
   aws codeartifact list-packages --domain {{my-domain}} --repository {{my-repo}}
   ```

    JSON 形式のデータが、インストールしたパッケージの形式と名前とともに出力に表示されます。

   ```
   {
       "packages": [
           {
               "format": "npm",
               "package": "{{lodash}}"
           }
       ]
   }
   ```

   これで、次の三つの CodeArtifact リソースが作成されました。
   +  ドメイン`my-domain`。
   +  `my-domain` に含まれるリポジトリ `my-repo`。このリポジトリには、利用可能な npm パッケージがあります。
   +  `my-domain` に含まれるリポジトリ `npm-store`。このリポジトリは、パブリック npm リポジトリへの外部接続を持ち、アップストリームリポジトリとして `my-repo` リポジトリに関連付けられています。

1. 更なる AWS の課金を回避するには、このチュートリアルで使用したリソースを削除します。
**注記**  
 リポジトリを含むドメインは削除できないため、`my-domain` を削除する前に `my-repo` および `npm-store` を削除する必要があります。

   1.  `npm-store` リポジトリを削除するには、**delete-repository** コマンドを使用します。

      ```
      aws codeartifact delete-repository --domain {{my-domain}} --domain-owner {{111122223333}} --repository {{my-repo}}
      ```

       JSON 形式のデータが、削除されたリポジトリの詳細とともに出力に表示されます。

      ```
      {
          "repository": {
              "name": "my-repo",
              "administratorAccount": "{{111122223333}}",
              "domainName": "{{my-domain}}",
              "domainOwner": "{{111122223333}}",
              "arn": "arn:aws:codeartifact:{{us-west-2}}:{{111122223333}}:repository/{{my-domain}}/{{my-repo}}",
              "upstreams": [
                  {
                      "repositoryName": "{{npm-store}}"
                  }
              ],
              "externalConnections": []
          }
      }
      ```

   1.  `npm-store` リポジトリを削除するには、 **delete-repository** コマンドを使用します。

      ```
      aws codeartifact delete-repository --domain {{my-domain}} --domain-owner {{111122223333}} --repository {{npm-store}}
      ```

       JSON 形式のデータが、削除されたリポジトリの詳細とともに出力に表示されます。

      ```
      {
          "repository": {
              "name": "{{npm-store}}",
              "administratorAccount": "{{111122223333}}",
              "domainName": "{{my-domain}}",
              "domainOwner": "{{111122223333}}",
              "arn": "arn:aws:codeartifact:{{us-west-2}}:{{111122223333}}:repository/{{my-domain}}/{{npm-store}}",
              "upstreams": [],
              "externalConnections": [
                  {
                      "externalConnectionName": "public:npmjs",
                      "packageFormat": "npm",
                      "status": "AVAILABLE"
                  }
              ]
          }
      }
      ```

   1. `my-domain` リポジトリを削除するには、 **delete-domain** コマンドを使用します。

      ```
      aws codeartifact delete-domain --domain {{my-domain}} --domain-owner {{111122223333}}
      ```

       JSON 形式のデータが、削除されたドメインの詳細とともに出力に表示されます。

      ```
      {
          "domain": {
              "name": "{{my-domain}}",
              "owner": "{{111122223333}}",
              "arn": "arn:aws:codeartifact:{{us-west-2}}:{{111122223333}}:domain/{{my-domain}}",
              "status": "Deleted",
              "createdTime": "2020-10-07T15:36:35.194000-04:00",
              "encryptionKey": "arn:aws:kms:{{us-west-2}}:{{111122223333}}:key/your-kms-key",
              "repositoryCount": 0,
              "assetSizeBytes": 0
          }
      }
      ```