2021-01-12
1388
#aws#django
Oluwaseun Raphael Afolayan
31977
Jan 12, 2021 ⋅ 4 min read

Using Zappa and AWS Lambda to deploy serverless Django apps

Oluwaseun Raphael Afolayan Developer and digital growth hacker. Saving the world one paragraph at a time. Aspiring ethical hacker and a WordPress evangelist.

Recent posts:

Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 ⋅ 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 ⋅ 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 ⋅ 7 min read
Implementing Infinite Scroll In Next Js With Server Actions

Implementing infinite scroll in Next.js with Server Actions

Infinite scrolling in Next.js no longer requires external libraries — Server Actions let us fetch initial data directly on the server.

Rahul Chhodde
Apr 19, 2024 ⋅ 10 min read
View all posts

5 Replies to "Using Zappa and AWS Lambda to deploy serverless Django apps"

  1. Great post, thanks for writing it up. I wonder if you have a recommendation for a database to go together with a Django/Lambda project. Using RDS is always an option but it’s a shame that you end up with such a large baseline expense even though the app itself is serverless.

  2. Hello. Thanks for great post.
    I try it all, but when i deploy zappa i ‘ve got erro:

    Deploying API Gateway..
    Scheduling..
    Unscheduled zappatest-dev-zappa-keep-warm-handler.keep_warm_callback.
    Scheduled zappatest-dev-zappa-keep-warm-handler.keep_warm_callback with expression rate(4 minutes)!
    Waiting for lambda function [zappatest-dev] to be updated…
    Error: Warning! Status check on the deployed lambda failed. A GET request to ‘/’ yielded a 502 response code.

    Can you tell me how fix it error?

    1. I used `zappa tail` to see the error message, and this error is from File “/var/task/django/db/models/base.py” where it checks the version of sqlite. To the best of my knowledge there are 3 ways of solving this, though none is ideal:
      1. Edit `settings.py` and comment out the DATABASES lines
      2. Install django-s3-sqlite. (See http://blog.perwagnernielsen.dk/django_sqlite_zappa.html )
      3. Edit your base.py (if you use a virtual environment then this file should be in venv/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py) and replace “`raise ImproperlyConfigured(
      “SQLite 3.9.0 or later is required (found %s).” % Database.sqlite_version
      )“`
      with `pass`

  3. Hi, I was using Python v3.8 and Django v4 and this didn’t work for me at the step “zappa deploy dev” I get error “File “/var/task/django/db/backends/sqlite3/base.py”, line 67, in check_sqlite_version
        raise ImproperlyConfigured(“

  4. All works great! Only problem I have is with: zappa manage dev “collectstatic –noinput”

    I can do it local but can not do it from zappa which I would like to so I could put in my build process.

    I am thinking it has to do with access to the S3 bucket but I have tried setting various admin level permissions to see and can not resolve this error.

    The app deploys fine and statics work fine from s3 from pushing local env but not from zappa env.

    Any ideas?

    [DEBUG] 2022-04-05T18:01:27.040Z 7cca4688-e589-4ddb-882b-1fbe38084e8e S3 request was previously redirected, not redirecting.
    [ERROR] ClientError: An error occurred (400) when calling the HeadObject operation: Bad Request
    Traceback (most recent call last):
      File “/var/task/handler.py”, line 655, in lambda_handler
        return LambdaHandler.lambda_handler(event, context)
      File “/var/task/handler.py”, line 252, in lambda_handler
        return handler.handler(event, context)
      File “/var/task/handler.py”, line 430, in handler
        management.call_command(*event[“manage”].split(” “))
      File “/var/task/django/core/management/__init__.py”, line 198, in call_command
        return command.execute(*args, **defaults)
      File “/var/task/django/core/management/base.py”, line 460, in execute
        output = self.handle(*args, **options)
      File “/var/task/django/contrib/staticfiles/management/commands/collectstatic.py”, line 209, in handle
        collected = self.collect()
      File “/var/task/django/contrib/staticfiles/management/commands/collectstatic.py”, line 135, in collect
        handler(path, prefixed_path, storage)
      File “/var/task/django/contrib/staticfiles/management/commands/collectstatic.py”, line 368, in copy_file
        if not self.delete_file(path, prefixed_path, source_storage):
      File “/var/task/django/contrib/staticfiles/management/commands/collectstatic.py”, line 278, in delete_file
        if self.storage.exists(prefixed_path):
      File “/var/task/storages/backends/s3boto3.py”, line 469, in exists
        self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
      File “/var/task/botocore/client.py”, line 401, in _api_call
        return self._make_api_call(operation_name, kwargs)
      File “/var/task/botocore/client.py”, line 731, in _make_api_call
        raise error_class(parsed_response, operation_name)[END] RequestId: 7cca4688-e589-4ddb-882b-1fbe38084e8e

Leave a Reply