AWS CodeArtifact, NPM, PyPI, Twine, Django & Demo Project.
AWS Code Artifact: Secure, scalable, and cost-effective artifact management
Hi Folks,
Today, I am going to describe the AWS CodeArtifact, and it's important aspects. Starting from theoretical & basic knowledge to the implementation of this service. Implementation includes launching a new Linux VM, installation of pre-requisites, and down the line upstream tool NPM, PyPI & Twine explanation. Also, We will create a Demo Project in Django Server and implement/ understand the AWS CodeArtifact in real-time.
Introduction:
AWS CodeArtifact is a fully managed artifact repository service that makes it easy for organizations of any size to securely store, publish, and share software packages used in their software development process. CodeArtifact works with commonly used package managers and builds tools like Maven and Gradle (Java), npm and yarn (JavaScript), or pip and twine (Python).
The pricing for CodeArtifact is based on usage. There is an “always free” tier with 2GB storage and up to 100,000 requests per month. After that, you will pay $0.05 per GB/month for storage and $0.05 per 10,000 requests. You also pay up to $0.09 per GB for data transferred out.
CodeArtifact Flow Diagram
Pre-requisites for this tutorial:
You should have a basic knowledge of:
- Linux
- Python
- Node
- Django
This entire tutorial will be explained in the below steps:
Step1: AWS Environment Setup
Step 2: Linux & Software installation
Step 3: Connect to your code artifact repo
Step 4: Python installation & PyPI setup
Step 5: Create your own Python Package Twine
Step 6: Artifact creation and upload to AWS Code Artifact
Step 7: Create a new Django Project
Step 8: Verification & conclusion
Let’s START
Now, without making any delay, let’s get our hand dirty with below 8 steps:
Step1: AWS Environment Setup
1. Login to Aws console
2. Create code artifact repo
3. Select Public upstream repositories
a. PyPI
b. NPM
4. Write a domain name
5. Create the repo
Step 2: Linux & Software installation
6. Setup you Linux box
7. Install the prerequisites
a. Python3
b. PIP3
c. AWS CLI version 2.0.21 and newer
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zipsudo ./aws/installaws --version
d. AWS configure
e. IAM User with CodeArtifact permission
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codeartifact:*"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "sts:GetServiceBearerToken",
"Resource": "*",
"Condition": {
"StringEquals": {
"sts:AWSServiceName": "codeartifact.amazonaws.com"
}
}
}
]
}
Step 3: Connect to you code artifact repo
8. Login into your AWS code artifact repository command for NPM
aws codeartifact login --tool npm --repository varunArtifact --domain varunartifact --domain-owner 276701924684
9. Install Node & it prerequisites
yum install tree -ycurl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
Yum install nodejs -ynpm --versionnode --versioncurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bashnvm --versioncd /opt/nvm --versionnvm install --ltsnode --versionnvm -lsyum install gcc-c++ make
10. Create a new NPM Package
nvm use 12npm install -g aws-cdk
11. Install the package
mkdir npm_packagecd npm_package/npm initnpm publishnpm install maniknpm
You will get an error here, so create a new directory and run following command
cd ../mkdir npmtempcd npmcd npmtemp/npm install maniknpmtree
You can find this code on below link:
git clone https://github.com/manikcloud/CodeArtifact-npm.git
Tree view of your code
vim package-lock.json
You can see your package.json with the above command
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"maniknpm": {
"version": "1.0.0",
"resolved": "https://varunartifact-276701924684.d.codeartifact.us-east-1.amazonaws.com:443/npm/varunArtifact/maniknpm/-/maniknpm-1.0.0.tgz",
"integrity": "sha512-Znm5+nCW+wwEqguBpR8a9fGV6gukdUC4Bdx7QiipXOWoR7Z8kjGoTL7DZhrO/5HaPUB3OHEAaougimSWgY2UaA=="
}
}
}
12. Verify your AWS CodeArtifact Repository with newly created package
PYTHON PyPI
Step 4: Python installation & PyPi setup
13. Install Python 3 from Miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.shsh Miniconda3-latest-Linux-x86_64.sh
14. Login in to your AWS code artifact repository command PyPI
aws codeartifact login --tool pip --repository pypi-store --domain varunartifact --domain-owner 276701924684
15. Install a Django Package
pip install django==2.2
16. Verify your Django package in AWS code artifact
Step 5: Create your own Python Package Twine
17. Log in with twine in you was code artifact & create projects
aws codeartifact login --tool twine --repository pypi-store --domain varunartifact --domain-owner 276701924684mkdir projectscd projects
18. Clone your GitHub repository
git clone https://github.com/manikcloud/AwsCodeArtifact
19. Build your artifacts
python setup.py sdist bdist_wheel
Step 6: Artifact creation and upload AWS Code Artifact
20. Install twine package
pip install twine
21. Upload your build artifact into AWS code artifact
twine upload --repository codeartifact dist/manik_notebookc-1.1.3.tar.gz
22. Verify your Python package in AWS console with new Artifacts
Step 7: Create a new Django project
23. Start a Django project
django-admin startproject djangocodecd djangocode/
24. Clone the Github repo from Github & make necessary changes
https://github.com/manikcloud/AwsCodeArtifact/tree/master/djangocode
25. Run You Django Server on your Linux box
python manage.py runserver 0.0.0.0:8080
Step 8: Verification
26. Verify your version on you AWS console
27. Verify your version on your browser
Step 9: Verify with New version of your Artifact
28. Update your code artifact with the new version of packages
29. Upload into the AWS code artifacts
30. Install your new packages from AWS CodeArtifact
twine upload --repository codeartifact dist/manik_notebookc-1.1.4.tar.gz
pip install manik-notebookc==1.1.4python manage.py runserver 0.0.0.0:8080
31. Verify your version of your code on your AWS console
32. Verify your version of your code on your Browser.
Conclusion:
I have successfully shown you, all the steps for setup AWS Code Artifact, Linux box & pre-requisites software installation, and step by step implementation of a demo project on Django Framework.
For more info please connect & Follow me:
LinkedIn: https://www.linkedin.com/in/vkmanik/
Email: varunmanik1@gmail.com
Facebook: https://www.facebook.com/cloudvirtualization/
YouTube: https://bit.ly/32fknRN
Github:
Twitter: https://twitter.com/varunkmanik
References: