Monday, January 20, 2020

AWS CloudFormation Starting EC2 Instance Requires ec2:RunInstances Permission

Another weird case with AWS CloudFormation. 

Problem

I attempted to start an EC2 instance and for somewhat reason it failed and said it doesn't have ec2:RunInstances permission, but it does. After few checks, I found out that the cause is the IamInstanceProfile. If it is set, the error happens. 

Solution

With clue from some online forum, I tried adding iam:PassRole permission for CloudFormation instead of the required ec2:RunInstances and it works!

ASP.NET Web API 404 The Resource Cannot Be Found

I have an old ASP.NET Web API 2 which I would like to update with OWIN. As usual, it didn't go smoothly.

Problem

After updating to OWIN, it somehow threw a 404 error. I spent hours trying various things as stated below but none works.
  • Verified the order of route registration
  • Attempted to use Route attributes
  • Applied runAllManagedModulesForAllRequests="true" on modules tag in web.config
  • Made sure spelling, Nuget packages and imports are correct
  • Checked with a brand new Web API project to make sure code are correct

Solution

At the end, I remembered that I accidentally hit "Create Virtual Directory" when the Project Url field was set to "http://localhost:xxxxx/api" and using IIS Express. I suspect the virtual directory was the issue. After few online searches, I found the virtual directory was set in:

<solution folder>/.vs/config/applicationhost.config

Removing the virtual directory solves my 404 issue.