Reputation: 3384
I have a Web-API developed with .Net Core.It has few end points ( GET / POST ). The requirement is to move that to AWS API-Gateway. That Web-API is built using layered architecture, it has a business layer that talks to Db layer that got some entity framework repositories ( backend database Postgres). Now i have re-created my solution as a AWS Serverless solution ( using one of the template projects that comes with AWS Toolkit for visual studio).
The question is how to make my web api methods AWS API Gatway enabled ? I tried publishing my web-api to AWS as it is but its creating a blank api in api gateway ( Visual studio says successfully published), that means for some reasons, Api-Gateway cannot recognize my endpoint within my solution, and i think the reason is i don't know how to configure them properly and make them AWS-API Gateway enabled ...
The second question is How the model binding will work in AWS API-GATEWAY. Should i use mapping template to implement model bindings or the built in .net core web api model binding will work and its sufficient ?
Following is an example Web API that is developed and needs to be deployed to AWS-API-Gateway
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace TestApi
{
[Route("api/testapi")]
public class TestApiController : Controller
{
private ITestApiManager testApiManager;
public TestApiController(ITestApiManager testApiManager)
{
this.testApiManager = testApiManager;
}
// GET: api/testapi/data/D-001
[HttpGet]
[Route("data/{param}")]
public IActionResult SomeMethod(string param)
{
// This method access busines layer which calls data access layer to get the data from postgress database using entity framework
}
// There are some more similar GET and POST methods in this api as well
}
}
Upvotes: 4
Views: 2880
Reputation: 21
You can use API Gateway to proxy your requests, then use AspNetCoreServer to transform API Gateway requests into ASP.NET Core requests and transform outgoing responses so that API Gateway will understand them. I wrote a detailed article on how to achieve this and deploy using AWS CDK.
Upvotes: 0
Reputation: 3384
ok i am answering my own question just incase if someone else is looking for same information. The reason my endpoints were not avaiable on API Gateway, my lambda handler was not fully qualified and i had to configure Proxy+ section in serverless.template file.
for your serverless.template file, check the Resources > AspNetCoreFunction > Handler property. It should have this format
"Handler": "<your-web-api-project-name>::<namespace-for-your-lambda>.<lambda-class-name>::FunctionHandlerAsync"
I also had to add these to make my API work on AWS Gateway into serverless.template
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/{proxy+}",
"Method": "ANY"
}
},
"RootResource": {
"Type": "Api",
"Properties": {
"Path": "/",
"Method": "ANY"
}
}
Upvotes: 4