Local dynamodb serverless code#
This approach sets you up to rapidly iterate on code locally, deploying to your dev environment only when they need to make environment configuration changes or they have made significant progress on function code.
The bottom line? Fast local development cycles, reduced debugging friction, and the ability to ship new functionality faster as a result. This setup cuts off that entire class of problems. For example, one common debugging headache results from different service to service permissions and configurations between local and cloudside resources. The result? Consistency between how you code behaves locally and the cloudside environment. This avoids the need for keeping a local copy of environment variables and other forms of bookkeeping needed to integrate with cloudside services. A key component of this approach is to query the environment and IAM configuration directly from your cloudside development environment. No need to maintain localhost mocks of cloudside servicesįollowing this approach, you will execute local versions of your function code in the context of a deployed cloudside environment. There is a best practice today for creating a serverless dev environment. Pull Cloudside Services to Your Local Code The Optimal Local Serverless Development Workflow With this approach, the local environment is not consistent with the cloudside environment, and somewhat cruelly, any bugs resulting from these inconsistencies will still need to be debugged and resolved cloudside which means more time spent following Suboptimal Approach #1. Inevitably there will be inconsistencies between the local mocks and real cloudside services, especially for recently added features. Most significantly, fully replicating AWS' rapidly evolving suite of cloud services is a monumental task. While this approach may initially appear attractive it comes with a number of significant downsides. Many developers figure out ways to mock AWS service calls to speed up their dev cycles and there are even projects such as localstack which attempt to provide a fully functional local AWS cloud environment. Suboptimal Approach #2: Mock cloud services locallyĪnother common approach is to create mock versions of the cloud services to be used in the local environment. This makes it more likely problems will emerge in upstream environments. While this does improve the inner loop cycle time it is still significantly slower than executing in a local environment and creates inconsistency in the cloudside environment.
For example, Serverless Framework's sls deploy -f quickly packages and deploys an individual function. In some cases, these minor code change deploy times can be made faster, but only to a point and often at the cost of consistency. The primary disadvantage of this is that developers must wait for the deploy process to complete for each minor code change. One common approach is to avoid developing locally and deploy each change to the cloud to run in the cloudside environment. Suboptimal Approach #1: Push each change to the cloud
However, there are a few common approaches to the serverless developer workflow which we know results in suboptimal developer workflows and productivity. Serverless architecture is still relatively new so best practices are evolving and not widely known. This is an area where Stackery has a long history in helping developers express, deploy, and manage the pipeline of promoting applications to production.Ĭommon Suboptimal Inner Loop Approaches to Serverless Local Development The outer loop changes in service configurations and application architectures occur less rapidly- maybe a few times a day for apps under active development.
This cuts down on the number of code changes a developer can make in a day and results in context switching and frustration. When this happens developers spend most of their time waiting for new versions of their code to deploy to the cloud where it can be run and analyzed (before making the next change). Today many serverless developers are forced into a slow inner loop which takes several minutes to complete. In a traditional local development environment, this loop can be completed in 3-10 seconds, meaning a developer can make and test many code changes in a minute.