Deploy C# App on AWS Part (3/3)

Ali Alhaddad
4 min readJan 22, 2024

In this tutorial, we’ll pick up where we left off in the previous session and proceed to implement our AWS web server.

Here is the previous tutorial. If you haven’t done it yet, I would recommend taking a look at it:

After pushing our Docker image to the AWS ECR repository, let’s begin hosting our image on the cloud.

Create an AWS ECS cluster.

Create a task definition for your C# server. Specify the details of the task definition.

  • Launch type: Fargate.
  • OS/Architecture: Linux/X86_64.
  • Task size specifics: 1GB CPU and 2GB memory.
  • Set the taskRole to the default ecsTaskExecutionRole. This role will be selected since we are not accessing any other AWS resources in our server; we only require access to ECS.

Set these attributes for container details.

  1. Provide the name for your container.
  2. Specify the Image URI as the URI of your ECR repository (not the individual image).
  3. Set the container port to 80, as this is the port exposed in the Docker file. Additionally, configure the protocol as TCP and the app protocol as HTTP.
  4. Add environment variables based on the appsettings.json file. Use variables from the appsettings.json, and separate each level with two colons.
  5. Include a health check in the task definition. This health check should be a command that hits an endpoint to verify the health of your Docker container. The specified endpoint is http://localhost/List.

Here is the appsettings.json for your reference.

Now, let’s proceed to create the task.

  1. Choose the launch type as FARGATE, which is lightweight and the most cost-effective option.
  2. Configure the task type as Task for microservices, aligning with our built solution.
  3. Assign the task definition to the one you’ve just created.
  4. Opt for a single subnet, a subdivision of the IP network. Although setting up multiple subnets is possible, it doesn’t impact your task execution within this subnet.
  5. Generate a new security group, acting as a virtual firewall to regulate traffic. Define a rule specifying the type as HTTP, protocol as TCP, port as 80, and set the source to Anywhere.

Test your endpoint after verifying that your task’s health check indicates the running task is healthy.

To conclude this tutorial, let’s test the remaining functionality.

Test the POST endpoint in Postman.

Test the PUT endpoint in Postman.

Test the delete endpoint in Postman.

Congratulations! You’ve created a .NET project that utilizes a variety of tools, including Docker, Supabase PostgreSQL database, and AWS services.

1st Part of Tutorial:

Previous 2nd Part of Tutorial:

Here is our GitHub repository with the source code for reference:

--

--