Refactoring, a popular coding technique is defined by Martin Folwer as:
A disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
Refactoring to Serverless aims to move code from the application to CDK automation.
There are multiple benefits to refactoring your solution to serverless:
- The refactored code better leverages platform capabilities. Automation features don't need code library upgrades, testing, or debugging. They also generally scale better and are more robust than application code.
- AWS continually adds new services and capabilities, so you might find that you had written application code for a function that can now be done using a service capability. Time to refactor!
- Occasionally your application's needs outgrow the capability of one service. For example, EventBridge has many features to filter incoming messages but if your application's needs evolve to require a complex rule across multiple fields, you might need to refactor from EventBridge to a custom lambda function.
- Refactoring to serverless can improve your run-time characteristics and reduce cost. For example, if you can replace polling for results with a callback or a wait state, you reduce latency and cost.
Because of these benefits, refactoring should be an integral part of serverless development.
This repo is AWS CDK implementation for the patterns in Refactorings to Serverless.
Name | Description |
---|---|
Extract Function Invocation | Instead of calling one Lambda function directly from another, use Lambda Destinations instead |
Extract Send Message to Lambda Destination | Instead of sending SQS messages via code, use Lambda Destinations instead |
Replace Lambda with Service Integration | Service integration allows direct calls to any AWS Service API from StepFunctions without the need for an additional Lambda function |
Replace Polling with Callback | Instead of polling for results, use StepFunctions Wait for a Callback with the Task Token |
Direct database access | Replace a Lambda function that only reads from DynamoDB with Step Functions' getItem task |
Extract Send Message to DynamoDB Stream | Instead of a Lambda function sending a message after updating DynamoDB, use DynamoDB Streams plus EventBridge Pipes |
Gregor Hohpe, Enterprise Strategist, AWS
Sindhu Pillai, Sr. Solutions Architect, AWS
Svenja Raether,Associate ProServe Specialist, AWS
Abel Fresnillo Silva, Sr. Solutions Architect, AWS
Eugene Kim, Sr. Solutions Architect, AWS
More details here