You can return to the original look by selecting English in the language selector
above.

Deploying an ASP.NET Core Application with AWS Elastic Beanstalk

In this tutorial, you will walk through the process of building a new ASP.NET Core
application and deploying it to Elastic Beanstalk.

First, you will use the .NET Core SDK's dotnet command line tool to generate a basic .NET Core command line application, install
dependencies, compile code, and run applications locally. Next, you will create the default Program.cs class, and add an
ASP.NET Startup.cs class and configuration files to make an application that serves HTTP requests with
ASP.NET and IIS.

Finally, Elastic Beanstalk uses a deployment manifest to configure deployments for .NET Core applications, custom
applications, and multiple .NET Core or MSBuild applications on a single server. To
deploy a .NET Core application to a Windows Server environment, you add
a site archive to an application source bundle with a deployment manifest. The dotnet publish command generates compiled classes and
dependencies that you can bundle with a web.config file to create a site archive. The deployment manifest tells Elastic Beanstalk the
path at which
the site should run and can be used to configure application pools and run multiple
applications at different paths.

This tutorial uses a command line ZIP utility to create a source bundle that you can
deploy to Elastic Beanstalk. To use the zip command in Windows,
you can install UnxUtils, a lightweight collection of useful command line utilities like zip and ls. Alternatively,
you can use Windows Explorer or any other ZIP utility to create source bundle archives.

Launch an Elastic Beanstalk Environment

Use the AWS Management Console to launch an Elastic Beanstalk environment. For this
example, you will launch with a .NET platform. After you launch and configure your
environment, you can deploy new source code at any time.

The following procedure shows how to convert the project code into a web application.
To simplify the process, you can generate the project
as a web application right from the start. In the previous section Generate a .NET Core Project, modify the dotnet new step's command with the following command.

C:\Users\username> dotnet new web -o dotnet-core-tutorial

To add ASP.NET and IIS support to your code

Copy Program.cs to your application directory to run as a web host builder.

Add dotnet-core-tutorial.csproj, which includes IIS middleware and includes the web.config file from the
output of dotnet publish.

Note

The following example was developed using .NET Core Runtime 2.2.1. You might need
to modify the TargetFramework or the
Version attribute values in the PackageReference elements to match the version of .NET Core Runtime that you are using
in your custom projects.

To run the application on a web server, you need to bundle the compiled source code
with a web.config configuration file and
runtime dependencies. The dotnet tool provides a publish command that gathers these files in a directory based on the
configuration in dotnet-core-tutorial.csproj.

To build your website

Use the dotnet publish command to output compiled code and dependencies to a folder named site.

C:\users\username\dotnet-core-tutorial> dotnet publish -o site

To deploy the application to Elastic Beanstalk, bundle the site archive with a deployment manifest. This tells Elastic Beanstalk how to
run it.

Choose Choose File and use the dialog box to select the source bundle.

Choose Deploy.

When the deployment completes, choose the site URL to open your website in a new
tab.

The application simply writes Hello from ASP.NET Core! to the response and returns.

Launching an environment creates the following resources:

EC2 instance – An Amazon Elastic Compute Cloud (Amazon EC2) virtual
machine configured to run web apps on the platform that you choose.

Each platform runs a specific set of software, configuration files, and scripts to
support a specific language version, framework, web container, or
combination of these. Most platforms use either Apache or nginx as a reverse proxy
that sits in front of your web app, forwards requests to it, serves
static assets, and generates access and error logs.

Load balancer security group – An Amazon EC2 security group configured to allow inbound traffic on port 80. This
resource lets HTTP traffic from the internet reach the load balancer. By default,
traffic isn't allowed on other ports.

Auto Scaling group – An Auto Scaling group configured to replace
an instance if it is terminated or becomes unavailable.

Amazon S3 bucket – A storage location for your source
code, logs, and other artifacts that are created when you use Elastic Beanstalk.

Amazon CloudWatch alarms – Two CloudWatch alarms that monitor the load on the instances in your environment
and that are
triggered if the load is too high or too low. When an alarm is triggered, your Auto
Scaling group scales up or down in response.

AWS CloudFormation stack – Elastic Beanstalk uses AWS CloudFormation to launch the
resources in your environment and propagate configuration changes. The resources are
defined
in a template that you can view in the AWS CloudFormation
console.

Domain name – A domain name that routes to your
web app in the form
subdomain.region.elasticbeanstalk.com.

All of these resources are managed by Elastic Beanstalk. When you terminate your environment,
Elastic Beanstalk terminates all the resources that it contains.

Note

The Amazon S3 bucket that Elastic Beanstalk creates is shared between environments
and isn't deleted during environment termination. For more information, see Using Elastic Beanstalk with Amazon S3.

In the Confirm Termination dialog box, enter the environment name, and then choose Terminate.

With Elastic Beanstalk, you can easily create a new environment for your application
at any time.

Next Steps

As you continue to develop your application, you'll probably want to manage environments
and deploy your application without manually creating a .zip
file and uploading it to the Elastic Beanstalk console. The Elastic Beanstalk Command Line Interface (EB CLI) provides easy-to-use commands for
creating, configuring, and deploying applications to Elastic Beanstalk environments
from the command line.

If you use Visual Studio to develop your application, you can also use the AWS Toolkit
for Visual Studio to deploy changed, manage your Elastic Beanstalk environments, and
manage other AWS
resources. See The AWS Toolkit for Visual Studio for more information.

For developing and testing, you might want to use the Elastic Beanstalk functionality
for adding a managed DB instance directly to your environment. For
instructions on setting up a database inside your environment, see Adding a Database to Your Elastic Beanstalk Environment.