-
-
Notifications
You must be signed in to change notification settings - Fork 701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof of concept for Datasette on AWS Lambda with EFS #850
Comments
File locking is interesting here. https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html
SQLite can apparently work on NFS v4.1. I think I'd rather set things up so there's only ever one writer - so a Datasette instance could scale reads by running lots more lambda functions but only one function ever writes to a file at a time. Not sure if that's feasible with Lambda though - maybe by adding some additional shared state mechanism like Redis? |
Easier solution to this might be to have two functions - a "read-only" one which is allowed to scale as much as it likes, and a "write-only" one which can write to the database files but is limited to running a maximum of one Lambda instance. https://docs.aws.amazon.com/lambda/latest/dg/invocation-scaling.html |
https://docs.aws.amazon.com/efs/latest/ug/wt1-getting-started.html is an EFS walk-through using the AWS CLI tool instead of clicking around in their web interface. |
https://github.com/jordaneremieff/mangum looks like the best way to run an ASGI app on Lambda at the moment. from mangum import Mangum
async def app(scope, receive, send):
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [[b"content-type", b"text/plain; charset=utf-8"]],
}
)
await send({"type": "http.response.body", "body": b"Hello, world!"})
handler = Mangum(app) |
From https://mangum.io/adapter/
I can use https://github.com/simonw/datasette-debug-asgi to see that. |
It looks like SAM - AWS Serverless Application Model - is the currently recommended way to deploy Python apps to Lambda from the command-line: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.html |
Installed SAM:
|
|
|
|
I need to get my AWS credentials sorted. I'm going to follow https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started_create-admin-group.html and https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-set-up-credentials.html |
I used https://console.aws.amazon.com/billing/home?#/account and activated "IAM user/role access to billing information" - what a puzzling first step! I created a new user with AWS console access (which means access to the web UI) called |
I think I need to sign in to the AWS console with this new ... for which I needed my root "account ID" - a 12 digit number - to use on the IAM login form. |
Logged in as |
Clicking that button generated me an access key ID / access key secret pair. Dropping those into
|
OK,
|
https://q7lymja3sj.execute-api.us-east-1.amazonaws.com/Prod/hello/ That's a pretty ugly URL. I'm not sure how to get rid of the |
I added an exclamation mark to hello world and ran Running |
I changed
And from datasette.app import Datasette
from mangum import Mangum
datasette = Datasette([], memory=True)
lambda_handler = Mangum(datasette.app()) But then when I ran
|
Someone else ran into this problem: iwpnd/fastapi-aws-lambda-example#1 So I need to be able to pip install MOST of Datasette, but skip |
OK, changed
No |
https://q7lymja3sj.execute-api.us-east-1.amazonaws.com/Prod/hello/ is now giving me a 500 internal server error. |
Tried
|
Just realized Colin Dellow reported an issue with Datasette and Mangum back in April - #719 - and has in fact been working on https://github.com/code402/datasette-lambda for a while! |
https://aws.amazon.com/blogs/compute/announcing-http-apis-for-amazon-api-gateway/ looks very important here: AWS HTTP APIs were introduced in December 2019 and appear to be a third of the price of API Gateway. |
https://aws.amazon.com/about-aws/whats-new/2020/06/aws-lambda-support-for-amazon-elastic-file-system-now-generally-/
If Datasette can run on Lambda with access to EFS it could both read AND write large databases there.
The text was updated successfully, but these errors were encountered: