【发布时间】:2019-12-17 08:05:59
【问题描述】:
我有一个使用 .Net Core 开发的 Web-API。它的端点很少( GET / POST )。要求是将其移至 AWS API-Gateway。该 Web-API 是使用分层架构构建的,它有一个与 Db 层对话的业务层,该 Db 层有一些实体框架存储库(后端数据库 Postgres)。现在,我已将我的解决方案重新创建为 AWS 无服务器解决方案(使用 AWS Toolkit for Visual Studio 附带的模板项目之一)。
问题是如何使我的 web api 方法 AWS API Gatway 启用?我尝试按原样将我的 web-api 发布到 AWS,但它在 api 网关中创建了一个空白 api(Visual Studio 说已成功发布),这意味着由于某些原因,Api-Gateway 无法在我的解决方案中识别我的端点,我认为原因是我不知道如何正确配置它们并使它们启用 AWS-API 网关...
第二个问题是 模型绑定将如何在 AWS API-GATEWAY 中工作。我应该使用映射模板来实现模型绑定还是内置的 .net core web api 模型绑定可以工作并且足够?
以下是开发并需要部署到 AWS-API-Gateway 的示例 Web API
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
}
}
【问题讨论】:
标签: amazon-web-services aws-api-gateway asp.net-core-webapi