Skip to content

Commit

Permalink
Merge pull request #1407 from dawidborycki/LP-NetAspire
Browse files Browse the repository at this point in the history
LP on .NET Aspire deployment to Arm-powered AWS EC2 and GCP
  • Loading branch information
pareenaverma authored Dec 16, 2024
2 parents 7fb076c + c543746 commit 6af0813
Show file tree
Hide file tree
Showing 26 changed files with 556 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Using Arm-powered Virtual Machines in Amazon Web Services and Google Cloud Platform for running .NET Aspire applications

minutes_to_complete: 60

who_is_this_for: This learning path is for software developers interested in learning how to deploy .NET Aspire applications in AWS and GCP

learning_objectives:
- Learn about the .NET Aspire.
- Create a project and deploy it to the ARM-powered Virtual Machines in the Cloud.

prerequisites:
- A Windows on Arm computer such as [Windows Dev Kit 2023](https://learn.microsoft.com/en-us/windows/arm/dev-kit), a Lenovo Thinkpad X13s running Windows 11 or a Windows on Arm [virtual machine](/learning-paths/cross-platform/woa_azure/).
- Any code editor. [Visual Studio Code for Arm64](https://code.visualstudio.com/docs/?dv=win32arm64user) is suitable.

author_primary: Dawid Borycki

### Tags
skilllevels: Introductory
subjects: Cloud
cloud_service_providers: AWS, GCP

armips:
- Neoverse

tools_software_languages:
- .NET
- C#
- Visual Studio Code

operatingsystems:
- Windows
- Linux


### FIXED, DO NOT MODIFY
# ================================================================================
weight: 1 # _index.md always has weight of 1 to order correctly
layout: "learningpathall" # All files under learning paths have this same wrapper
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# ================================================================================
# Edit
# ================================================================================

next_step_guidance: >
You can continue learning about how to deploy serverless applications using the Serverless Framework and AWS.
# 1-3 sentence recommendation outlining how the reader can generally keep learning about these topics, and a specific explanation of why the next step is being recommended.

recommended_path: "/learning-paths/servers-and-cloud-computing/serverless-framework-aws-lambda-dynamodb"
# Link to the next learning path being recommended(For example this could be /learning-paths/servers-and-cloud-computing/mongodb).


# further_reading links to references related to this path. Can be:
# Manuals for a tool / software mentioned (type: documentation)
# Blog about related topics (type: blog)
# General online references (type: website)

further_reading:
- resource:
title: .NET Aspire Overview
link: https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview
type: Documentation
- resource:
title: Compute Service - Amazon EC2
link: https://aws.amazon.com/pm/ec2
type: Documentation
- resource:
title: Compute Service - Google GCP
link: https://cloud.google.com/products/compute/
type: Documentation


# ================================================================================
# FIXED, DO NOT MODIFY
# ================================================================================
weight: 21 # set to always be larger than the content in this path, and one more than 'review'
title: "Next Steps" # Always the same
layout: "learningpathall" # All files under learning paths have this same wrapper
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
review:
- questions:
question: >
Which command do you use to install the Aspire workload on an Arm-powered VM?
answers:
- sudo apt install aspire
- dotnet workload install aspire
- dotnet install aspire --arm64
correct_answer: 2
explanation: >
The correct command to install the Aspire workload is `dotnet workload install aspire`, as it uses the .NET CLI to manage workloads.
- questions:
question: >
When creating an AWS EC2 instance, which step ensures secure remote access to the VM?
answers:
- Creating a new key pair in the "Key pair (login)" section
- Selecting the appropriate security group for the instance
- Allowing HTTP and HTTPS traffic in the network settings
correct_answer: 1
explanation: >
Creating a new key pair in the "Key pair (login)" section generates a private key file that is essential for secure SSH access to the EC2 instance.
- questions:
question: >
In Google Cloud Platform, what series should you select to use an Arm64 processor for your VM?
answers:
- T2A (Ampere Altra Arm)
- E2 (General Purpose)
- N2D (Compute Optimized)
correct_answer: 1
explanation: >
The T2A series (Ampere Altra Arm) is designed specifically for Arm64 processors and provides cost-effective, high-performance computing in GCP.
# ================================================================================
# FIXED, DO NOT MODIFY
# ================================================================================
title: "Review" # Always the same title
weight: 20 # Set to always be larger than the content in this path
layout: "learningpathall" # All files under learning paths have this same wrapper
---
136 changes: 136 additions & 0 deletions content/learning-paths/servers-and-cloud-computing/net-aspire/aws.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: Deploy to AWS EC2
weight: 4

### FIXED, DO NOT MODIFY
layout: learningpathall
---

### Objective
The goal of this task is to deploy a .NET Aspire application onto an AWS Virtual Machine (using Amazon Elastic Compute Cloud (EC2)) powered by Arm-based processors, such as AWS Graviton. This involves leveraging the cost and performance benefits of Arm architecture while demonstrating the seamless deployment of cloud-native applications on modern infrastructure.

Amazon Elastic Compute Cloud (EC2) is a highly scalable and flexible cloud computing service provided by AWS that allows users to run virtual servers, known as instances, on demand. EC2 offers a wide variety of instance types optimized for different workloads, including general-purpose, compute-intensive, memory-intensive, and GPU-enabled tasks. It supports both x86 and Arm architectures, with Arm-powered Graviton instances providing significant cost and performance advantages for specific workloads. EC2 integrates seamlessly with other AWS services, enabling applications to scale automatically, handle varying traffic loads, and maintain high availability.

### EC2 Instance
Follow these steps to deploy an app to an Arm-powered EC2 instance::
1. Log in to AWS Management Console [here](http://console.aws.amazon.com)
2. Navigate to EC2 Service. In the search box type "EC2". Then, click EC2:

![fig5](figures/05.png)

3. In the EC2 Dashboard, click “Launch Instance” and fill out the following details:
* Name: type arm-server
* AMI: Select Arm-compatible Amazon Machine Image, Ubuntu 22.04 LTS for Arm64.
* Architecture: Select 64-bit (Arm).
* Instance Type: Select t4g.small.

The configuration should look as follows:

![fig6](figures/06.png)

4. Scroll down to "Key pair (login)", and click "Create new key pair". This will display the "Create key pair" window, in which you configure the following:
* Key pair name: arm-key-pair
* Key pair type: RSA
* Private key format: .pem
* Click the Create key pair button, and download the key pair to your computer

![fig7](figures/07.png)

5. Scroll down to "Network Settings", where:
* VPC: use default
* Subnet: select no preference
* Auto-assign public IP: Enable
* Firewall: Check Create security group
* Security group name: arm-security-group
* Description: arm-security-group
* Inbound security groups

![fig8](figures/08.png)

5. Configure "Inbound Security Group Rules". Specifically, click "Add Rule" and set the following details:
* Type: Custom TCP
* Protocol: TCP
* Port Range: 7133.
* Source: Select Anywhere (0.0.0.0/0) for public access or restrict access to your specific IP for better security.
* Repeat this step for all three ports the application is using. Here I have 7133, 7511, 17222. These must match the values we had, when we run the app locally.

The configuration should look as follows:

![fig9](figures/09.png)

6. Launch an instance by clicking "Launch instance" button. You should see the green box with the Success label. This box also contains a link to the EC2 instance. Click it. It will take you to the instance dashboard, which looks like the one below:

![fig10](figures/10.png)

### Deploying an app
Once the EC2 instance is ready, we can connect to it and deploy the application. Follow these steps to connect:
1. Locate the instance public IP (e.g. 98.83.137.101 in my case).
2. Use an SSH client to connect:
* Open the terminal
* Set appropriate permissions for the key pair file (remember to use your IP address)
```console
chmod 400 arm-key-pair.pem
ssh -i arm-key-pair.pem ubuntu@98.83.137.101
```

![fig11](figures/11.png)

We can now install required components, pull the application code from git, and launch the app:
1. In the EC2 terminal type
```console
sudo apt update && sudo apt upgrade -y
```

This will update the package list and upgrade the installed packages.

2. Install .NET SDK using the following commands:
```console
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update
sudo apt install -y dotnet-sdk-8.0
```

Verify the installation:
```console
dotnet --version
```

3. Install the Aspire workload using the dotnet CLI
```console
dotnet workload install aspire
```

4. Install git:
```console
sudo apt install -y git
```

5. Clone the repository:
```console
git clone https://github.com/dawidborycki/NetAspire.Arm.git
cd NetAspire.Arm/
```

6. Trust trust the development certificate:
```console
dotnet dev-certs https --trust
```

7. Build and run the project
```console
dotnet restore
dotnet run --project NetAspire.Arm.AppHost
```

The application will run the same way as locally. You should see the following:

![fig12](figures/12.png)

Finally, open the application in the web browser (using the EC2's public IP):

![fig13](figures/13.png)

### Summary
You have successfully deployed the Aspire app onto an Arm-powered AWS EC2 instance. This demonstrates the compatibility of .NET applications with Arm architecture and AWS Graviton instances, offering high performance and cost-efficiency.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Background
weight: 2

### FIXED, DO NOT MODIFY
layout: learningpathall
---

### What is the .NET Aspire
.NET Aspire is a comprehensive suite of powerful tools, templates, and packages designed to simplify the development of cloud-native applications using the .NET platform. Delivered through a collection of NuGet packages, .NET Aspire addresses specific cloud-native concerns, enabling developers to build observable and production-ready apps efficiently.

Cloud-native applications are typically composed of small, interconnected services or microservices rather than a single monolithic codebase. These applications often consume a variety of services such as databases, messaging systems, and caching mechanisms. .NET Aspire provides a consistent and opinionated set of tools and patterns that help developers build and run distributed applications, taking full advantage of the scalability, resilience, and manageability of cloud infrastructures.

.NET Aspire enhances the local development experience by simplifying the management of your app’s configuration and interconnections. It abstracts low-level implementation details, streamlining the setup of service discovery, environment variables, and container configurations. Specifically, with a few helper method calls, you can create local resources (like a Redis container), wait for them to become available, and configure appropriate connection strings in your projects.

.NET Aspire offers integrations for popular services like Redis and PostgreSQL, ensuring standardized interfaces and seamless connections with your app. These integrations handle cloud-native concerns such as health checks and telemetry through consistent configuration patterns. By referencing named resources, configurations are injected automatically, simplifying the process of connecting services.

.NET Aspire provides project templates that include boilerplate code and configurations common to cloud-native apps, such as telemetry, health checks, and service discovery. It offers tooling experiences for Visual Studio, Visual Studio Code, and the .NET CLI to help you create and interact with .NET Aspire projects. The templates come with opinionated defaults to help you get started quickly, reducing setup time and increasing productivity.

By providing a consistent set of tools and patterns, .NET Aspire streamlines the development process of cloud-native applications. It manages complex applications during the development phase without dealing with low-level implementation details. .NET Aspire easily connects to commonly used services with standardized interfaces and configurations. There are also various templates and tooling to accelerate project setup and development cycles. Finally, with .NET Aspire, you can create applications that are ready for production with built-in support for telemetry, health checks, and service discovery.

Here, we will explain how to create a .NET Aspire application, describe the project, and modify the code. Finally, we will deploy the application to AWS and then to GCP using virtual machines.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6af0813

Please sign in to comment.