Swagger Endpoint not working on AWS Lambda - amazon-web-services

I created an ASP.NET Core Web API using .NET Core 3.1 and added Swashbuckle Nuget packages to get the Swagger endpoint working. When I run the API locally, the Swagger endpoint works.
Then I deployed the API using AWS Lambda but the issue is the Swagger endpoint doesn't work there. This is the error I get:
Is there a way I can get it working on this Lambda?

A bit late but I've recently stumbled upon a similiar problem.
When you deploy to AWS Lambda, it generates your endpoint with the /Prod stage, while your default Swagger UI initialization looks like u.SwaggerEndpoint("/swagger/v1/swagger.json", "Api") (notice the lack of /Prod at the start). You just have to adjust your UI endpoint so it contains the /Prod stage, so a working solution would look like u.SwaggerEndpoint("/Prod/swagger/v1/swagger.json", "Api")

Related

ASP.NET AWS Serverless

After publishing the serverless API project to the AWS Lambda, the serverless Url not working. Running the project in local is still working, but the serverless Url just wont work. What can possibly be the reason?
Looks like your API is not deployed.
To deploy your API go to the AWS console and try to deploy your API resource:
Use the following options:
Actions > Deploy API:

Deploying a serverless application with Nest.js

I have an application using Nest.js, and I'd like to deploy it using API Gateway + Lambda functions.
I have some experience with AWS, but it's my first time with a serverless application.
I searched for some things but almost everything that I found uses the Serverless framework, and I would like to do it using the AWS SDK.
I have an API with 4 endpoints, I want to use API Gateway and a single Lambda function to run the application.
Any tips on how I could do that?
Thanks in advance.

How to access AWS API Gateway documentation using Swagger UI

I have created API using AWS Api Gateway. Then i have documented documentation parts for all the entities ( like API, RESOURCE, METHOD, MODEL etc). Then using AWS Gateway Console i have published the documentation to dev stage with version 1
But i am not sure how do i (or the consumer of the API) going to access the documentation?
There is an Export option that can export documentation as Swagger or OpenAPI3. This will create .json or .yaml file and then consumer has to import these files into swagger UI. However this is not user-friendly option to provide swagger file every time i update documentation to all consumers.
I was wondering, after publishing the documentation is there anyway consumer can access documentation directly via http. So lets assume my dev stage api URL is
https://devapi.example.com/v1 so something like https://devapi.example.com/v1/help should launch Swagger UI with latest published swagger file.
Update 1
In ASP.NET Web API or .NET Core you can include Swashbuckle that creates swagger files and also has embedded version of the Swagger UI tool. So after deploying API user can access documentation directly from UI something like https://devapi.example.com/swagger.
I was hoping the same thing from AWS gateway. After publishing the documentation it should make that documentation available via some predefined resource path.
AWS API Gateway can only make documentation exportable but won't render a UI app. There is no endpoint that you can use in the gateway to render the documentation. You may wish to use third party tools or AWS API Gateway Developer Portal to allow users browse API documentation. You may find this blog helpful.
Micro Swagger imports swagger spec from Amazon API Gateway & serves a swagger UI from it.
You can leave it running on an EC2 instance:
npm i -g micro-swagger
micro-swagger start
It'll use the instance's IAM role to download the Swagger spec from API Gateway. Your CI/CD pipeline can restart/refresh Micro Swagger whenever it deploys. Your customers can see the latest API docs at the instance's domain.

How to deploy a serverless code into a stage in AWS API Gateway

To deploy a serverless project into a stage of a service, following command can be used
serverless deploy --stage dev
Extracted from the docs
https://serverless.com/framework/docs/providers/aws/guide/deploying/
However when above command is used to deploy a service, it creates a new service with name dev-aws-nodejs in API Gateway.
Is it possible to create a service with name aws-nodejs and have different stages like dev, stag, prod etc.. Therefore, when you run the following command
serverless deploy --stage stag
A new stage called stag will be created under service aws-nodejs.
By design the current version of serverless framework doesn't support this feature. But the version 0.5.6 had been designed to deploy multiple stages into api single api gateway project. Following open issues are related to this. Some have suggested few workarounds.
AWS API Gateway stages and names are separated
Issue below, mainly highlight different services into same api gateway. But it also has some comments related to your query as well.
Deploy many micro/nano services to one API Gateway
Update:
In the recent release of serverless (v1.19), they have mentioned that they have started working on a solution for this.
Serverless v1.19 Changelog

AWS Lambda http, where do I find the URL?

I am fairly new to AWS Lambda but sure can see the benefits of it and stumbled upon the superb framework Serverless to help me built solutions on Lambda.
I started out building solutions using AWS API Gateway but really need "internal" VPC API's and not public Internet facing API's like API GW creates.
I found that Servless indeed can expose a HTTP endpoint but I can't figure out how this is done and how the URL is created.
When I deploy the Lambda from Serverless it gives me the URL, e.g.:
https://uxezd6ry8z.execute-api.eu-west-1.amazonaws.com/dev/ping
I would like to be able to find (or create) this same http listener for already existing Lambdas so my question is how is the URL created and where is teh actual HTTP listener deployed?
You might be looking for the invoke url,
1. go to https://console.aws.amazon.com/apigateway
2. select api link (which you have deployed on aws lambda).
3. select stages in left side panel and
see the invoke url.
Adding a http listener can be done by going to your lambda function, selecting the 'triggers' tab and 'add trigger', finally selecting API Gateway - but as others mentioned this does create a public facing url.
Duh, I was in the wrong AWS logon previously so the API GW was not showing any matching Serverless API and that was why I couldn't understand how they did it...
Once I logged into the AWS account that hosts the Serverless structure I can see the API GW GET API's for the Serverless HTTP listener.