将.Net Core Web-API移至AWS Web Api Gateway [英] Moving .Net Core Web-API to AWS Web Api Gateway

查看:136
本文介绍了将.Net Core Web-API移至AWS Web Api Gateway的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用.Net Core开发的Web-API,它的端点很少(GET/POST).要求是将其移至AWS API-Gateway.该Web-API是使用分层体系结构构建的,它具有与Db层进行通信的业务层,该Db层获得了一些实体框架存储库(后端数据库Postgres).现在,我已将解决方案重新创建为无AWS Server解决方案(使用适用于Visual Studio的AWS Toolkit附带的模板项目之一).

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).

问题是如何使我的Web api方法启用AWS API Gatway?我尝试将Web-api原样发布到AWS,但是它在api网关中创建了一个空白api(Visual Studio说成功发布了),这意味着由于某些原因,Api-Gateway无法识别我的解决方案中的端点,我认为原因是我不知道如何正确配置它们并使它们启用AWS-API网关...

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 ...

第二个问题是 模型绑定将如何在AWS API-GATEWAY中工作.我应该使用映射模板来实现模型绑定,还是内置的.net核心Web API模型绑定可以正常工作?

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 ?

以下是已开发的示例Web API,需要将其部署到AWS-API-Gateway

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

    }
}

推荐答案

好吧,我正在回答自己的问题,以防万一有人在寻找相同的信息.我的端点在API网关上不可用的原因,我的lambda处理程序不完全合格,我不得不在serverless.template文件中配置Proxy +部分.

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.

对于您的serverless.template文件,检查资源">"AspNetCoreFunction">处理程序"属性.它应该具有这种格式

"Handler": "<your-web-api-project-name>::<namespace-for-your-lambda>.<lambda-class-name>::FunctionHandlerAsync"

我还必须添加这些内容,以使我的API可以在AWS Gateway上运行到无服务器模板中.

                "Events": {
              "ProxyResource": {
                "Type": "Api",
                "Properties": {
                  "Path": "/{proxy+}",
                  "Method": "ANY"
                }
           },
            "RootResource": {
                "Type": "Api",
                "Properties": {
                    "Path": "/",
                    "Method": "ANY"
                    }
                }

这篇关于将.Net Core Web-API移至AWS Web Api Gateway的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆