Getting the application running on AWS

Let's see what needs to be done before you can see the Tic-Tac-Toe application running in AWS, as follows:

  1. Open the Package Manager Console in Visual Studio 2019 and execute the Script-Migration instruction, as shown here:

  1. Take the generated script and copy it into a query window for the Amazon RDS database, then execute the script to create the database and the various database objects.
  2. Download and install the AWS Toolkit for Visual Studio 2017 and 2019 from https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.AWSToolkitforVisualStudio2017, as shown in the following screenshot (if you are using Visual Studio Code, you can also get an AWS Toolkit for Visual Studio Code from https://aws.amazon.com/visualstudiocode/):

  1. Go to the AWS Management Console, enter IAM in the AWS services textbox, and click on the displayed link; you will be redirected to the Amazon Identity and Access Management (IAM) page, as shown in the following screenshot:

  1. On the Amazon Identity and Access Management (IAM) page, click on Create individual IAM Users and then on Manage Users and click the Add user button, as shown in the following screenshot:

  1. On the Add user page, give the new user a meaningful username and grant them Programmatic access, then click on the Next: Permissions button at the bottom of the page, as shown in the following screenshot:

  1. You now have to set the permissions for the new user; for that, click on the Attach existing policies directly button, as shown in the following screenshot:

  1. Select AdministratorAccess from the existing policies and click on the Next: Tags button at the bottom of the page, as shown in the following screenshot:

  1. We can ignore tags for now, since we don't intend to have many users, and just go to Next: Review and verify that the User name and AWS access type, as well as the selected policies, are correct, then click on the Create user button, as shown in the following screenshot:

  1. Wait for the new user to be created; when the success page is displayed, you can then download the .csv file, which we will use to configure Visual Studio 2019 with AWS, as shown in the following screenshot:

  1. Open Visual Studio 2019 and display AWS Explorer by going to View | AWS Explorer, as shown in the following screenshot:

  1. Click on the New account profile button (the only active button), as shown in the following screenshot:
  1. A wizard will be displayed; leave the Profile Name as default and fill in the Access Key ID and Secret Access Key fields with the values coming from the .csv file you have downloaded before, during the new user creation process on AWS, as shown in the following screenshot:

  1. Since AWS is based on IIS as the host for .NET Core applications, you now have to add a web.config file to the TicTacToe application, which specifies the IIS web server properties. The handlers, which are meant to process external requests and give a response, are assigned aspNetCore attributes and are set to allow all HTTP verbs such as GET, POST, PUT, DELETE, and many others. The processing path for the aspNetCore instance is assigned with the our dll path, and we also make sure that Windows authentication is supported, by setting the forwardWindowsAuthToken attribute to true, as shown in the following code block:
        <?xml version="1.0" encoding="utf-8"?> 
        <configuration> 
          <system.webServer> 
            <handlers> 
              <add name="aspNetCore" path="*" verb="*"
modules="AspNetCoreModule"
resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet"
arguments=".TicTacToe.dll"
stdoutLogEnabled="true"
stdoutLogFile=".logsstdout"
forwardWindowsAuthToken="true" /> </system.webServer> </configuration>
  1. Furthermore, we have to enable IIS integration. For us to do that, we open the Program.cs file and change the WebHost builder configuration to enable IIS integration, by adding webBuilder.UseIISIntegration(), as follows:
        public static IHostBuilder CreateHostBuilder(string[]
args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.CaptureStartupErrors(true);
webBuilder.PreferHostingUrls(true);
webBuilder.UseUrls("http://localhost:5000");
webBuilder.ConfigureLogging((hostingcontext,
logging) =>
{
logging.AddLoggingConfiguration(
hostingcontext.Configuration);
});
webBuilder.UseIISIntegration();
});
  1. Right-click on the TicTacToe project and click on Publish to AWS Elastic Beanstalk... in the context menu, as shown in the following screenshot:

  1. A wizard will be displayed; click on Create a new application environment and click on the Next button, as shown in the following screenshot:

  1. You have three options for the environment—whether dev, test, or production—but select the default environment you have created before, then click on the Next button, as shown in the following screenshot:

  1. Verify that the Framework version is set to netcoreapp3.0, signifying an ASP.NET Core 3 application, and leave all default values, then click on the Next button, as shown in the following screenshot:

  1. Select Generate AWSDeploy configuration, which will allow you to redeploy a copy of your application with AWS, then click on the Deploy button, as shown in the following screenshot:

  1. The deployment will start; you can see the advancement of the deployment process by going to Output | Amazon Web Services, as shown in the following screenshot:  
  1. When the application is deployed, you can use AWS Explorer to get the URL of the application, as follows:
  1. Open a browser and go to the application URL in AWS, start the application, and try to register a new user.
Note that if the application is not working as expected, you will get a 404 Not Found HTTP response. Everything is working locally and the deployment in AWS was successful, but something is wrong. You will see in the next chapter, which is about logging and monitoring, how to analyze, diagnose, understand, and fix this problem.

Congratulations—you have successfully deployed your first application in the public cloud. It is now available to the outside world, and users can connect to it and start working with it.

This concludes the examples in relation to AWS. However, we still have some compelling content, since we will explore how to deploy to other targets, such as Microsoft Azure and Docker containers, in the next sections; so, stay sharp, and continue reading the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.31.11