{"id":6561,"library":"chalice","title":"AWS Chalice","description":"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.","status":"active","version":"1.32.0","language":"en","source_language":"en","source_url":"https://github.com/aws/chalice","tags":["aws","serverless","lambda","api-gateway","microframework","python"],"install":[{"cmd":"pip install chalice","lang":"bash","label":"Install Chalice"}],"dependencies":[{"reason":"Chalice internally uses the AWS SDK for Python to interact with AWS services, including deployment and runtime operations.","package":"boto3"},{"reason":"Required for configuring AWS credentials, which Chalice relies on for deployment and local testing.","package":"awscli","optional":true}],"imports":[{"symbol":"Chalice","correct":"from chalice import Chalice"},{"note":"Used for customizing HTTP responses (status codes, headers, non-JSON bodies).","symbol":"Response","correct":"from chalice import Response"},{"note":"Used with @app.schedule decorator for defining scheduled events.","symbol":"Rate, Cron","correct":"from chalice import Rate, Cron"}],"quickstart":{"code":"import os\nfrom chalice import Chalice\n\n# Configure AWS credentials if not already set up via AWS CLI\n# os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY')\n# os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY')\n# os.environ['AWS_DEFAULT_REGION'] = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')\n\napp = Chalice(app_name='my-first-chalice-app')\n\n@app.route('/')\ndef index():\n    return {'hello': 'world'}\n\n@app.route('/greet/{name}')\ndef greet_name(name):\n    return {'message': f'Hello, {name}!'}\n\n# To deploy:\n# 1. Ensure AWS CLI is configured with credentials.\n# 2. Run `chalice new-project my-first-chalice-app`\n# 3. Replace the generated `app.py` content with the code above.\n# 4. Run `chalice deploy` in your project directory.\n# To test locally: `chalice local`\n# To delete: `chalice delete`","lang":"python","description":"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`."},"warnings":[{"fix":"Manually review `.chalice/policy.json` and refine permissions, or use `manage_iam_role=False` in `.chalice/config.json` and provide your own IAM role ARN.","message":"Chalice automatically generates IAM policies for your Lambda functions. While convenient, these auto-generated policies can sometimes be overly permissive. For production environments, it's recommended to review the generated policies (in `.chalice/policy.json`) and manually refine them or disable auto-generation using `manage_iam_role=False` in `config.json` or the `--no-autogen-policy` flag during deployment for fine-grained control.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your local AWS CLI profile (e.g., `~/.aws/credentials`, `~/.aws/config`) has sufficient permissions for all AWS services your Chalice app uses.","message":"When using `chalice local` for local development and testing, the application runs in your local environment and uses your configured AWS CLI credentials, not the IAM role that would be assumed by the Lambda function in AWS. Ensure your local AWS profile has the necessary permissions to access any AWS services (e.g., DynamoDB, S3) your application interacts with during local testing.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If using `@app.on_s3_event`, use `chalice deploy` for direct deployment rather than `chalice package`.","message":"The `@app.on_s3_event` decorator, used for triggering Lambda functions from S3 events, is incompatible with the `chalice package` command. If your application uses S3 event sources, you cannot use `chalice package` to generate a CloudFormation/SAM template; you must deploy directly using `chalice deploy`.","severity":"breaking","affected_versions":"All versions"},{"fix":"Check AWS Lambda's current Python runtime support and ensure your development environment and `runtime` configuration in `.chalice/config.json` are compatible.","message":"AWS Lambda has specific Python runtime versions it supports. While Chalice aims to support these, always verify that your local Python environment matches a supported AWS Lambda runtime (e.g., Python 3.9 through 3.13 are currently supported) to avoid deployment issues or unexpected behavior.","severity":"gotcha","affected_versions":"Older versions might have narrower support, but current versions align with AWS Lambda's latest runtimes."}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}