Getting started using the AWS CLI
Run the following steps to get started with CodeArtifact using the AWS Command Line Interface (AWS CLI). For more
information, see Install or upgrade and then configure the
AWS CLI. This guide uses the npm package manager,
if you are using a different package manager, you will need to modify some of the following steps.
-
Use the AWS CLI to run the create-domain command.
aws codeartifact create-domain --domainmy-domainJSON-formatted data appears in the output with details about your new domain.
{ "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 } }If you receive the error
Could not connect to the endpoint URL, make sure that your AWS CLI is configured and that your Default region name is set to the same Region where you created your repository, see Configuring the AWS Command Line Interface. -
Use the create-repository command to create a repository in your domain.
aws codeartifact create-repository --domainmy-domain--domain-owner111122223333--repositorymy-repoJSON-formatted data appears in the output with details about your new repository.
{ "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": [] } } -
Use the create-repository command to create an upstream repository for your
my-reporepository.aws codeartifact create-repository --domainmy-domain--domain-owner111122223333--repositorynpm-storeJSON-formatted data appears in the output with details about your new repository.
{ "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": [] } } -
Use the associate-external-connection command to add an external connection to the npm public repository to your
npm-storerepository.aws codeartifact associate-external-connection --domainmy-domain--domain-owner111122223333--repositorynpm-store--external-connection"public:npmjs"JSON-formatted data appears in the output with details about the repository and its new external connection.
{ "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" } ] } }For more information, see Connect a CodeArtifact repository to a public repository.
-
Use the update-repository command to associate the
npm-storerepository as an upstream repository to themy-reporepository.aws codeartifact update-repository --repositorymy-repo--domainmy-domain--domain-owner111122223333--upstreams repositoryName=npm-storeJSON-formatted data appears in the output with details about your updated repository, including its new upstream repository.
{ "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": [] } }For more information, see Add or remove upstream repositories (AWS CLI).
-
Use the login command to configure your npm package manager with your
my-reporepository.aws codeartifact login --tool npm --repositorymy-repo--domainmy-domain--domain-owner111122223333You should receive output confirming your login succeeded.
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:00For more information, see Configure and use npm with CodeArtifact.
-
Use the npm CLI to install an npm package. For example, to install the popular npm package
lodash, use the following command.npm installlodash -
Use the list-packages command to view the package you just installed in your
my-reporepository.Note
There may be a delay between when the
npm installinstall command completes and when the package is visible in your repository. For details on typical latency when fetching packages from public repositories, see External connection latency.aws codeartifact list-packages --domainmy-domain--repositorymy-repoJSON-formatted data appears in the output with the format and name of the package that you installed.
{ "packages": [ { "format": "npm", "package": "lodash" } ] }You now have three CodeArtifact resources:
-
The domain
my-domain. -
The repository
my-repothat is contained inmy-domain. This repository has an npm package available to it. -
The repository
npm-storethat is contained inmy-domain. This repository has an external connection to the public npm repository and is associated as an upstream repository with themy-reporepository.
-
-
To avoid further AWS charges, delete the resources that you used during this tutorial:
Note
You cannot delete a domain that contains repositories, so you must delete
my-repoandnpm-storebefore you deletemy-domain.-
Use the delete-repository command to delete the
npm-storerepository.aws codeartifact delete-repository --domainmy-domain--domain-owner111122223333--repositorymy-repoJSON-formatted data appears in the output with details about the deleted repository.
{ "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": [] } } -
Use the delete-repository command to delete the
npm-storerepository.aws codeartifact delete-repository --domainmy-domain--domain-owner111122223333--repositorynpm-storeJSON-formatted data appears in the output with details about the deleted repository.
{ "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" } ] } } -
Use the delete-domain command to delete the
my-domainrepository.aws codeartifact delete-domain --domainmy-domain--domain-owner111122223333JSON-formatted data appears in the output with details about the deleted domain.
{ "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 } }
-