
Amazon DynamoDB is a NoSQL database, designed to handle the scaling and operational challenges of relational databases. DynamoDB aims to offer high availability and resilience for worldwide applications. With automatic scaling and no maintenance requirements, DynamoDB ensures consistent performance for applications of any size.
Adding DynamoDB support to OpenSIPS makes it even smoother to integrate OpenSIPS with AWS environment and services. It offers straightforward access to a powerful database through the AWS library, speeding up rollout and service creation.
The new module is called cachedb_dynamodb. It implements the cachedb interface, enabling operations like setting, fetching, and removing cache items directly in DynamoDB. The module leverages the AWS SDK for C++ to connect to a DynamoDB instance and supports key-value store operations, making it easy to integrate and use within OpenSIPS.
Dependencies
The cachedb_dynamodb module depends on the AWS SDK for C++. Ensure that you have the AWS SDK for C++ installed and configured on your Linux system. You can follow the AWS SDK for C++ Installation Guide. Additional instructions can be found on the AWS SDK for C++ GitHub Repository.
Usage
Local vs region
You can use Amazon DynamoDB both locally for testing and development, and as a fully managed service in AWS for production.
Using DynamoDB Locally:
- Download DynamoDB Local: Visit the DynamoDB Local download page and download the DynamoDBLocal.jar file.
- Run DynamoDB Local: “java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb”
This command starts a local DynamoDB instance that you can use for testing and development without incurring any costs or requiring an internet connection.
Using DynamoDB in AWS for Production:
- Create a DynamoDB Table: Use the AWS Management Console, CLI, or SDK to create a DynamoDB table in your preferred region.
- Configure Security: Set up IAM roles and policies to manage access to your DynamoDB tables.
- Scale Automatically: DynamoDB automatically handles scaling, ensuring it meets the demands of your application without manual intervention. More details can be found in the DynamoDB Auto Scaling documentation.
- Integration with Other AWS Services: DynamoDB integrates seamlessly with other AWS services such as Lambda, S3, and Kinesis, providing a comprehensive solution for building scalable applications.
By using DynamoDB locally, you can develop and test your applications cost-effectively. For production, AWS-managed DynamoDB offers unmatched scalability, reliability, and integration with other AWS services.
Prerequisites
Before running OpenSIPS with the “cachedb_dynamodb” module, make sure you have completed these steps:
- Install the AWS SDK for C++
- Create a DynamoDB table
- Configure the cachedb_url parameter with the appropriate DynamoDB table details.
Example of creating a table from CLI:
aws dynamodb create-table --table-name TableName \
--attribute-definitions \
AttributeName=KeyName,AttributeType=S \
--key-schema \
AttributeName=KeyName,KeyType=HASH \
--provisioned-throughput \
ReadCapacityUnits=5,WriteCapacityUnits=5 \
--table-class STANDARD
If you create the table using the above command, then you have to specify the key in the cachedb_url: modparam(“cachedb_dynamodb”, “cachedb_url”, “dynamodb://localhost:8000/TableName?key=KeyName;val=ValName”)”
URLs
The URLs of the server groups that OpenSIPS will connect to in order to use, from script, the cache_store(), cache_fetch(), etc. operations. It may be set more than once. The prefix part of the URL will be the identifier that will be used from the script.
There are some default parameters that can appear in the URL:
- region – specifies the AWS region where the DynamoDB table is located
- key – specifies the table’s Key column; default value is “opensipskey”
- val – specifies the table’s Value column on which cache operations such as cache_store, cache_fetch, etc., will be performed; default value is “opensipsval”
Examples for cachedb_url:
- Single-instance URLs:
modparam(“cachedb_dynamodb”, “cachedb_url”, “dynamodb://localhost:8000/table1”);
modparam(“cachedb_dynamodb”, “cachedb_url”, “dynamodb:///table2?region=central-1”); - multi-instance URL:
modparam(“cachedb_dynamodb”, “cachedb_url”, “dynamodb://localhost:8000/table1?key=Key;val=Val”);
modparam(“cachedb_dynamodb”, “cachedb_url”, “dynamodb:///table2?region=central-1;key=Key;val=Val”);
Scripting
cache_store("dynamodb", "call1", "10");
// ttl = 150s ->optional
cache_store("dynamodb", "call2", "25", 150);
cache_fetch("dynamodb", "call1", $var(total));
cache_remove("dynamodb", "call1");
cache_store("dynamodb", "counter1", "200");
// ttl = 1000s ->mandatory parameter
cache_sub("dynamodb", "counter1", 4, 1000);
// -this update will not expire -mandatory parameter
cache_add("dynamodb", "call2", 5, 0);
cache_remove("dynamodb", "counter1");
To enable TTL (Time to Live) for the table, you can update the table with the TTL option:
aws dynamodb update-time-to-live \--table-name TableName \--time-to-live-specification "Enabled=true, \ AttributeName=ttl"
Conclusions
In summary, integrating Amazon DynamoDB with OpenSIPS provides a robust and scalable solution for managing real-time communication data. The cachedb_dynamodb module allows seamless interaction with DynamoDB, leveraging its high availability, durability, and low latency. By following the provided guidelines, dependencies and examples, you can efficiently set up and utilize this integration for enhanced performance and reliability in your OpenSIPS deployments.
This is the first version of the cachedb_dynamodb module, and we are open to feedback regarding other usage cases that you find useful to integrate into the module.
We encourage you to share your suggestions and needs for future extensions so that we can improve and expand the module.
