Click here to Skip to main content
15,884,836 members
Articles / Hosted Services / AWS

Deploying Multiple Web Apps to Elastic Beanstalk

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
20 Apr 2017CPOL4 min read 17.8K   123   1
Deploy an ASP.NET Core and MVC app to same beanstalk server

Introduction

In my organization, we typically install a single web app to a single AWS Elastic Beanstalk server, and that web app is at the root directory [Default Web Site], and the URL ends up being http://instancename. We wanted to deploy several apps to the same box, and thus have http://instancename/app1, http://instancename/app2, etc.

Amazon's blog: https://aws.amazon.com/blogs/developer/multiple-application-support-for-net-and-elastic-beanstalk/ shows a screenshot of example "amazing front end" and "amazing admin" sites, but no sample code. I will present an ASP.NET Core and classic ASP.NET MVC website, deployed to the same Amazon instancename, with working example code.

Using the Code

Refer to prerequisite in "Points of Interest" below.

Run Visual Studio 2015.

New web project, .NET Core, create application called "core", and save to desktop folder.

Run Visual Studio developer command prompt.

C:\Users\username\Desktop\Core\CoreApp\src\CoreApp>dotnet run coreapp

Visit http://localhost:5000 in my browser, to verify it works.

Right click, and deploy to my EB instance, as http://instancename.us-east-1.elasticbeanstalk.com/core.

Verify that it works.

Make a new ASP app, using online template “Dynamic MVC”, added to desktop folder "Asp".

Right click, and deploy to my EB instance, as http://instancename.us-east-1.elasticbeanstalk.com/asp.

Verify that it works.

Amazon's example says to deploy the .NET Core app, and "bring along" the associated ASP.NET app. I therefore choose the core app to be "the parent project" to deploy, and the ASP app to be “the child project”.

Default Visual Studio deploy behavior will try to deploy a global web config with a URL rewrite section. This following step will override this behavior.

Unload each project by right clicking the project name in Visual Studio, clicking "unload", and right clicking again, and clicking "Edit project". In the first <PropertyGroup> you see, insert the following line. You may refer to the enclosed application csproj raw XML to see how it was done in the example app.

XML
<DeployIISAppPath>Default Web Site/sitename</DeployIISAppPath>

Per the article, add the manifest.

Add a JSON formatted file, named “aws-windows-deployment-manifest.json”, to the root directory of the Core csproj. The .NET Core portion, Core, will be designated in the first section “aspNetCoreWeb”. The classic ASP portion, Asp, will be designated in the msDeploy section, in zip file format. My manifest, much like Amazon's example, in the enclosed example application, is shown below. For more manifest information, consult their site: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/dotnet-manifest.html.

Razor
{
  "manifestVersion": 1,
  "deployments": {
    "aspNetCoreWeb": [
      {
        "name": "Core",
        "parameters": {
          "appBundle": "./Core",
          "iisPath": "/Core"
        }
      }
    ],

    "msDeploy": [
      {
        "name": "Asp",
        "parameters": {
          "appBundle": "AspApp.zip",
          "iisPath": "/Asp"
        }
      }
    ]
  }
}

Make the PowerShell as described in the article. Create a .ps1 file as follows. In my example, I add the .ps1 file to the "core" project for housekeeping purposes, but it is not necessary. After all is done, I will be adding all the files to source control, so why not put the deploy script in with the solution you will be deploying?

Go to the directory where the .NET Core site resides in the source tree, to do dotnet publish.

set-location C:\Users\username\Desktop\Core\CoreApp\src\CoreApp

$publishFolder = "c:\temp\publish"

$publishWorkspace = [System.IO.Path]::Combine($publishFolder, "workspace")

If (Test-Path $publishWorkspace){
       Remove-Item $publishWorkspace -Confirm:$false -Force
}

$appBundle = [System.IO.Path]::Combine($publishFolder, "app-bundle.zip")

If (Test-Path $appBundle){
       Remove-Item $appBundle -Confirm:$false -Force
}

Do the dotnet publish.

Write-Host 'Publish the ASP.NET Core frontend' 

$publishFrontendFolder = [System.IO.Path]::Combine($publishWorkspace, "Core")

write-host $publishFrontendFolder

dotnet publish .\project.json -o $publishFrontendFolder -c Release

MSBuild creates the zipped package for Asp. Note the path specified is relative to the Core project directory. Let's be real. In an organization, you very well have the various web site solutions in different parts of your source tree; rarely will you have all websites going to a common server all wrapped within the same solution. So just make your relative path have the right number of ..\..\ in there to reference the other websites to publish.

Write-Host 'Create msdeploy archive for Asp'

msbuild   ..\..\..\Desktop\Core\CoreApp\src\CoreApp.csproj 
/t:package /p:Configuration=Release

Copy-Item ..\..\..\Desktop\Core\CoreApp\obj\Release\Package\Asp.zip $publishWorkspace

The project manifest we created gets copied to the publish folder, along with the two zip files we made from dotnet publish and msbuild.

Write-Host 'Copy deployment manifest'

Copy-Item .\aws-windows-deployment-manifest.json $publishWorkspace

Write-Host 'Zipping up publish workspace to create app bundle'

Add-Type -assembly "system.io.compression.filesystem"

[io.compression.zipfile]::CreateFromDirectory( $publishWorkspace, $appBundle)

Amazon shows more PowerShell steps to automate the deploy of the zip we are about to deploy. However, you can manually deploy the zip file you just made.

Log in to your Amazon console, https://yourname.signin.aws.amazon.com/console

In the “all services” section, click on “elastic beanstalk”, and navigate to your target server. In the "Overview" section, click the "Upload and deploy" button, choose your app-bundle.zip, and deploy.

Points of Interest

Important prerequisite, which I learned the hard way: Start with a perfectly clean install of IIS on your AWS instance. If your server has some apps installed, no problem: just be sure that no web app resides at the root: "default web site" or "c:\inetpub\wwwroot".

If you just right click a web app in Visual Studio, and publish to elastic beanstalk, as the default website on your AWS instance, it will put your code in this default website. If you then follow that app by installing to instancename\site1, you'll get a misleading error message saying you have a duplicate script handler section in web config.

While working this out, and communicating my progress with Amazon support, they admitted the "amazing front end" was indeed only a screen shot. I gave them the enclosed source to use as an example in their online help / documentation, and they liked it, and might publish it! You can say you saw it HERE first! :)

History

  • 19th April, 2017: Initial revision

License

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


Written By
Software Developer (Senior) Ellie Mae
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionPhp Pin
Geet231222-Mar-21 7:13
Geet231222-Mar-21 7:13 

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.