Skip to main content
Package Version Python Versions Documentation Status License Chalice Logo

Chalice is a framework for writing serverless apps in Python. It allows you to quickly create and deploy applications that use AWS Lambda. It provides:

  • A command line tool for creating, deploying, and managing your app

  • A decorator based API for integrating with Amazon API Gateway, Amazon S3, Amazon SNS, Amazon SQS, and other AWS services.

  • Automatic IAM policy generation

You can create Rest APIs:

from chalice import Chalice

app = Chalice(app_name="helloworld")

@app.route("/")
def index():
    return {"hello": "world"}

Tasks that run on a periodic basis:

from chalice import Chalice, Rate

app = Chalice(app_name="helloworld")

# Automatically runs every 5 minutes
@app.schedule(Rate(5, unit=Rate.MINUTES))
def periodic_task(event):
    return {"hello": "world"}

You can connect a lambda function to an S3 event:

from chalice import Chalice

app = Chalice(app_name="helloworld")

# Whenever an object is uploaded to "mybucket"
# this lambda function will be invoked.

@app.on_s3_event(bucket="mybucket")
def handler(event):
    print(
        f"Object uploaded for bucket: {event.bucket}, key: {event.key}"
    )

As well as an SQS queue:

from chalice import Chalice

app = Chalice(app_name="helloworld")

# Invoke this lambda function whenever a message
# is sent to the ``my-queue-name`` SQS queue.

@app.on_sqs_message(queue="my-queue-name")
def handler(event):
    for record in event:
        print(f"Message body: {record.body}")

And several other AWS resources.

Once you’ve written your code, you just run chalice deploy and Chalice takes care of deploying your app.

$ chalice deploy
...
https://endpoint/api

$ curl https://endpoint/api
{"hello": "world"}

Up and running in less than 30 seconds. Give this project a try and share your feedback with us here on GitHub.

The documentation is available here.

Quickstart

In this tutorial, you’ll use the chalice command line utility to create and deploy a basic REST API. This quickstart uses Python 3.10, but AWS Chalice supports all versions of Python supported by AWS Lambda, which includes Python 3.10 through Python 3.14.

To install Chalice, we’ll first create and activate a virtual environment in python3.10:

$ python3 --version
Python 3.10.20
$ python3 -m venv .venv
$ . .venv/bin/activate

Next we’ll install Chalice using pip:

$ python3 -m pip install chalice

You can verify you have chalice installed by running:

$ chalice --help
Usage: chalice [OPTIONS] COMMAND [ARGS]...
...

Credentials

Before you can deploy an application, be sure you have credentials configured. If you have previously configured your machine to run boto3 (the AWS SDK for Python) or the AWS CLI then you can skip this section.

If this is your first time configuring credentials for AWS you can follow these steps to quickly get started:

$ mkdir ~/.aws
$ cat >> ~/.aws/config
[default]
aws_access_key_id=YOUR_ACCESS_KEY_HERE
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
region=YOUR_REGION (such as us-west-2, us-west-1, etc)

If you want more information on all the supported methods for configuring credentials, see the boto3 docs.

Creating Your Project

The next thing we’ll do is use the chalice command to create a new project:

$ chalice new-project helloworld

This will create a helloworld directory. Cd into this directory. You’ll see several files have been created for you:

$ cd helloworld
$ ls -la
drwxr-xr-x   .chalice
-rw-r--r--   app.py
-rw-r--r--   requirements.txt

You can ignore the .chalice directory for now, the two main files we’ll focus on is app.py and requirements.txt.

Let’s take a look at the app.py file:

from chalice import Chalice

app = Chalice(app_name='helloworld')


@app.route('/')
def index():
    return {'hello': 'world'}

The new-project command created a sample app that defines a single view, /, that when called will return the JSON body {"hello": "world"}.

Deploying

Let’s deploy this app. Make sure you’re in the helloworld directory and run chalice deploy:

$ chalice deploy
Creating deployment package.
Creating IAM role: helloworld-dev
Creating lambda function: helloworld-dev
Creating Rest API
Resources deployed:
  - Lambda ARN: arn:aws:lambda:us-west-2:123456789012:function:helloworld-dev
  - Rest API URL: https://abcd.execute-api.us-west-2.amazonaws.com/api/

You now have an API up and running using API Gateway and Lambda:

$ curl https://abcd.execute-api.us-west-2.amazonaws.com/api/
{"hello": "world"}

Try making a change to the returned dictionary from the index() function. You can then redeploy your changes by running chalice deploy.

Next Steps

You’ve now created your first app using chalice. You can make modifications to your app.py file and rerun chalice deploy to redeploy your changes.

At this point, there are several next steps you can take.

  • Tutorials - Choose from among several guided tutorials that will give you step-by-step examples of various features of Chalice.

  • Topics - Deep dive into documentation on specific areas of Chalice. This contains more detailed documentation than the tutorials.

  • API Reference - Low level reference documentation on all the classes and methods that are part of the public API of Chalice.

If you’re done experimenting with Chalice and you’d like to cleanup, you can use the chalice delete command, and Chalice will delete all the resources it created when running the chalice deploy command.

$ chalice delete
Deleting Rest API: abcd4kwyl4
Deleting function arn:aws:lambda:region:123456789012:function:helloworld-dev
Deleting IAM Role helloworld-dev

Feedback

We’d also love to hear from you. Please create any GitHub issues for additional features you’d like to see over at https://github.com/aws/chalice/issues.

Metadata

Release files for chalice 1.33.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chalice 1.33.0
File Size Uploaded
chalice-1.33.0.tar.gz 256.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chalice 1.33.0
File Interpreter ABI Platform
chalice-1.33.0-py3-none-any.whl Python 3 none any Details

Total release size: 522.8 kB

Release files / chalice-1.33.0.tar.gz

Download URL chalice-1.33.0.tar.gz
Size 256.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a2b483e0365d676e3b5a8e1315a8729406ec11f8360f73d106013200992d7b6e
BLAKE2b-256 checksum
How to use checksums
529af55061c92e33b4543af437a20fb555386f2b195f96a90e1daad977a04b5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.15

Release files / chalice-1.33.0-py3-none-any.whl

Download URL chalice-1.33.0-py3-none-any.whl
Size 265.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7748cac1e23633c3e72e6de5a17a90627dd0335cc3166ef7fc7043b6d4792ca
BLAKE2b-256 checksum
How to use checksums
5bedc721931d966d135387ab2d5404a026ca0ae205325fbac4b8f9ac91a45186
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

1.33.0 This release

2 release files

1.32.0

2 release files

1.31.3

2 release files

1.31.2

2 release files

1.31.1

2 release files

1.31.0

2 release files

1.30.0

2 release files

1.27.2

2 release files

1.27.0

2 release files

1.26.5

2 release files

1.26.1

2 release files

1.26.0

2 release files

1.25.0

2 release files

1.24.2

2 release files

1.24.0

2 release files

1.23.0

2 release files

1.22.4

2 release files

1.22.3

2 release files

1.22.0

2 release files

1.21.9

2 release files

1.21.7

2 release files

1.21.6

2 release files

1.21.4

2 release files

1.21.3

2 release files

1.21.2

2 release files

1.20.1

2 release files

1.20.0

2 release files

1.18.1

2 release files

1.18.0

2 release files

1.16.0

2 release files

1.15.1

2 release files

1.15.0

2 release files

1.14.1

2 release files

1.14.0

2 release files

1.12.0

2 release files

1.11.1

2 release files

1.11.0

2 release files

1.9.1

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page