ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.38k stars 1.64k forks source link

404 with AWS lambda + API Gateway #1344

Closed maxdulieu closed 4 years ago

maxdulieu commented 4 years ago

I have the most basic implementation of ocelot (the jsonplaceholder.typicode.com example). It gets deployed to a AWS lambda function with the following template

functions:
    api-backend:
        handler: Redacted.API::Redacted.API.LambdaEntryPoint::FunctionHandlerAsync
        description: 'Redacted .NET Core Web API'
        memorySize: 512
        timeout: 30
        events:
            - http: ANY /
            - http: 'ANY {proxy+}'

Expected Behavior / New Feature

When hitting the endpoint I should get the todos results

Actual Behavior / Motivation for New Feature

It works locally when running it under http://localhost:5000, but returns 404 once deployed

Steps to Reproduce the Problem

Routes": [
        {
            "DownstreamPathTemplate": "/todos/{id}",
            "DownstreamScheme": "https",
            "DownstreamHostAndPorts": [
                {
                    "Host": "jsonplaceholder.typicode.com",
                    "Port": 443
                }
            ],
            "UpstreamPathTemplate": "/todos/{id}",
            "UpstreamHttpMethod": ["Get"]
        }
    ] 
 public static void Main(string[] args)
        {
            new WebHostBuilder()
              .UseKestrel()
              .UseContentRoot(Directory.GetCurrentDirectory())
              .ConfigureAppConfiguration((hostingContext, config) =>
              {
                  config
                      .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                      .AddJsonFile("appsettings.json", true, true)
                      .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
                        .AddJsonFile("ocelot.json")
                      .AddEnvironmentVariables();
              })
              .ConfigureServices(s =>
              {
                  s.AddOcelot();
              })
              .ConfigureLogging((hostingContext, logging) =>
              {
                  //add your logging
              })
              .UseIISIntegration()
              .Configure(app =>
              {
                  app.UseOcelot().Wait();
              })
              .Build()
              .Run();
        } 

Specifications

maxdulieu commented 4 years ago

I fix this. Amazon.Lambda.AspNetCoreServer package has two entry points:

I had forgotten to add the json configuration to the AWS entry point. Welp, I learned a lot

nitusharma2022 commented 1 year ago

Hi

Can you share the steps , facing similar issue