There are more AWS SDK examples available in the AWS Doc SDK Examples
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-connectionexample adds an external connection to npmjs.com to a repository named test-repo.aws codeartifact associate-external-connection \ --repositorytest-repo\ --domaintest-domain\ --external-connectionpublic:npmjsOutput:
{ "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.
-
For API details, see AssociateExternalConnection
in AWS CLI Command Reference.
-
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-versionsmoves 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 \ --domaintest-domain\ --source-repositorymy-repo\ --destination-repositorytest-repo\ --formatnpm\ --packagetest-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.
-
For API details, see CopyPackageVersions
in AWS CLI Command Reference.
-
The following code example shows how to use create-domain.
- AWS CLI
-
To create a domain
The following
create-domainexample creates a domain named test-domain.aws codeartifact create-domain \ --domaintest-domainOutput:
{ "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-repositoryexample creates a repository named test-repo inside a domain named test-domain.aws codeartifact create-repository \ --domaintest-domain\ --domain-owner111122223333\ --repositorytest-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.
-
For API details, see CreateRepository
in AWS CLI Command Reference.
-
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-policyexample deletes the permission policy from a domain named test-domain.aws codeartifact delete-domain-permissions-policy \ --domaintest-domainOutput:
{ "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.
-
For API details, see DeleteDomainPermissionsPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use delete-domain.
- AWS CLI
-
To delete a domain
The following
delete-domainexample deletes a domain namedtest-domain.aws codeartifact delete-domain \ --domaintest-domainOutput:
{ "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-versionsexample deletes version 4.0.0 of a package named test-package.aws codeartifact delete-package-versions \ --domaintest-domain\ --repotest-repo\ --formatnpm\ --packagetest-package\ --versions4.0.0Output:
{ "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.
-
For API details, see DeletePackageVersions
in AWS CLI Command Reference.
-
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-policyexample deletes the permission policy from a repository named test-repo.aws codeartifact delete-repository-permissions-policy \ --domaintest-domain\ --repositorytest-repoOutput:
{ "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.
-
For API details, see DeleteRepositoryPermissionsPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use delete-repository.
- AWS CLI
-
To delete a repository
The following
delete-repositoryexample deletes a repository namedtest-repoin a domain namedtest-domain.aws codeartifact delete-repository \ --domaintest-domain\ --repositorytest-repoOutput: