AWS CLI 使用入門 - CodeArtifact

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS CLI 使用入門

執行下列步驟,以開始使用 CodeArtifact 使用AWS Command Line Interface(AWS CLI。如需詳細資訊,請參閱 安裝或升級,然後設定 AWS CLI。本指南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已配置並且您的預設區域名稱設為您建立儲存庫時所在的區域,請參閱設定 AWS 命令列界面

  2. 使用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": [] } }
  3. 使用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": [] } }
  4. 使用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 存儲庫 Connect 到公共存儲庫

  5. 使用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)

  6. 使用login命令來配置你的 npm 軟件包管理器my-repo儲存庫。

    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

    如需詳細資訊,請參閱 配置和使用 npm CodeArtifact

  7. 使用 npm CLI 來安裝 NPM 套件。例如,要安裝流行的 npm 軟件包lodash,使用下列命令。

    npm install lodash
  8. 使用list-packages命令來查看您剛剛安裝的軟件包my-repo儲存庫。

    注意

    之間可能會有延遲npm installinstall 命令完成,並且當軟件包在存儲庫中可見時。如需從公用儲存庫擷取套件時一般延遲的詳細資訊,請參閱外部連延延

    aws codeartifact list-packages --domain my-domain --repository my-repo

    JSON 格式的資料會出現在您安裝的輸出中。

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

    您現在有三個 CodeArtifact 資源:

    • 網域my-domain

    • 儲存庫my-repo包含於my-domain。這個存儲庫有一個可供它使用的 npm 軟件包。

    • 儲存庫npm-store包含於my-domain。此存儲庫具有與公共 npm 存儲庫的外部連接,並與my-repo儲存庫。

  9. 避免AWS收費,刪除您在此教學課程中使用的資源:

    注意

    您無法刪除包含儲存庫的網域,因此您必須刪除my-reponpm-store刪除之前my-domain

    1. 使用delete-repository命令來刪除npm-store儲存庫。

      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": [] } }
    2. 使用delete-repository命令來刪除npm-store儲存庫。

      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" } ] } }
    3. 使用delete-domain命令來刪除my-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 } }