The AWS Toolkit for Visual Studio - Working with .Net Core on Elastic Beanstalk
This topic shows how you can do the following tasks using the AWS Toolkit for Visual Studio:
-
Create an ASP.NET Core web application using a Visual Studio template.
-
Create an Elastic Beanstalk Amazon Linux environment.
-
Deploy the ASP.NET Core web application to the new Amazon Linux environment.
This topic also explores how you can use the AWS Toolkit for Visual Studio to manage your Elastic Beanstalk application environments and monitor your application's health.
The AWS Toolkit for Visual Studio is a plugin to the Visual Studio IDE. With the toolkit you can deploy and manage applications in Elastic Beanstalk while you are working in your Visual Studio environment.
Sections
Prerequisites
Before you begin this tutorial, you need to install the AWS Toolkit for Visual Studio. For instructions, see Setting up the AWS Toolkit for Visual Studio.
If you have never used the toolkit before, the first thing you'll need to do after installing the toolkit is to register your AWS credentials with the toolkit. For more information about this, see Providing AWS Credentials.
Create a new application project
If you don't have a .NET Core application project in Visual Studio, you can easily create one using one of the Visual Studio project templates.
To create a new ASP.NET Core web application project
-
In Visual Studio, on the File menu, choose New and then choose Project.
-
In the Create a new project dialog box, select C#, select Linux, and then select Cloud.
-
From the list of project templates that displays select ASP.NET Core Web Application, and then select Next.
Note
If you don't see ASP.NET Core Web Application listed in the project templates, you can install it in Visual Studio.
-
Scroll to the bottom of the template list and select the Install more tools and features link that is located under the template list.
-
If you are prompted to allow the Visual Studio application to make changes to your device, select Yes.
-
Choose the Workloads tab, then select ASP.NET and web development.
-
Select the Modify button. The Visual Studio Installer installs the project template.
-
After the installer completes, exit the panel to return to where you left off in Visual Studio .
-
-
In the Configure your new project dialog box, enter a Project name. The Solution name defaults to your project name. Next, choose Create.
-
In the Create a new ASP.NET Core web application dialog box, select .NET Core, and then select ASP.NET Core 3.1. From the list of application types that are displayed, select Web Application, then select the Create button.
Visual Studio displays the Creating Project dialog box when it creates your application. After Visual Studio completes generating your application, a panel with your application name is displayed.
Create an Elastic Beanstalk environment and deploy your application
This section describes how to create an Elastic Beanstalk environment for your application and deploy your application to that environment.
To create a new environment and deploy your application
-
In Visual Studio select View, then Solution Explorer.
-
In Solution Explorer, open the context (right-click) menu for your application, and then select Publish to AWS Elastic Beanstalk.
-
In the Publish to AWS Elastic Beanstalk wizard, enter your account information.
-
For Account profile to use, select your default account or choose the Add another account icon to enter new account information.
-
For Region, select the Region where you want to deploy your application. For information about available AWS Regions, see AWS Elastic Beanstalk Endpoints and Quotas in the AWS General Reference. If you select a Region that is not supported by Elastic Beanstalk, then the option to deploy to Elastic Beanstalk is unavailable.
-
Select Create a new application environment, then choose Next.
-
-
On the Application Environment dialog box, enter the details for your new application environment.
-
On the next AWS options dialog box, set Amazon EC2 options and other AWS related options for your deployed application.
-
For Container type select 64bit Amazon Linux 2 v
<n.n.n>
running .NET Core.Note
We recommend you select the current platform version of Linux. This version contains the most recent security and bug fixes that are included in our latest Amazon Machine Image (AMI).
-
For Instance Type, select t2.micro. (Choosing a micro instance type minimizes the cost associated with running the instance.)
-
For Key pair, select Create new key pair. Enter a name for the new key pair, and then choose OK. (In this example, we use
myuseastkeypair
.) A key pair enables remote-desktop access to your Amazon EC2 instances. For more information about Amazon EC2 key pairs, see Using Credentials in the Amazon Elastic Compute Cloud User Guide. -
For a simple, low traffic application, select Single instance environment. For more information, see Environment types
-
Select Next.
For more information about the AWS options that are not used in this example consider the following pages:
-
For Use custom AMI, see Using a custom Amazon machine image (AMI).
-
If you don't select Single instance environment, you need to choose a Load balance type. See Load balancer for your Elastic Beanstalk environment for more information.
-
Elastic Beanstalk uses the default Amazon VPC (Amazon Virtual Private Cloud) configuration if you didn't choose Use non-default VPC. For more information see Using Elastic Beanstalk with Amazon VPC.
-
Choosing the Enable Rolling Deployments option splits a deployment into batches to avoid potential downtime during deployments. For more information, see Deploying applications to Elastic Beanstalk environments.
-
Choosing the Relational Database Access option connects your Elastic Beanstalk environment to a previously created Amazon RDS database with Amazon RDS DB Security Groups. For more information, see Controlling Access with Security Groups in the Amazon RDS User Guide.
-
-
Select Next on the Permissions dialog box.
-
Select Next on the Applications Options dialog box.
-
Review your deployment options. After you've verified your settings are correct, select Deploy.
Your ASP.NET Core web application is exported as a web deploy file. This file is then uploaded to Amazon S3 and registered as a new application version with Elastic Beanstalk. The Elastic Beanstalk deployment feature monitors your environment until it is available with the newly deployed code. The Status for your environment is displayed on the Env:<environment name> tab. After the status updates to Environment is healthy, you can select the URL address to launch the web application.
Terminating an environment
To avoid incurring charges for unused AWS resources, you can use the AWS Toolkit for Visual Studio to terminate a running environment.
Note
You can always launch a new environment using the same version later.
To terminate an environment
-
Expand the Elastic Beanstalk node and the application node. In AWS Explorer open the context (right-click) menu for your application environment and select Terminate Environment.
-
When prompted, select Yes to confirm that you want to terminate the environment. It takes a few minutes for Elastic Beanstalk to terminate the AWS resources running in the environment.
The Status for your environment on the Env:<environment name> tab changes to Terminating and is eventually Terminated.
Note
When you terminate your environment, the CNAME associated with the terminated environment becomes available for anyone to use.