Povery is a framework for developing AWS Lambda functions with TypeScript. This CLI tool facilitates local development, testing, and deployment of serverless applications.
Povery CLI enables developers to:
- Locally serve multiple Lambda functions as an HTTP server
- Invoke Lambda functions locally via terminal
- Deploy Lambda functions to AWS environments
Unlike other serverless frameworks, Povery CLI focuses exclusively on Lambda function management without infrastructure provisioning. This adheres to the principle of separation of concerns between application logic and infrastructure management.
The local development server functionality is built on top of the Serverless Framework, leveraging its offline capabilities to simulate AWS Lambda and API Gateway locally. This integration provides a high-fidelity local development experience that closely mirrors the AWS production environment while maintaining a streamlined developer workflow.
The CLI requires a specific project structure:
/<project_root>
lambda/
API_Something/
index.ts
EVENT_Something/
index.ts
event.json
povery.json
- All Lambda functions must reside in the
lambda/directory - Each Lambda function requires
index.tsas its entry point - API Gateway Lambda functions must:
- Use proxy integration for API requests
- Use the prefix
API_(e.g.,API_UserService) - Start with a capital letter
- Event-driven Lambda functions must:
- Use the prefix
EVENT_(e.g.,EVENT_DataProcessor) - Start with a capital letter
- Use the prefix
{
"compilerOptions": {
"target": "es2020",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"moduleResolution": "node",
"baseUrl": "./",
"outDir": "./build",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"allowJs": true, // this is to allow custom authorizer
"paths": {
"povery": ["node_modules/povery"]
}
},
}
npm i -D povery-cliAdd to your package.json:
{
"scripts": {
"povery": "povery-cli"
}
}Usage:
npm run poveryWhen passing options:
npm run povery function deploy API_UserService -- --stage devnpm i -g povery-clipovery-cli --helppovery-cli start [options]Options:
-t, --timeout <seconds>: Set the Lambda timeout in seconds (default: 30)
Configure routes in povery.json:
{
"lambdas": {
"API_UserService": [
{
"method": "ANY",
"path": "/{proxy+}"
}
]
}
}On Authorization: for lambdas that needs Authentication and Authorization, you must add the "authorized": true field for the specific method call, like in the following example
{
"lambdas": {
"API_UserService": [
{
"method": "ANY",
"path": "/{proxy+}"
"authorized": true
}
]
}
}Start the local server:
povery-cli startYou can customize the Lambda timeout for local development:
povery-cli start --timeout 60This sets the Lambda timeout to 60 seconds (default is 30 seconds) which is useful for debugging or when working with long-running operations.
By default, Lambda functions have a 30-second timeout when running locally. If you're experiencing timeout issues during debugging or when working with long-running operations, you can increase this limit using the --timeout parameter.
Execute a Lambda function with the event.json file in its directory:
povery-cli function invoke EVENT_DataProcessorWhen sharing code between Lambda functions, use TypeScript path aliases instead of relative imports:
// Incorrect - will break transpilation
import { Something } from '../../common/something.ts';
// Correct
import { Something } from '@common/something.ts';Configure tsconfig.json with appropriate path mappings:
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@common/*": "common/*",
"povery": "node_modules/povery"
}
}
}The explicit povery path mapping prevents esbuild transpilation issues.
The povery.json file supports the following configuration options:
""(empty string): Deploys Lambda functions without prefix or alias (e.g.,API_UserService)STAGE_PREFIX: Deploys with stage name as prefix (e.g.,dev_API_UserService)STAGE_ALIAS: Deploys with stage name as alias (e.g.,API_UserService:dev)
Specifies a custom script to run instead of the default npm install during Lambda build.
Provides configuration options for esbuild:
{
"esbuild": {
"external": ["pg"]
}
}This is particularly useful for:
- Excluding libraries that should be deployed as Lambda Layers
- Handling libraries with compilation errors or dynamic imports
- Optimizing large dependencies that could impact cold start performance
Interactive mode:
povery-cli functionDirect deployment:
povery-cli function deploy <lambda_name>Deploy all Lambda functions (ideal for CI/CD pipelines):
povery-cli deployPovery CLI follows a structured process when building Lambda functions:
-
Clean Build Directory:
- Removes the
.distdirectory for the specified Lambda function - Creates a fresh
.distdirectory for the build output
- Removes the
-
Install Dependencies:
- Creates a temporary build folder (
.tmp) if it doesn't exist - Copies the main
package.jsonto the temporary folder - Runs
npm install --omit=dev(or a custom install script specified inpovery.json) - Creates a symbolic link from the temporary
node_modulesto the Lambda's.dist/node_modules
- Creates a temporary build folder (
-
TypeScript Compilation:
- Creates symbolic links for path aliases defined in
tsconfig.json - Generates a temporary Lambda-specific
tsconfig.jsonwith appropriate settings - Validates TypeScript code with
tsc --noEmit - Bundles the code using esbuild with:
- Entry point:
./lambda/<functionName>/index.ts - Output:
./lambda/<functionName>/.dist/index.js - Minification enabled
- Source maps generated
- External dependencies excluded as specified in
povery.json
- Entry point:
- Cleans up temporary files and symlinks
- Creates symbolic links for path aliases defined in
-
Package Creation:
- Creates a ZIP file containing:
- The compiled JavaScript file (
index.js) - Source map file (
index.js.map)
- The compiled JavaScript file (
- Outputs the ZIP to
./lambda/<functionName>/.dist/<functionName>.zip
- Creates a ZIP file containing:
-
Deployment (if requested):
- Uploads the ZIP file to AWS Lambda using the AWS SDK
- Updates the function code with the new package
- Applies the appropriate naming strategy based on
deployStrategyinpovery.json
This process can be initiated in several ways:
# Interactive mode
povery-cli function
# Direct build (package only)
povery-cli function build <functionName>
# Direct deployment (build and publish)
povery-cli function deploy <functionName>
# With environment option
povery-cli function deploy <functionName> --environment prod
# Force dependency reinstallation
povery-cli function deploy <functionName> --nocacheBy default, Povery CLI:
- Minifies code
- Produces a single file with source map
- Optimizes for cold start performance
Enable source maps for debugging by adding this environment variable to your Lambda:
NODE_OPTIONS=--enable-source-maps
Note: This may impact performance and is not recommended for production environments. Consider using error tracking services like Sentry with uploaded source maps instead.
Povery CLI provides several commands for managing the deployment lifecycle of your Lambda functions:
The function command is the primary interface for working with individual Lambda functions:
povery-cli function [operation] [functionName] [options]Available operations:
info: Retrieve information about a deployed Lambda functionbuild: Build the Lambda package without deployingdeploy: Build and deploy the Lambda functionpromote: Promote a Lambda function to a different stageinvoke: Run the Lambda function locally with an eventclean: Remove build artifacts
Options:
-p, --payload <payload>: Specify a payload for function invocation-e, --eventFilename <string>: Specify an event file for invocation-z, --environment <string>: Target environment (default: 'dev')-nc, --nocache: Disable cache and force npm install--auth: Load claims file for authorization testing
If no operation or function name is provided, an interactive wizard will guide you through the process.
To deploy all Lambda functions at once:
povery-cli deploy [options]Options:
-y, --yes: Automatically confirm all prompts-nc, --nocache: Disable cache and force npm install-z, --environment <string>: Target environment (default: 'dev')
To increment the version of all Lambda functions:
povery-cli versionThis command:
- Creates a new version of the
$LATESTLambda function - Sets the
devalias to point to$LATEST
To upload a Lambda Layer:
povery-cli layers [functionName]If no function name is provided, an interactive wizard will guide you through the process.
To promote Lambda functions between stages:
povery-cli promote [stage]Available promotion paths:
dev -> test: Promotes from development to testingtest -> prod: Promotes from testing to production
The promotion process:
- For
dev -> test: Creates a new version and sets thetestalias to that version - For other stages: Copies the version from the source stage to the target stage
To deploy API Gateway configurations:
povery-cli apiThis command allows you to select a stage (dev, staging, prod) and deploys the API Gateway configuration for all Lambda functions.
Create a .envrc file in your project root to define environment variables. All exported variables will be available during local Lambda execution.
Add the following to your .gitignore file:
.serverless.*
Contributions are welcome. Please feel free to submit issues and pull requests.
MIT