Full Guide to Developing REST API’s with AWS API Gateway and AWS Lambda
blog.sourcerer.io
blog.sourcerer.io
As a number of other comments have pointed out, there are packages that help with managing your infrastructure in code; which is critical outside of anything other than a play environment. Terraform, serverless, cloudformation, SAM, zappa, etc - are all essentially requirements for cloud usage.
At Amazon they’ve tooling which makes it relatively easy to set up an AWS account to develop against; the tool primarily configures the billing to the correct team within amazon. Additionally your manager gets “rights” to the account, IAM accounts can be linked to AD, etc, etc. This is all part of a push to get Amazon employees building infra on AWS proper. When you create the environment you have to denote whether it’s dev, or whether it’s production; in the former case it’s widely accepted that you use the GUI to set up your trial. However in the latter case you’re strongly encouraged to use something like cloudformation. It was always a shock to me that for prod accounts they don’t disable the GUI for anything other than viewing.
However, this only scales up to a 50MB binary distributable.
A single monolithic JAR was the fastest way to close the feedback loop between idea, prototype, deploy, and validate.
Wouldn't say this is best. Just faster. Every retrospective is an opportunity to explore use of cloud formation, or some templated deployment model.
* How to configure caching and caching rules - please note there are few ways (query strings, headers, parameters, cache enabled only on single method etc.) to specify how to cache responses.
* Attach your REST API on custom domain as a regional endpoint (instead of edge-optimized, since regional endpoints are more configurable)- create ACM certificate (per each region, and one for CloudFront), create own CloudFront distribution (think: multi region deployment), add DNS record in Route53 and configure WAF (some magic DDoS protection).
I took me a lot of time with CloudFormation to get through where I am today and yet I think I would be grateful if someone will share his knowledge gained on more sophisticated use-cases than just 'Hello World'.
Personally, I don't imagine to provide aaaaaaaaa.execute-api.eu-west-1.amazonaws.com/v1/transactions/XXXX/cancel as a API endpoint in the documentation of some product. Well.. It'd definitely made my day if I will see such endpoint in i.e. Stripe docs. Everyone uses short like address like api.example.com so there is definitely use for custom domain name as a feature of API Gateway. Custom domains allows you to separate an API by base paths (i.e. Transactions API, Notifications API, Refunds API) and it easier to upgrade/shutdown... basically maintain your API. Also if you are interested from requests made in two AWS regions and you also care about latency regional endpoints might be way better. Of course, if you will use it with WAF and CloudFront you have a lot of things to configure, which for some companies might be important.
It allows you the SAM simplifications, but also all the CF stuff.
[1]: https://awslabs.github.io/serverless-application-model/inter...
[2]: https://awslabs.github.io/serverless-application-model/globa...
[3]: https://github.com/awslabs/serverless-application-model/tree...
I have yet to deploy a production service with it, but the development experience has been positive.
Going through the motions of setting up my first API Gateway and Lambda was eye opening to me.
There are a ton of options in these two services — rate limiting, authorizers, concurrency, monitoring, etc. — that point to how much power you gain building an app like this.
If you’d like to see an automated, infrastructure-as-code approach to setting up an API, check out my boilerplate app:
I was really excited about lambda, but that is flat out terrible performance for a lot of users. Is this not an issue for others? Why not?
``` from flask import Flask app=Flask() @app.route(‘/‘) def hi(): return "Hi!” ```
$ pip install zappa
$ zappa init
$ zappa deploy
$ zappa certify
IAM, SSL, API Gateway, Lambda, all taken care of. We did the work so you don't have to.
One thing I would improve with the authors article is he crammed a giant conditional statement on the http-method inside his one function. Serverless makes it easy to bundle a single function per HTTP method and even share common code between them. You can build out a whole application as a single npm package.
Bonuses include plugins for serverless that let you unit test your handlers, run a simulated APIG/Lambda/Dynamo environment locally for development, plugins that let you interact more deeply with AWS like assigning a custom domain to your APIG.
Example apps: https://github.com/serverless/examples
Are there any particular benefits to exporting and reimplementing all of that routing and organizational logic into instructions that "program" the API Gateway instead?
In this particular case, the API is solely for external consumption by a third party
[0] https://github.com/UnitedIncome/serverless-python-requiremen...
Sure Zappa, keeps the “container-function-thing” alive so you can cache it as a global variable, but this is a jacket approach that I’m not clear enough on the consequences to use.
Something like dynamo db is a better fit if it works for you, otherwise most people seem to be forced to run a few servers with pgbouncer
For folks who already have AWS infra and want the benefits of Lambda without the pain of API Gateway or Cloud Formation:
Also using something like serverless framework is better suited for the average developer to get this setup up and running. Clicking through the aws cli is not something professional aws users do often. (exceptions would be Cloudwatch metrics and logs). The article should at least mention that infrastructure better is managed in code.
I am not convinced API gateway+ Lambda can substitute for a Web Application , atleast for J2EE apps. The Lambda "boot" time is way too high unless we resort to tricks to keep the lambda instance active. I find the extra $30 or similar is well spent on a a AWS Elastic Beanstalk with auto scaling. The packaging and deployment is cleaner and simpler.
What is your issue with keeping Lambda instance alive? They mostly stay in standby mode some minutes to keep listening for requests and then it will shutdown whether staying idle - what means next request will boot a Lambda function (container?; It usually takes ~1 second), after that time to receive response is approx. ~100ms.
The cold starts are really bad for the 95th percentile latency, and you can't use a relational db with decent performance and throughput until aurora serverless rolls out.
If you're using AWS based services it does a good job of doing what letsencrypt would otherwise do.