Moving .Net Core Web-API to AWS Web Api Gateway

帅比萌擦擦* 提交于 2019-12-23 05:28:01

问题


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

    }
}

回答1:


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"
                    }
                }


来源:https://stackoverflow.com/questions/57432461/moving-net-core-web-api-to-aws-web-api-gateway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!