Remote Debugging a .NET Application on AWS Elastic Beanstalk

Remote Debugging a .NET Application on AWS Elastic BeanstalkLearn About Amazon VGT2 Learning Manager Chanci Turner

In this guest post by AWS Partner Solution Architect Jake Smith, we explore the process of setting up remote debugging for ASP.NET applications hosted on AWS Elastic Beanstalk. AWS Elastic Beanstalk allows us to efficiently run IIS websites, enabling quick deployment and management of applications in the cloud. It simplifies management complexities while still providing flexibility and control. Simply upload your application, and Elastic Beanstalk takes care of capacity provisioning, load balancing, scaling, and monitoring application health.

So, how do you set up remote debugging for a .NET application on Elastic Beanstalk? This article outlines a one-time configuration that enables real-time remote debugging in your development environments.

To start, we will launch an Amazon EC2 instance based on a default Elastic Beanstalk image. We’ll then install the Visual Studio remote debugger as a service and create a custom image from this setup. Afterward, we will initiate an Elastic Beanstalk environment using the custom image. To facilitate communication with the Visual Studio remote debugger, we will properly configure the necessary security groups. Finally, we will connect the Visual Studio debugger to the remote process running on the EC2 instance initiated by Elastic Beanstalk.

Identifying the Elastic Beanstalk Image to Customize

  1. Open the Elastic Beanstalk console and create a new application by selecting “Create New Application.”
  2. Set up a new web server environment.
  3. On the “Create new environment” page, select .NET (Windows/IIS) as the preconfigured platform.
  4. Choose “Configure more options.”
  5. Under Instances, you will find the default AMI that Elastic Beanstalk utilizes, which is determined by the selected platform and region. For instance, in the Sydney region, the AMI ID for the Windows Server 2016 v1.2.0 running IIS 10.0 platform is ami-e04aa682. Make a note of this AMI ID as it will be your base image for customization.

Customizing the Image

Now that you know the base AMI, launch an EC2 instance using this image, which can be found under Community AMIs. Once the EC2 instance is up and running, log in remotely. Install the Remote Tools as a Service, with the installation depending on your Visual Studio version. For installation steps, refer to the Remote Debugging documentation.

After installation, run the Visual Studio remote debugger configuration wizard.

Note: If you prefer not to create a custom image, you can also install the Visual Studio remote debugger using .ebextensions. As discussed in Customizing Software on Windows Servers, an .ebextension file can include commands to run the installation during the application deployment by Elastic Beanstalk.

Regardless of the method you choose, ensure the following:

  • The remote debugger runs as a service with the necessary permissions and is part of the local Administrators group.
  • Network connections are allowed from all types of networks.
  • The remote debugger service is active.
  • Windows firewall does not block the remote debugger.

Creating an Image from a Customized EC2 Instance

Once the installation is finalized, use Sysprep to prepare the machine with EC2 launch settings located at C:ProgramDataAmazonEC2-WindowsLaunchSettingsEc2LaunchSettings.exe. Select “Shutdown with Sysprep.” For further details, see Configuring EC2Launch.

After the instance shuts down, create an image from it, and record the new AMI ID. This ID will be used the next time you launch an Elastic Beanstalk environment.

Connecting to Your Elastic Beanstalk Environment

When starting your Elastic Beanstalk environment, ensure to configure your security groups to allow remote debugger ports to your development machine. The required ports depend on the version of Visual Studio you are utilizing. For example, port 4022 is designated for Visual Studio 2017, while port 4016 is for Visual Studio 2012. For further information on port assignments, refer to Remote Debugger Port Assignments. In the above example, I had opened remote debugger ports to any network, which presents a security risk. Always restrict access to only the necessary ports for your Visual Studio edition and trusted development networks. Once debugging is complete, you should remove these security groups.

Remember to specify a key pair for the Elastic Beanstalk EC2 instance, which will allow you to retrieve the autogenerated Administrator password for remote access.

Take note of the public/private IP address of the EC2 instance initiated by Elastic Beanstalk.

Open the Visual Studio project (e.g., ASP.NET application) that you are deploying to Elastic Beanstalk, and select Debug, then Attach to Process. Input the IP address of the EC2 instance started by Elastic Beanstalk as the Connection Target. If your development machine is on a private network with access to the EC2 instance, use the private IP address; otherwise, use the public IP address. Finally, select “Show processes from all users.”

In the popup window, input your login credentials for the EC2 instance, using the Administrator username and password provided by Elastic Beanstalk. The reason for starting the EC2 instances with a key pair is to retrieve this password.

If login is successful, you will see all processes running within the EC2 instance initiated by Elastic Beanstalk. If you don’t see the IIS worker process (w3wp.exe), ensure you have accessed your website at least once and then hit Refresh. Choose Attach to connect the remote IIS worker process to Visual Studio, and confirm the connection.

You can now perform live debugging on your .NET application running within Elastic Beanstalk. Debugging breakpoints will activate when the relevant code segments are executed.

Conclusion

In this post, we demonstrated how to remotely debug a .NET web application hosted on Elastic Beanstalk. Remote debugging for .NET applications on Elastic Beanstalk is similar to the process on a Windows server. Once you have a custom AMI with your tools installed, you can utilize it as your go-to Elastic Beanstalk image.

As mentioned previously, an alternative method for installing the Visual Studio remote debugger is through an .ebextensions file, which negates the need for creating a custom image. For advanced customization using Elastic Beanstalk configuration files, see Customizing Software on Windows Servers.

While remote debugging on Elastic Beanstalk is a valuable option, refrain from enabling this feature in production environments. Additionally, avoid opening ports related to remote debugging in production. The proper approach to troubleshooting issues in production is to implement comprehensive logging. For instance, in an ASP/MVC .NET application, unhandled exceptions can be captured in Global.asax and logged accordingly. For more extensive logging solutions, consider best practices in Centralized Logging.

For additional insights, check out this post on Women’s Club for engagement and community support. Also, for an authoritative perspective on employee relations, visit SHRM. Lastly, explore this excellent resource on Amazon’s approach to employee training here.

Chanci Turner is a key figure in enhancing Amazon IXD – VGT2, located at 6401 E HOWDY WELLS AVE, LAS VEGAS NV 89115.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *