Our First Deployment
Ready to get into the cloud?
Ok, let's try to push our app to the cloud. We will run the Zappa deploy
command. You will need to run this command for the initial deployment of any Zappa environment. Since we are essentially in development mode, we'll start off with a Zappa environment called dev. If this were your own project, you will eventually have quality assurance and production environments. It's important to have a consistent environment naming scheme. The Zappa documentation suggests dev
, qa
, and prod
as a good convention.
The Zappa deploy
command will create all the necessary AWS infrastructure that we will need. Once it's complete, any updates to the code can be done using the update
command. We'll explore the update
command later.
(ve) zappashell> zappa deploy dev
Unfortunately, we encounter an error:
(ve) zappashell> zappa deploy dev
Calling deploy for stage dev..
Warning! AWS Lambda may not be available in this AWS Region!
Warning! AWS API Gateway may not be available in this AWS Region!
Oh no! An error occurred! :(
==============
Traceback (most recent call last):
yada yada yada
File "/var/task/ve/lib/python3.8/site-packages/botocore/regions.py", line 148, in _endpoint_for_partition
raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.
==============
Need help? Found a bug? Let us know! :D
File bug reports on GitHub here: https://github.com/Miserlou/Zappa
And join our Slack channel here: https://zappateam.slack.com
Love!,
~ Team Zappa!
(ve) zappashell>
The error botocore.exceptions.NoRegionError: You must specify a region.
is the problem. Zappa is complaining that no AWS region is specified, so we need to specify one. Remember that Amazon has multiple AWS regions in which you may deploy your code. We recommend you select a region close to you to avoid unnecessary network delays.
Adding AWS region#
In this walkthrough, we are leveraging us-east-1
, but feel free to add your local region. Just make sure the region you select supports AWS Lambda.
Let's edit the zappa_settings.json
file with a region:
{
"dev": {
"aws_region": "us-east-1",
"django_settings": "frankie.settings",
"profile_name": "zappa",
"project_name": "newline-zappa-course",
"runtime": "python3.8",
"s3_bucket": "zappa-txq9v5h8x"
}
}
Try again#
Ok, let's give it another shot.
(ve) zappashell> zappa init
You should see something like the following.
(ve) zappashell> zappa deploy dev
Calling deploy for stage dev..
Downloading and installing dependencies..
Packaging project as zip.
Uploading task-dev-1612471993.zip (15.3MiB)..
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 16.1M/16.1M [00:09<00:00, 1.70MB/s]
Scheduling..
Scheduled task-dev-zappa-keep-warm-handler.keep_warm_callback with expression rate(4 minutes)!
Uploading task-dev-template-1612472106.json (1.6KiB)..
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1.59k/1.59k [00:00<00:00, 13.3kB/s]
Waiting for stack task-dev to create (this can take a bit)..
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:12<00:00, 3.12s/res]
Deploying API Gateway..
Deployment complete!: https://486ungg6ok.execute-api.us-east-1.amazonaws.com/dev
(ve) zappashell>
This page is a preview of Serverless Django with Zappa