AWS Lambda w / API Gateway for Angular back-end?

I'm still trying to get around the limitations of AWS Lambda, especially now that the AWS API Gateway opens up many options for serving REST requests with Lambda.

I am considering creating a web application in Angular using Lambda acting as a back-end.

For simple CRUD things, this seems simple enough, but what about authentication? Can I use something like Passport in Lambda to authenticate a user?

+5
source share
3 answers

Yes, you can do almost everything, just save your session in a database hosted in AWS (RDS, Dynamo, etc.). But keep in mind that you are buying lambda. He has many compromises.

  • Price: EC2 server costs a fixed price per month, but lambda has a cost per call. Which is cheaper depends on your usage patterns. Lambda is cheaper when no one is using your product, EC2 is most likely cheaper as usage increases.

  • Scale: EC2 can scale (in different ways), but it is more “manual” and “shorter” (you can run only one server or 2, not 1,5). Lambda has fine-grained scaling. You are not worried about this, but you also have less control over it.

  • Performance: Lambda is a certain speed, and you have very little control. In some cases, this can have huge delays as they deploy new containers to handle traffic. EC2 gives you more options for tuning performance. (Box size, cache on the box using the latest node.js, removing unnecessary services from the box, having the ability to run strace, etc.). You can pay for excess capacity to provide low latency.

  • Code: The way you code will be slightly different in Lambda vs EC2. Lambda forces you to obey certain conventions, which in most cases are best practice. But EC2 allows you to break them for performance or just development speed. Lambda is a black box in which you have less control and visibility when you need to troubleshoot.

  • Customization: Lambda is easier to configure and requires less knowledge in general. EC2 requires you to be an administrator and understand abbreviations such as VPC, EBS, VPN, AMI, etc.

+12
source

Posting this here since this is the first thread I found when searching for NodeJS Passport authentication on Lamdba.

Since you can run Express applications on Lamda , you can really run Passport on Lambda directly. However, Passport is indeed middleware specifically for Express, and if you are developing for Lamda in the first place, you probably do not want to bloat Express (since the API gateway basically does all this).

As @Jason mentioned, you can use your own authorizer. It seems pretty straight forward, but who wants to build all possible auth methods? This is one of the advantages of the Passport, people have already done it for you.

If you use the Servlerless Framework , someone has created a “Serviceless Authentication” . This includes modules for many standard auth providers: Facebook , Google , Microsoft . There is also a template for creating additional service providers .

It took me a lot of research to cope with all this, so hopefully this helps someone else.

+3
source

but what about authentication?

The most modular approach is to use the Gateway Custom Authorizers API (new since February 16) to provide the AWS Lambda function, which implements authentication and authorization.

I wrote a generic Custom Authorizer that works with Auth0 , a third-party Single-Sign-On service.

See also this question: How - AWS Rest API Authentication

Can I use something like Passport in Lambda to authenticate a user?

Not easy. Your passport uses callback URLs that you will need to create and configure.

+1
source

All Articles