Click here to Skip to main content
15,881,867 members
Articles / Hosted Services / AWS

Deploy ASP.NET Core Application on EC2 Amazon Linux Instance

Rate me:
Please Sign up or sign in to vote.
4.93/5 (6 votes)
10 Feb 2017CPOL3 min read 38.9K   11   2
Step by step guide to deploy ASP .NET core web application on Amazon Linux Instance

Introduction

ASP.NET Core is an open-source and cross-platform framework for developing web applications and mobile backend. ASP.NET Core being cross-platform framework it provides flexibility to develop and run applications on Windows, Linux and Mac.

There are multiple ways to deploy application on AWS EC2 Linux Instance. I will post about AWS code pipeline which can be used to automate deployment process and install application on EC2 Instance some other day, for now we will focus on deploying ASP.NET core web application on Amazon Linux instance.

Image 1

Step 1 - Build ASP.NET Core Application

Develop your own ASP .NET core Application from scratch. Alternatively, you can also use sample application on GitHub for this demo.

Step 2 - Provision EC2 Instance using Amazon Linux AMI

Provision a t2.micro instance using Amazon Linux AMI as it is eligible for Free Tier Usage for 12 months.

  • Logon to AWS console and launch Amazon Linux EC 2 Instance

    Image 2

  • Follow through steps on Launch Instance wizard and configure inbound rules to allow HTTP and SSH Protocol. Ensure while deploying real time production application you lock down security on SSH protocol to allow access from desired source only. Leaving source as 0.0.0.0/0 gives access to everyone.

Image 3

 

  • Create and download new Key Pair. In case you have already created key pair, make sure you have access to .pem file. You will need .pem in below steps to generate ppk file and logon to EC2 instance.
  • Launch EC2 instance and note Public IP showed on EC2 Dashboard. You will need Public IP to SSH in to EC2 Instance.

Step 3 - Configure PuTTY to SSH in Linux EC2 Instance from Windows

  • Download Putty and PuttyKeyGen from putty download page and configure PuTTY.
  • Load downloaded pem file and click on save private key to generate private key (.ppk) file without passphrase.

    Image 4

  • Specify generated ppk file path in PuTTY Configuration for Authenticating.

    Image 5

  • Specify username and public IP to SSH EC2 instance User name will be ec2-user@<Public IP Address>.

    Image 6

Step 4 - Install Git, Apache and .NET Core on Linux EC2 Instance

  • Elevate permission for installation using sudo su command:

    Image 7

  • Run below commands to install Appache and Git:
    C#
    yum install httpd
    
    yum install git
  • Execute below commands on terminal in sequence to download and Install .NET Core:
    sudo yum install libunwind libicu
    curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=835019
    sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
    sudo ln -s /opt/dotnet/dotnet /usr/local/bin

    Refer to https://www.microsoft.com/net/core#linuxcentos steps described for installing .NET Core on CentOS 7.1 also work for Amazon Linux Instance.

  • Exit from sudo mode and run dotnet command to verify the installation:

    Image 8

Step 5 - Configure Reverse Proxy so that All Incoming Requests are Passed to kestrel Server

  • Elevate permissions to edit httpd.conf file and make below changes:
    XML
    <VirtualHost *:80>
        ProxyPass / https://127.0.0.1:5000/
        ProxyPassReverse / https://127.0.0.1:5000/
    </VirtualHost>
  • Restart httpd service:
    sudo service httpd restart

    For more information on why we need reverse proxy, refer to https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction.

Step 6 - Compile and Launch .NET Core Application on Linux EC2 Instance

Execute the below command to compile and Launch application:

dotnet restore

dotnet run

Browse deployed application through public DNS name displayed on EC2 Dashboard. Sample Application display's OS, Frame and Environment variables set on EC2 Instance.

Image 9

References

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Australia Australia
Vipul is a senior .NET Developer with 14 years of experience in Requirement elicitation, Web Application Development, project execution using SCRUM methodology

Vipul is proficient in architecting and hands on with web applications development by applying various Design Patterns and SOLID principles using Microsoft Programming Languages and technology stack.
Over the years he has gained solid experience in building enterprise application with highest level of quality and customer satisfaction

Comments and Discussions

 
QuestionSteps 4 and 5 not clear Pin
Member 132980946-Jul-17 23:50
Member 132980946-Jul-17 23:50 
GeneralMy vote of 4 Pin
HenriSardou2-Jan-17 20:26
HenriSardou2-Jan-17 20:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.