AWS Chalice

1.32.0 · active · verified Wed Apr 15

Chalice is a microframework for writing serverless applications in Python. It allows developers to quickly create and deploy applications that leverage AWS Lambda and Amazon API Gateway. It features a command-line tool for project management, a decorator-based API for integrating with various AWS services (like S3, SNS, SQS), and automatic IAM policy generation. Currently at version 1.32.0, Chalice is actively maintained by AWS.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a basic REST API with Chalice. After installing Chalice and configuring AWS credentials, create a new project using `chalice new-project <project-name>`, then update `app.py` with the provided code. Deploy the application to AWS Lambda and API Gateway with `chalice deploy`.

import os
from chalice import Chalice

# Configure AWS credentials if not already set up via AWS CLI
# os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY')
# os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY')
# os.environ['AWS_DEFAULT_REGION'] = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')

app = Chalice(app_name='my-first-chalice-app')

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

@app.route('/greet/{name}')
def greet_name(name):
    return {'message': f'Hello, {name}!'}

# To deploy:
# 1. Ensure AWS CLI is configured with credentials.
# 2. Run `chalice new-project my-first-chalice-app`
# 3. Replace the generated `app.py` content with the code above.
# 4. Run `chalice deploy` in your project directory.
# To test locally: `chalice local`
# To delete: `chalice delete`

view raw JSON →