View a markdown version of this page

CodeArtifact examples using AWS CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

CodeArtifact examples using AWS CLI

The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with CodeArtifact.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use associate-external-connection.

AWS CLI

To add an external connection to a repository

The following associate-external-connection example adds an external connection to npmjs.com to a repository named test-repo.

aws codeartifact associate-external-connection \ --repository test-repo \ --domain test-domain \ --external-connection public:npmjs

Output:

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

For more information, see Add an external connection in the AWS CodeArtifact User Guide.

The following code example shows how to use copy-package-versions.

AWS CLI

To copy package versions from one repository to another

The following copy-package-versions moves versions 4.0.0 and 5.0.0 of a package named test-package from my-repo to test-repo.

aws codeartifact copy-package-versions \ --domain test-domain \ --source-repository my-repo \ --destination-repository test-repo \ --format npm \ --package test-package \ --versions '["4.0.0", "5.0.0"]'

Output:

{ "format": "npm", "package": "test-package", "versions": [ { "version": "5.0.0", "revision": "REVISION-1-SAMPLE-6C81EFF7DA55CC", "status": "Published" }, { "version": "4.0.0", "revision": "REVISION-2-SAMPLE-55C752BEE772FC", "status": "Published" } ] }

For more information, see Copy packages between repositories in the AWS CodeArtifact User Guide.

The following code example shows how to use create-domain.

AWS CLI

To create a domain

The following create-domain example creates a domain named test-domain.

aws codeartifact create-domain \ --domain test-domain

Output:

{ "domain": { "name": "test-domain", "owner": "111122223333", "arn": "arn:aws:codeartifact:us-west-2:111122223333:domain/test-domain", "status": "Active", "createdTime": "2020-10-20T13:16:48.559000-04:00", "encryptionKey": "arn:aws:kms:us-west-2:111122223333:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "repositoryCount": 0, "assetSizeBytes": 0 } }

For more information, see Create a domain in the AWS CodeArtifact User Guide.

  • For API details, see CreateDomain in AWS CLI Command Reference.

The following code example shows how to use create-repository.

AWS CLI

To create a repository

The following create-repository example creates a repository named test-repo inside a domain named test-domain.

aws codeartifact create-repository \ --domain test-domain \ --domain-owner 111122223333 \ --repository test-repo \ --description "This is a test repository."

Output:

{ "repository": { "name": "test-repo", "administratorAccount": "111122223333", "domainName": "test-domain", "domainOwner": "111122223333", "arn": "arn:aws:codeartifact:us-west-2:111122223333:repository/test-domain/test-repo", "description": "This is a test repository.", "upstreams": [], "externalConnections": [] } }

For more information, see Create a domain in the AWS CodeArtifact User Guide.

The following code example shows how to use delete-domain-permissions-policy.

AWS CLI

To delete the permissions policy document from a domain

The following delete-domain-permissions-policy example deletes the permission policy from a domain named test-domain.

aws codeartifact delete-domain-permissions-policy \ --domain test-domain

Output:

{ "Version":"2012-10-17", "Statement": [ { "Sid": "BasicDomainPolicy", "Action": [ "codeartifact:GetDomainPermissionsPolicy", "codeartifact:ListRepositoriesInDomain", "codeartifact:GetAuthorizationToken", "codeartifact:CreateRepository" ], "Effect": "Allow", "Resource": "*", "Principal": { "AWS": "arn:aws:iam::111122223333:root" } } ] }

For more information, see Delete a domain policy in the AWS CodeArtifact User Guide.

The following code example shows how to use delete-domain.

AWS CLI

To delete a domain

The following delete-domain example deletes a domain named test-domain.

aws codeartifact delete-domain \ --domain test-domain

Output:

{ "domain": { "name": "test-domain", "owner": "417498243647", "arn": "arn:aws:codeartifact:us-west-2:417498243647:domain/test-domain", "status": "Deleted", "createdTime": "2020-10-20T13:16:48.559000-04:00", "encryptionKey": "arn:aws:kms:us-west-2:417498243647:key/c9fe2447-0795-4fda-afbe-8464574ae162", "repositoryCount": 0, "assetSizeBytes": 0 } }

For more information, see Delete a domain in the AWS CodeArtifact User Guide.

  • For API details, see DeleteDomain in AWS CLI Command Reference.

The following code example shows how to use delete-package-versions.

AWS CLI

To delete package versions

The following delete-package-versions example deletes version 4.0.0 of a package named test-package.

aws codeartifact delete-package-versions \ --domain test-domain \ --repo test-repo \ --format npm \ --package test-package \ --versions 4.0.0

Output:

{ "successfulVersions": { "4.0.0": { "revision": "Ciqe5/9yicvkJT13b5/LdLpCyE6fqA7poa9qp+FilPs=", "status": "Deleted" } }, "failedVersions": {} }

For more information, see Delete a package version in the AWS CodeArtifact User Guide.

The following code example shows how to use delete-repository-permissions-policy.

AWS CLI

To delete a permissions policy from a repository

The following delete-repository-permissions-policy example deletes the permission policy from a repository named test-repo.

aws codeartifact delete-repository-permissions-policy \ --domain test-domain \ --repository test-repo

Output:

{ "Version":"2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:root" }, "Action": [ "codeartifact:DescribePackageVersion", "codeartifact:DescribeRepository", "codeartifact:GetPackageVersionReadme", "codeartifact:GetRepositoryEndpoint", "codeartifact:ListPackages", "codeartifact:ListPackageVersions", "codeartifact:ListPackageVersionAssets", "codeartifact:ListPackageVersionDependencies", "codeartifact:ReadFromRepository" ], "Resource": "*" } ] }

For more information, see Delete a policy in the AWS CodeArtifact User Guide.

The following code example shows how to use delete-repository.

AWS CLI

To delete a repository

The following delete-repository example deletes a repository named test-repo in a domain named test-domain.

aws codeartifact delete-repository \ --domain test-domain \ --repository test-repo

Output: