Binding API gateway to multiple lambdas with FastAPI - amazon-web-services

I have been following this article for deploying a FastAPI app on AWS lambda and integrating that with API Gateway, and I have done with that.
Now the issue I have two different app on two different lambda, now I want to connect the both lambda to same api gateway. Is it possible, how can I do that ??
Any suggestion is helpful.
I have tried to deploy an other method /service and that has an resource for ANY with lambda proxy integration enabled. When I git the api with key/service/ it says method not
{"detail":"Not Found"}
while I have an route for this enabled in APP which looks like below.
#router.get("/", status_code=status.HTTP_200_OK)
def get_version(request: Request):
return {'version': 'v1.0.0'}
Please help

You can very well create several endpoints in API Gateway, and link them to different lambda functions.
For instance, let's say your two apps only have the get endpoint you describe.
Then, you could very well define 2 resources (app1 and app2), each one of them with a GET method, linking to the different lambda functions.
If this is what you did, and it didn't work, then there is probably another problem, like are you lambdas in the same VPC, with right policies etc

Related

How to invoke multiple AWS Lambda functions on same custom subdomain in different paths?

Here's my situation. I have 2 AWS lambda functions that I want to use under one subdomain route let's call it api.mywebsite.com. To get it setup I made all the necessary changes to the certificate manager, api gateway, dns records and all that. The subdomain works great with one lambda function. However, when I try to add the second lambda function on API mappings I get errors like cannot get, or "Missing Authentication Token". I cannot get this to work with multiple lambdas.
The following is the setup:
Custom Domains setup:
production-mywebsite-api setup:
production-mywebsite-payments-api setup:
Do you know if it's possible to have one domain working for various lambda functions? Like lets say the domain is api.mywebsite.com but I have 1 lambda that can be reached on api.mywebsite.com/lambda1 and another lambda function that can be reached on api.mywebsite.com/lambda2?
It turns out that the issue that I was having was due to deploying separate lambda functions to separate api getaway configurations. As you can see form my post I had different configurations for both of them. This is like fedonev pointed out a bad practice.
After reading this article and unifying my lambda functions under one api gateaway configuration on deployment I was able to deploy all of them to the same subdomain.

How to use ECS and Lambda microservices within the same API?

I am trying to setup a microservice architecture on AWS, each microservice is a REST API.
Some of the services are running on ECS using Fargate and some of the services are running as a set of lambdas.
I am trying to have each api route resolve to the correct service, whether it is a ECS or Lambda based service.
I can see how it would be possible using only ECS services (with Application Load Balancer and listeners) or using only Lambdas (with an API Gateway). But I just cant seem to figure out how to mix the two together.
I have been searching relentlessly all week and I cannot find any decent documentation or an example of how to implement something similar to this.
There appears to be a limit to the number of routes for ALB or API Gateway. If I have several lambda based services there will need to be a declared path for each Lambda function and they will use up the path limit very quickly.
Should there be an intermediary step between each service and the API Gateway? For instance, each Lambda service has its own API Gateway which 'groups' those functions together. Which would mean there will be a nested set of API Gateways that the parent API Gateway routes to. This doesn't feel correct though.
Any help in the right direction would be appreciated.
Thanks
Your AWS account's API Gateway REST and Websocket routes/resources limit can be increased with a request to AWS support.

Is there a way to deploy multiple api gateways sharing same lambdas using serverless

My use case is as follows,
I have built a rest api written in nodejs with serverless and when deployed will create lambdas and an api gateway that gives url which works fine. However, I will have multiple clients who would want to use this application (with their clients consuming the api) and I wouldn't want to duplicate the lambda's for each client as the business logic wouldn't change. What would be different is the stage variables set in the api gateway for each client.
Is there a way I can deploy and manage this using serverless, so that when a new client comes on board, I should be able to do something like update the serverless.yml with new api gateway details and then running the deploy command would generate the new gateway with it's own stage variables sharing the previously created lambdas.
Hope, the question is clear and apologies if this has been previously asked and answered.

Serverless - Options for communicating between services?

I have a few different services (generated by the Serverless Framework) that need to communicate between each other. The data is sensitive and requires authentication.
My current strategy is to create an api key for each service communicate between services using json web token like the token below.
fM61kaav8l3y_aLC/3ZZF7nlQGyYJsZVpLLiux5d84UnAoHOqLPu4dw3W7MiGwPiyN
What are some other options for communicating between services? Are there any downsides to this approach? To reiterate, the request needs to be authenticated and appropriately handle sensitive data.
Do you need sync or async communication?
A good approach would be to use events, because aws-lambda is designed as an event based system. So you could use SNS or SQS to decouple your services.
If you just want to make calls from one service to another you could invoke the lambda function directly via the aws-sdk see docs. So you would not add an API Gateways endpoint and your lambdas would stay private.
To better anwser your question you should give a short overview of your application and and an example of an interservice call you would make.
As I understand it, you intend to make the various functions in a given a service private. In doing so, each service will likely have serverless.yml file that resembles the following:
Image shows the setup for api keys used with a serverless framework rest api
While this is a suitable approach, it is less desirable than using ** Custom Authorizers**.
Custom Authorizers allow you to run an AWS Lambda Function before your targeted AWS Lambda Function. This is useful for Microservice Architectures or when you simply want to do some Authorization before running your business logic.
If you are familiar with the onEnter function when using ReactRouter, the logic among Custom Authorizers is similar.
Regarding implementation, since different services are leveraged to deploy various functions, consider deploying the function to AWS and noteing the ARN of the Lambda function. Follow these links to see the appropriate setup for the custom authorizer.
These images show the serverless.yml file for using custom authorizers when the authorizers are not part of the service but rather deployed on lambda already
The following github project aws-node-auth0-custom-authorizers-api/frontend is a good example of how to implement Custom Authorizers when the authorizer funciton is in the same service as the private function. Note your situation differs slightly yet you should expect their authorizer function logic to be simliar - only the project structure should differ

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.