|
| 1 | +--- |
| 2 | +title: Deploy to AWS EC2 |
| 3 | +weight: 4 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +### Objective |
| 10 | +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. |
| 11 | + |
| 12 | +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. |
| 13 | + |
| 14 | +### EC2 Instance |
| 15 | +Follow these steps to deploy an app to an Arm-powered EC2 instance:: |
| 16 | +1. Log in to AWS Management Console [here](http://console.aws.amazon.com) |
| 17 | +2. Navigate to EC2 Service. In the search box type "EC2". Then, click EC2: |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +3. In the EC2 Dashboard, click “Launch Instance” and fill out the following details: |
| 22 | +* Name: type arm-server |
| 23 | +* AMI: Select Arm-compatible Amazon Machine Image, Ubuntu 22.04 LTS for Arm64. |
| 24 | +* Architecture: Select 64-bit (Arm). |
| 25 | +* Instance Type: Select t4g.small. |
| 26 | + |
| 27 | +The configuration should look as follows: |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +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: |
| 32 | +* Key pair name: arm-key-pair |
| 33 | +* Key pair type: RSA |
| 34 | +* Private key format: .pem |
| 35 | +* Click the Create key pair button, and download the key pair to your computer |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +5. Scroll down to "Network Settings", where: |
| 40 | +* VPC: use default |
| 41 | +* Subnet: select no preference |
| 42 | +* Auto-assign public IP: Enable |
| 43 | +* Firewall: Check Create security group |
| 44 | +* Security group name: arm-security-group |
| 45 | +* Description: arm-security-group |
| 46 | +* Inbound security groups |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +5. Configure "Inbound Security Group Rules". Specifically, click "Add Rule" and set the following details: |
| 51 | +* Type: Custom TCP |
| 52 | +* Protocol: TCP |
| 53 | +* Port Range: 7133. |
| 54 | +* Source: Select Anywhere (0.0.0.0/0) for public access or restrict access to your specific IP for better security. |
| 55 | +* 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. |
| 56 | + |
| 57 | +The configuration should look as follows: |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +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: |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +### Deploying an app |
| 66 | +Once the EC2 instance is ready, we can connect to it and deploy the application. Follow these steps to connect: |
| 67 | +1. Locate the instance public IP (e.g. 98.83.137.101 in my case). |
| 68 | +2. Use an SSH client to connect: |
| 69 | +* Open the terminal |
| 70 | +* Set appropriate permissions for the key pair file (remember to use your IP address) |
| 71 | +```console |
| 72 | +chmod 400 arm-key-pair.pem |
| 73 | +ssh -i arm-key-pair.pem [email protected] |
| 74 | +``` |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +We can now install required components, pull the application code from git, and launch the app: |
| 79 | +1. In the EC2 terminal type |
| 80 | +```console |
| 81 | +sudo apt update && sudo apt upgrade -y |
| 82 | +``` |
| 83 | + |
| 84 | +This will update the package list and upgrade the installed packages. |
| 85 | + |
| 86 | +2. Install .NET SDK using the following commands: |
| 87 | +```console |
| 88 | +wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb |
| 89 | +sudo dpkg -i packages-microsoft-prod.deb |
| 90 | +sudo apt update |
| 91 | +sudo apt install -y dotnet-sdk-8.0 |
| 92 | +``` |
| 93 | + |
| 94 | +Verify the installation: |
| 95 | +```console |
| 96 | +dotnet --version |
| 97 | +``` |
| 98 | + |
| 99 | +3. Install the Aspire workload using the dotnet CLI |
| 100 | +```console |
| 101 | +dotnet workload install aspire |
| 102 | +``` |
| 103 | + |
| 104 | +4. Install git: |
| 105 | +```console |
| 106 | +sudo apt install -y git |
| 107 | +``` |
| 108 | + |
| 109 | +5. Clone the repository: |
| 110 | +```console |
| 111 | +git clone https://github.com/dawidborycki/NetAspire.Arm.git |
| 112 | +cd NetAspire.Arm/ |
| 113 | +``` |
| 114 | + |
| 115 | +6. Trust trust the development certificate: |
| 116 | +```console |
| 117 | +dotnet dev-certs https --trust |
| 118 | +``` |
| 119 | + |
| 120 | +7. Build and run the project |
| 121 | +```console |
| 122 | +dotnet restore |
| 123 | +dotnet run --project NetAspire.Arm.AppHost |
| 124 | +``` |
| 125 | + |
| 126 | +The application will run the same way as locally. You should see the following: |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +Finally, open the application in the web browser (using the EC2's public IP): |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | +### Summary |
| 135 | +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. |
| 136 | + |
0 commit comments