Skip to content

Conversation

@SMCodesP
Copy link

Summary

This PR adds native AWS Lambda deployment support to Loco, aiming to provide a simple way to deploy applications to AWS Lambda with just a single command—much like Zappa does for Python projects. It's my first Pull Request here, so I'm really excited but also a bit nervous; I'm not entirely sure if I should be opening this yet or if it's ready for review. If there's anything I need to adjust, add, or fix, please just let me know—I'm happy to iterate!

Motivation

While Loco already supports Docker and Shuttle deployments, AWS Lambda support opens the door to the massive AWS ecosystem.

The implementation is inspired by Zappa, the popular Python framework for serverless deployment. Like Zappa, this feature:

  • Requires minimal configuration
  • Creates temporary files during deployment and cleans up automatically
  • Provides a simple CLI interface for deploy, invoke, and logs
  • Works out of the box with sensible defaults

CLI Commands

Deploy to AWS Lambda

cargo loco lambda deploy

Build only (dry run)

cargo loco lambda deploy --dry-run

Invoke the deployed function

cargo loco lambda invoke
cargo loco lambda invoke --payload '{"httpMethod": "GET", "path": "/api/users"}'

View CloudWatch logs

cargo loco lambda logs
cargo loco lambda logs --follow

The handler uses the lambda_http crate to adapt HTTP requests from API Gateway or Lambda Function URLs to Axum-compatible requests, which Loco handles natively.

Dependencies

This feature requires Cargo Lambda to be installed:

cargo install cargo-lambda

No new Rust dependencies are added to Loco itself—the Lambda runtime dependencies are only added to the user's project during the build process.

Testing

Tested with a fresh Loco API project:

  1. Created new project with cargo loco new
  2. Configured Lambda settings in config/development.yaml
  3. Deployed with cargo loco lambda deploy
  4. Invoked with cargo loco lambda invoke
  5. Verified logs with cargo loco lambda logs

Related

- Introduced AWS Lambda deployment configuration in development.yaml.
- Added CLI commands for deploying, invoking, and logging Lambda functions.
- Implemented Lambda handler template and deployment context management.
- Enhanced Config struct to include Lambda settings.
… for AWS Lambda

- Updated CLI commands to better reflect AWS Lambda deployment functionality.
- Renamed DeployCommands to LambdaCommands for clarity.
- Introduced a new module for Lambda deployment utilities and added a handler template.
- Enhanced deployment context management for temporary file handling.
- Updated main command handling to accommodate new command structure.
…ation examples

- Added comprehensive AWS Lambda deployment instructions to the deployment.md file.
- Included prerequisites, configuration options, deployment commands, invocation examples, and log viewing instructions.
- Updated development.yaml template comments to clarify Lambda deployment command usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant