<jupyter_start><jupyter_text>Into To Deploying App To AWSSince there is so much to know about AWS, this will mostly focus on a specific use case:_How to get your app up & running on a server on the internet  so you can test it with friends & family._We will use the **AWS Free Tier**. We will be creating a new server on AWS, deploying our code, & configuring the server to make it available on the internet.You will need to sign up for the AWS free tier [here](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all).  Add Key Pair to AWSIn thsi section, we will add an SSH key pair to AWS. This will be done so that when we create our server, we can connect to it using SSH authentication. This is the same method of authentication used to connect to GitHub.In prior vieo we created an SSH key paid on our local machine. We will now be using the public key to add to AWS insetad of GitHub. Output the content of public key pairIf you don't have your SSH yet, follow the instructions [here](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys).1. Open **git bash** or terminal window - NOT on the vagrant server2. Run:  `cat ~/.ssh/id_rsa.pub`    Be sure to copy everything - including the email.        3. After logging into AWS console, go into the **Services** option and **EC2**. This si where the key pairs can be added for use on server instances.4.  Under **Network & Security** go to **Key Pairs**. If you don't already see it, click on the **Actions** drop down and select **Import key pair**.5. Give it a name you'll remember (and if using more than one machine, ensure you can tell the difference). Then paste the output of your RSA data in the box.6. Click **Import Key** to successfully import the key.  Create EC2 Server InstanceThis EC2 server instance will run our project. This _instance_ is a virtual machine that you can spin up and & connect to in order to deploy your application.1. Open AWS console & select EC2 - if you are not already in the **EC2 Dashboard** be sure to click there. This is where you will find all of your EC2 server instances.2. Click on **Launch instance** to create a new instance. If you are using the free tier 12 month period, you should not be charged as long as you use the options for the free tier. 3. Give your instance a name. In the **Aplication and Os Images (Amazon Machine Image)** section, click the **Browse more AMIs** and then locate the one mentioned [here](https://gist.github.com/LondonAppDev/d195610d79c9cca1769b6b5fece09067) (`Ubuntu Server 18.04`).    Then click **Select** button.     4. Be sure to choose the **micro** instance if it's not chosen already. (2nd one down.)5. Choose your key pair for login using the one you just added. 6. In the **Network settings** area, be sure to check **_Allow HTTP traffic from the internet7. Click the **Launch instance** button. You should now see a screen similar to:At this point, you can set up billing alerts if oyu wish to know when you are coming close to your free tier limits.  [Add Deployment Script & Configs To Project](https://www.udemy.com/course/django-python/learn/lecture/7371366questions) Add Files To Project1. Download the **deploy.zip** file [here](https://drive.google.com/file/d/1axRytyrpIAUN5K_LOyMnIlr5ZwdXBglV/view). Thsi file contains a ZIp of all the scripts & configuration files needed to deploy the project. (We'll add the contents of this to our project.)2. Unzip the downloaded ZIP & copy the _deploy directory_ into your profiles REST API project: Review Of FilesIn Atom, you should now see something like this: setup.shThis script that will be used to setup th server when it's first created. Please note that an updated version should be found [here](https://gist.github.com/LondonAppDev/7090d8097553ab82209adb1809304d0e).Need to update the project URL for your GitHub project. This is because the script will clone the contents of our project to the server when we run it. You can find the correct URL on the GitHub site under the **Code** drop down:This URL needds to be in the **PROJECT_GIT_URL** variable.The **PROJECT_BASE_PATH** is where the project will be kept on the AWS server.In the **apt-get install** we will install:- git:  clone the project- nginx:  the web server that will serve the static files & act as a proxy to our uWSGI service that will run in **supervisor**Other installations:- uwsgi:  Python daemon for running python code as a web serverThe `manage.py collectstatic --noinput` will collect all of the static files for all of the apps in our project into one directory. When you use the Django management server, it does this automatically for you. But since we're not going to be using the Django DEV server on PROD, we need to create a location with all of the static files we can use to serve the CSS & JavaScript for the Django admin & REST framework browseable API.Configuring the **supervisor** - an app on linux that allows you to manage processes. Thsi is what will manage our Python process or our uWSGI server.  update.shThis script will be used to update the code on the server when we make a change. Once the server is setup, **setup.sh** will only work once. You'll then need to use the **update.sh** script to pull updates or changes from git onto the server.  Update settings.pyIn the project folder, you'll need to update the **setings.py** file for it to run better on the server. Here are the settings changes to be made:1. Disable DEBUG mode, as it is best practice to nbever run in DEBUG mode when it is publicly accessible. If you leave it as `True`, it opens you up to vulnerabilities. Running in DEBUG mode means that if there are any errors or exceptions in the API it will return a full stack trace on the screen. This can reveal secret information like the Django secret file or other things making your server vulnerable.    Since we want to run DEBUG on vagrant DEV server but not on AWS, replace `DEBUG = True` with:<jupyter_code>DEBUG = bool(int(os.environ.get('DEBUG', 1)))  # the 1 is for if "DEBUG" doesn't exist<jupyter_output><empty_output><jupyter_text>This will pull in the value of the environment variable called DEBUG. This environment variable is set in the **supervisor_profiles_api.conf** file. When **DEBUG=0**, this sets the debug environment variable to 0 when we run our application.2. Need to add a static route to the bottom of your configuration.<jupyter_code>STATIC_ROOT = 'static/'<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06688861985472155, 'fraction_numerical': 0.014527845036319613, 'mean_word_length': 4.355753646677472, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 6, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '458211', 'license': 'MIT', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1703, 'n_words': 1016, 'path': 'REST/Udemy-Django-Python/Django REST Course - 12 Deploying API to AWS Server.ipynb', 'repo_name': 'ProsperousHeart/TrainingUsingJupyter', 'size': '6608'}