
Chalice: Python Serverless Microframework for AWS - fideloper
https://aws.amazon.com/blogs/developer/preview-the-python-serverless-microframework-for-aws/?sc_channel=sm&sc_campaign=launch_sdk_tools_4a8efa18&sc_publisher=tw_go&sc_content=Python_Microframework&sc_country=global&sc_geo=global&adbsc=social_launches_20160711_63715856&adbid=752600622390587393&adbpl=tw&adbpr=66780587
======
cdnsteve
I think I would have preferred this to be some type of plugin/add-on to Flask
rather than a full replacement that now locks me to AWS and is a brand new
project without any docs :(

If it was a cli with decorators or something that uses Flask I would feel more
comfortable and give it a shot.

~~~
ak217
I've looked into doing this. Flask is too integrated with the WSGI protocol to
be easily adapted to this model. It presupposes a number of things about the
request and response protocol that are not true in Lambda. You would end up
having to write an unwieldy WSGI emulation layer (what Zappa did) and still
wouldn't be able to achieve 100% WSGI compatibility, breaking a subset of the
plugins.

Most people love Flask because of its beautiful, minimalistic route decorators
and hooks. That subset of the API can be easily replicated - Chalice is part
of the way there - and I'm hoping it emerges as an API standard, separate from
WSGI.

~~~
eli
You're not wrong, but there are plenty of examples of using Flash without
WSGI. I use Flask-Frozen to generate static sites from the CLI, for example.

~~~
bmelton
You may be right overall, but that's a particularly bad example, as Frozen
simply eliminates the "flask" portion that gets deployed to the server in lieu
of static files, ergo obviating the need for WSGI altogether.

Serving a Frozen app on lambda means serving static files on lambda, which is
very doable, and a very different use case than developing something like an
API to be deployed to lambda.

Edit: Re-reading our comments, you may be confusing the difficulty -- it isn't
in building the CLI for Flask, it's in getting Flask to be served over lambda.
Presumably, the OP could easily re-write the deploy functionality to deploy a
flask application, it's just that the flask application is unlikely to work
because it defaults to WSGI, which lambda (apparently) does not provide.

------
collyw
Ok, I have seen the phrase "serverless" a few times recently. Can someone
explain to me what it is (as I am pretty sure it involves a server - it runs
on AWS ffs) and why I should want to use it? And most importantly, is it web
scale?

~~~
nashadelic
Well, if you look at how we've done things over the years:

\- We used to have our own machines in our own data centers

\- Then we started renting machines in data centers

\- We then moved to the cloud model where we would get compute capacity on
demand. But the minimum unit was an hour

\- But what if you could deploy your code and you were only charged for the
compute and memory you take for the fulfillment of that request? That is what
the "serverless" model is. You don't constantly run a server like apache;
instead, when you receive a user Request, the relevant function is called,
executed and results returned to the user. You are billed for the ram ⨉ CPU.

This has many benefits:

\- For low traffic sites, this has significant cost savings

\- For high traffic sites, this is auto-scaling without thinking about
launching machine instances

This isn't without problems, naturally. This lends itself well to certain type
of problems better than others. For example, if you need lots of hot-cache
data, the response times on a serverless stack would be slower.

But as you can see from the above, this is the logical direction cloud
computing will evolve. Infrastructure will truly be shared and you should be
able to extract efficiencies down to the minute.

~~~
aashu_dwivedi
then why is it something new? Isn't this what google appengine / heroku has
been doing for years ?

~~~
IanCal
GAE will start up a machine occasionally to deal with increased demand and
keep them on for 15 minutes at least. With something like Lambda (my old
favourite was PiCloud) I can scale out to 50 processes for 10 seconds and only
pay for 500 seconds of processing time.

For me, most of the benefit comes from data processing, where my usage is very
bursty. The classic example used on most of the tutorials is image
thumbnails/scaling/similar. All you want to say is "Do X to every file in this
folder of 50k images" and let someone else handle starting and stopping as
many machines as they can in order to get this done as quickly as possible.

------
SwellJoe
AWS Lambda is cool and all, but aren't people doing the math on this? Lambda
seems like a _really_ expensive way to deliver almost anything. Likewise, the
AWS API Gateway is expensive, but at least provides some additional
capabilities. Lambda seems like its profitable niche would be very small;
limited computing environment, very high cost (relative to almost every other
way to host an API), and having to learn a whole bunch of new APIs and
processes to make it all spin.

Am I missing something?

~~~
scrollaway
What makes you say Lambda is more expensive than things like EC2?

Obviously lambda is a hammer, not a swiss army knife - you shouldn't shoehorn
it into your app just because it's the new tech on the block. But the use case
isn't niche at all.

We're using lambda for our service to ingest and process Hearthstone replays.
An HTTP POST is sent to the API gateway, this triggers a lambda which parses a
0.5-2MB file, scrapes the data in it and stores data in the db + converts it
to another format. The whole process takes 3-6 seconds. Lambda lets us easily
scale to dozens of requests per second without having to worry about anything
other than the DB server. Our frontend/app servers don't need to be touched.

The alternative would be to provision and manage a lot of EC2 instances to
handle the load. We'd have to worry about provisioning them dynamically so
that it's economically viable. We'd have to manage the load balancing
ourselves. Lambda's been a huge time saver.

PS: Let it be known that Lambda only supports python 2.7, not python 3, and
that really frickin sucks. Get your shit together, Amazon.

~~~
emjr
"Let it be known that Lambda only supports python 2.7, not python 3, and that
really frickin sucks. Get your shit together, Amazon."

Node 4 support came, what, a month ago? It's pretty ridiculous.

~~~
joobus
There is no significant benefit to python 3 over python 2.

~~~
scrollaway
You're wrong, and it's irrelevant anyway. Our app is in Python 3. Having to
support Python 2 just because lambda doesn't support 3.x is a pain.

------
johnwheeler
Question:

With these "Serverless" frameworks (Zappa, Chalice, Serverless, etc), do you
have to redeploy to Lambda every time you want to test your changes during
development?

Is there a way to develop locally and get quick feedback?

~~~
marcrosoft
I am not sure about the frameworks, but a lambda function is just that, a
function. You can easily run your function and pass in an event object (a dict
in Python) to test various scenarios. You don't need to deploy to test. Once
you are ready you can deploy to lambda without publishing to fully test before
publishing live.

~~~
johnwheeler
Thank you. Are these not meant to render user interfaces and just be for API-
style computing?

~~~
niftich
Correct. That being said, there's nothing stopping you from emitting, say,
HTML from such a function. But there's nothing really helping you either.

It's basically function calls in the cloud; a remote procedure call where the
remote procedure is executing on their infrastructure.

~~~
johnwheeler
I'm also guessing there's no session state or cookies?

~~~
johnwheeler
We'll I guess there wouldn't be without a server. You'd have to use JWT or the
like.

~~~
skion
Or any server side store, maybe DynamoDB.

------
ak217
This is awesome - it takes care of a lot of the pain of setting up Lambda,
including the packaging, the tricky IAM policies and the crazy API Gateway
incantations. It also follows the Flask decorator conventions!

I could have really used this a few months ago. I ended up writing a library
of my own, but I'd much rather have used this, as it's supported by the AWS
Python team.

This really lowers the barrier to entry to deploying Python-based API servers!

------
pesfandiar
Has anyone successfully and painlessly used Lambda+API Gateway in production
as their main backend? It appears Lambda has many limitations, but I see
rather mature frameworks such as Serverless (formerly JAWS) being promoted
here, and now Amazon is also working on their standard framework.

It would be great to just use CDNs and this; get all benefits of using a PaaS
with IaaS-level costs only!

~~~
adzicg
we use it now as the main backend for Mindmup 2, migrated from Heroku.

I recently published the scripts evolved from our usage to simplify
deployments as [https://Github.com/claudiajs](https://Github.com/claudiajs) \-
the tool is mature, and allows teams to use API GW almost as easy as if it
were a lightweight web server

~~~
spriggan3
So basically each end point is a function ? how do you test your whole app
locally ? I mean integration tests and acceptance tests on your local machine
if you depend entirely on AWS vendor lockin infrastructure

------
robmccoll
Serverless computing seems to just be reinventing hosted CGI. Is this not just
a trade of Perl and php for Python and JavaScript?

~~~
e12e
I think one _could_ engineer CGI to get many of the same benefits - I'm not
entirely sure most people _did_. First, you'd want to run each process in a
separate jail, as a separate user - and yet be able to (easily) use fifo's or
pipes (possibly sockets) to pipe data through.

At that point, you're already a bit from ephemeral data in /tmp and your
typical php/perl/cgi setup.

But I think you're right in that it borrows some of the good ideas from CGI
(chief among them simplicity, assuming that you were doing stateless stuff).

------
gsmethells
I love the name. :) Fits right in with "flask"
([http://flask.pocoo.org](http://flask.pocoo.org)) and "bottle"
([http://bottlepy.org/docs/dev/index.html](http://bottlepy.org/docs/dev/index.html)).

~~~
alaskamiller
Shameless plug: come join over 6200+ of us at
[https://flask.reddit.com](https://flask.reddit.com) discussing Python and
Flask!

------
mxuribe
I think this is great! While I'm no python expert - as much as i love flask -
i get annoyed at the parts needed to setup up the uWSGI stuff. It looks like
using chalice, maybe i don't have to worry about setting up the annoying uWSGI
stuff?

------
tdicola
Very cool, is it still Python 2.7.x only though like AWS Lambda service &
Python code?

~~~
Slippery_John
Seems that way, until Lambda adds support for Python 3

------
jaydenmallen
Consider [https://getsandbox.com](https://getsandbox.com) it provides great
support for viewing state and route logs. Various hosting options.

------
e12e
What is the recommended way of keeping the URL of the service straight? To set
up a DNS pointer to the DNS name amazon generates, with a "low enough" TTL?

