DEV Community

Ameh Mathias Ejeh
Ameh Mathias Ejeh

Posted on

1 1 1 1 1

Setting Up CodeArtifact from the CLI

`Introduction
This hands-on lab walks you through how to create CodeArtifact domains and repositories, and then populate the repositories using the AWS Command Line Interface.

Scenario

Image description

I am going to use the command line interface to set up CodeArtifact. First, I will create a CodeArtifact domain, a CodeArtifact repository, and an upstream repository. Then, I will connect to a public repository and install the necessary packages.

Lab Objectives

  • Create an EC2 instance.
  • Create access keys for cloud_user.
  • Run aws configure.
  • Install nvm and Node.js.
  • Create a CodeArtifact domain.
  • Create a CodeArtifact repository.
  • Create an upstream repository.
  • Create a connection to the public npm repository.
  • Associate the npm repository to the main repository.
  • Configure the npm package manager with the main repository.
  • Install the necessary npm packages.
  • View the installed packages.
  • Review CodeArtifact in the AWS Management Console.
  • Delete all resources.

Prepare the AWS Environment

Prepare the EC2 Instance

  • Navigate to EC2.
  • In the Launch instance section of the dashboard, use the Launch instance dropdown to select Launch instance.
  • Fill in the instance details: Name: CodeArtifactDemo. Application and OS Images (AMI): Amazon Linux Instance type: t3.micro.
  • In the Network settings section, click Edit on the right.
  • In the Auto-assign public IP field, use the dropdown to select Enable.
  • Leave all other default settings, and click Launch instance.
  • In the Create key pair dialog, select Proceed without key pair, and then click Proceed without key pair to confirm.
  • Click Launch instance again.

Image description

Prepare the Access Key

  • After the instance is successfully launched, navigate to IAM.
  • In the sidebar menu, navigate to Access management and then select Users.
  • From the Users list, select the cloud_user user name. From the user details, select the Security credentials tab.
  • In the Access keys section, click Create access key. Select Command Line Interface (CLI).
  • Check the I understand the above recommendation checkbox toward the bottom of the page, and then click Next.
  • Leave the tag section blank and click Create access key.
  • Leave this tab open so you can refer back to your access key when you need it.

Image description

Prepare the AWS CLI Environment

  • In a new browser tab, navigate to EC2.
  • From the EC2 dashboard, select Instances (running).
  • Check the checkbox next to the CodeArtifactDemo instance and then click connect
  • Click Connect again.
  • In the terminal, set up your AWS CLI installation: aws configure
  • When prompted for the access key, navigate back to your IAM Management Console tab and copy your access key.
  • Navigate back to your EC2 Instance Connect tab and paste your copied access key into the terminal.
  • When prompted for the secret key, navigate back to your IAM Management Console tab and copy your secret access key.
  • Navigate back to your EC2 Instance Connect tab and paste your copied secret access key into the terminal.
  • Enter the default Region name: us-east-1
  • When prompted for the default output format, press Enter.

Image description

Create a CodeArtifact Domain

Image description

Create a Repository within the Domain

  • Create a demo-repo repository within the demo-domain CodeArtifact domain aws codeartifact create-repository --domain demo-domain --domain-owner 974009255478 --repository demo-repo

Image description

Create an Upstream Repository

  • Create an npm-store repository within the demo-domain CodeArtifact domain: aws codeartifact create-repository --domain demo-domain --domain-owner 974009255478 --repository npm-store

Image description

  • Link the npm-store repository with the public npm repository aws codeartifact associate-external-connection --domain demo-domain --domain-owner 974009255478 --repository npm-store --external-connection "public:npmjs"
  • This will allow you to pull packages from the public repository.

Image description

  • Make npm-store an upstream repository to demo-repo aws codeartifact update-repository --repository demo-repo --domain demo-domain --domain-owner 974009255478 --upstreams repositoryName=npm-store
  • This allows demo-repo to inherit packages from npm-store.

Image description

  • Configure npm in demo-repo aws codeartifact login --tool npm --repository demo-repo --domain demo-domain --domain-owner 974009255478
  • You should see a message indicating that npm was successfully configured to use the demo-repo repository.

Image description

  • Install a JavaScript library npm package: npm install lodash

Image description

  • Install the express, eslint, and mongo packages: npm install express eslint mongo
  • List the packages in demo-repo: aws codeartifact list-packages --domain demo-domain --repository demo-repo

Image description

Validate and Clean Up Resources
Verify the packages in the AWS Management Console:

  • Navigate back to the IAM Management Console tab, and then navigate to CodeArtifact.
  • In the sidebar menu, navigate to Artifacts and then select Domains.
  • Select the demo-domain domain name.
  • View the contents of each repository one at a time.

Image description

Attempt to delete demo-domain:

  • Navigate back to demo-domain.
  • On the right, click Delete domain.
  • When prompted, type delete into the text field to confirm the deletion, and then click Delete.
  • You should see a warning that the domain must contain 0 repositories before deletion

Image description

Delete the repositories:

  • Select one of the repository names.
  • On the right, click Delete repository.
  • When prompted, type delete into the text field to confirm the deletion, and then click Delete.
  • Repeat the process to delete any remaining repositories. Attempt to delete demo-domain again:
  • Navigate back to demo-domain.
  • On the right, click Delete domain.
  • When prompted, type delete into the text field to confirm the deletion, and then click Delete.
  • This time, the deletion should be successful.

Image description

Billboard image

Synthetic monitoring. Built for developers.

Join Vercel, Render, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay