Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Serverless is a great platform for managing your serverless infrastructure. It significantly reduces boilerplate code for setting up a service and defining functions. It even allows defining platform specific resources for things that aren’t supported out of the box. The problem is that service providers can require complex templates to support basic infrastructure. For example, AWS CloudFormation requires defining DynamoDB keys under two different fields for a single table. Therefore I created a plugin that would simplify table definitions, reduce boilerplate code and have smart defaults: serverless-plugin-tables.
Let’s see an example
Below are two example servlerless.yml definitions for a table described in the DynamoDB documentation. The first example is using the standard CloudFormation template and the second is using serverless-plugin-tables.
As you can see, the serverless-plugin-tables implementation has significantly reduced boilerplate (1/3 the lines). It also has sane defaults, using On-Demand Billing Mode and strings as the default data types. Despite being so simple to define, it is fully customizable, supporting every CloudFormation option at the time of release. See the complete example in the Readme.
Sounds great! Let’s incorporate it!
First, add the dependency to your existing Serverless project:
yarn add -D serverless-plugin-tables
Now add the plugin to your service file:
# serverless.yml
plugins: - serverless-plugin-tables
Now define the `resources` section if you don’t already have one, add a tables property, and start creating tables 🤩
# serverless.yml
resources: tables: # Start defining tables here
Here is another table example for Users, with a little more configuration:
For even more configuration options, check out the GitHub Readme, which describes each option along with links to the AWS documentation.
What about other providers and databases?
I started off the project by implementing it for AWS DynamoDB. However, I designed it so it can easily expand to support other service providers and database platforms. So if there is another platform you want to be supported, comment here or submit an issue on GitHub.
Let me know what you think. Leave a comment below and give me some claps. The longer you hold the claps button, the more I get 👏👏👏
Manage table resources in serverless was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.