`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
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.
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.
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.
Create a CodeArtifact Domain
- In the terminal, install Node Version Manager (nvm): curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- Activate nvm: . ~/.nvm/nvm.sh
- Install Node.js version 16: nvm install 16
- Create the demo-domain CodeArtifact domain: aws codeartifact create-domain --domain demo-domain
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
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
- 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.
- 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.
- 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.
- Install a JavaScript library npm package: npm install lodash
- 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
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.
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
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.
Top comments (0)