Exposing .NET Core Web API on IIS on EC2 instance

  1. I have setup a .NET Core Web API on EC2 instance on IIS
  2. I Have been able to invoke from within the EC2 instance, it works

What are the steps required to expose an API that can be invoked from outside AWS Environment like say Python running on my local laptop

asked 2 years ago1209 views
1 Answer

You want to expose your web API to the Internet so that users can call that API. In your setup, you have a web server (IIS) running on an EC2 instance and listening for incoming requests.

Please refer to this knowledge center article that explains how to allow inbound traffic on port 80 and/or 443 for an EC2 instance. It is recommended to only allow traffic for HTTPS (port 433) because it is more secure.

If you want to understand in detail how the Security Groups described in that article work, please refer to the Virtual Private Cloud documentation.

Note that you do not necessary need an EC2 instance for hosting a web API implemented using the .NET platform. Depending on your requirements, you might want to consider to host your application on AWS Lambda. In this blog post, you can read about the differences and advantages of both approaches.

Another option for hosting a web API is containerizing your application and using a container orchestration framework for running it. Here, Linux-based containers offer more advantages than Windows-based containers. Since you build your application on .NET Core which supports cross-platform targets, you might want to consider using Linux as your platform. AWS offers multiple ways to run containerized applications. In this blog post, you can read about running a .NET based web API using AWS App Runner. If you want to use Kubernetes, there is also a way for that - using Amazon EKS. Another (easier) option is to use Amazon ECS and AWS Fargate - you can read this blog post for details and advantages of this approach.

Now you can make an informed decision what option fits your requirements - a classic server-based model, a modern container app, or even a serverless architecture.

profile pictureAWS
answered 2 years ago
  • I totally agree with your approach of lambda etc. For the same reason, I created an AWS API Gateway and was able to invoke Sample API's and able to get the response from a browser outside AWS. Attached the Lambda function to API Gateway. Sample API's used in the Lambda Code is https://reqres.in/api/users

    But moment I use the .NET Core API hosted on EC2 instance (on Port 5050) , withing the lambda function it stops working. The .NET Core API is hosted on IIS. I have setup the Security Groups on the Inbound rules of the Security Group associated with the EC2 instance. All TCP allowed for To look up further I tried to access directly the .NET Core API From another EC2 instances withing the same subnet and VPC, even that doesn't Work. But the same .NET Core API works within the EC2 instance where the API is hosted. On the EC2 API Server i have also configured the hosts file too.

    Do I have to configure anything else?

  • If you cannot reach your API from within the same subnet, then there has to be something blocking the network traffic. You can use the VPC Reachability Analyzer or VPC Flow Logs to ensure the traffic is not blocked on the subnet level. Also, make sure the Windows firewall on the instance does not block the incoming requests.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions