Table of Contents
List of Tables
List of Examples
This module is an implementation of a cachedb system designed to work with Amazon DynamoDB. It uses the AWS SDK library for C++ to connect to a DynamoDB instance. It leverages the Key-Value interface exported from the core.
https://aws.amazon.com/pm/dynamodb/
set - sets a key in DynamoDB using the cachedb_store function
get - queries a key from DynamoDB using the cachedb_fetch function
remove - removes a key from DynamoDB using the cachedb_remove function
get_counter - queries a key with a numerical value from DynamoDB using the cachedb_counter_fetch function
add - increments the value of a specific item with a given value using the cachedb_add function
sub - decrements the value of a specific item with a given value using the cachedb_sub function
The following are internally used by OpenSIPS:
map_get
map_set
map_remove
The tables used with DynamoDB must adhere to a specific format. Below is an example of creating a table:
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")"
For additional examples of how cachedb_url should be formatted, refer to the cachedb_url (string) section.
To enable TTL (Time to Live) for the table, which can be used with operations like set, add, and subtract, 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"
For additional information about the table format and TTL options, follow these links:
scalable and fully managed NoSQL database service provided by AWS
integrated with other AWS services, providing robust security and scalability features
high availability and durability due to data replication across multiple AWS Availability Zones
serverless architecture, reducing operational overhead
offers single-digit response times, with DynamoDB Accelerator (DAX) for even lower latencies
relies heavily on indexes; without them, querying involves costly full table scans
does not support table joins, limiting complex queries involving multiple tables
item size limit:each item has a size limit of 400KB, which cannot be increased.
The following libraries or applications must be installed before running OpenSIPS with this module loaded:
AWS SDK for C++:
By following these steps, you'll have the AWS SDK for C++ installed and configured on your Linux system, allowing you to integrate with DynamoDB: AWS SDK for C++ Installation Guide
Additional instructions for installation can be found at: AWS SDK for C++ GitHub Repository
For testing purposes, you can run a DynamoDB locally. To achieve this, you should follow these steps in order to deploy dynamodb locally.
Don't forget to always run the server using this command:
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
in the directory where you extracted DynamoDBLocal.jar.
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"
Syntax for cachedb_url
when using a previously created table (you have to specify the key and value):
host and port
"dynamodb://id_host:id_port/tableName?key=key1;val=val1"
region
"dynamodb:///tableName?region=regionName;key=key2;val=val2"
when using the default key and value:
host and port
"dynamodb://id_host:id_port/tableName"
region
"dynamodb:///tableName?region=regionName"
Example 1.1. Set cachedb_url
parameter
...
# 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 (will perform circular failover on each query)
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")
...
Example 1.2. Use Dynamodb servers
... cache_store("dynamodb", "call1", "10"); cache_store("dynamodb", "call2", "25", 150) // expires = 150s -optional cache_fetch("dynamodb", "call1", $var(total)); cache_remove("dynamodb", "call1"); cache_store("dynamodb", "counter1", "200"); cache_sub("dynamodb", "counter1", 4, 1000); // expires = 1000s -mandatory parameter cache_add("dynamodb", "call2", 5, 0) // -this update will not expire -mandatory parameter cache_remove("dynamodb", "counter1"); ...
Table 2.1. Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
Name | DevScore | Commits | Lines ++ | Lines -- | |
---|---|---|---|---|---|
1. | Alexandra Titoc | 67 | 17 | 3573 | 1192 |
2. | Razvan Crainea (@razvancrainea) | 6 | 2 | 0 | 213 |
(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)
(2) including any documentation-related commits, excluding merge commits. Regarding imported patches/code, we do our best to count the work on behalf of the proper owner, as per the "fix_authors" and "mod_renames" arrays in opensips/doc/build-contrib.sh. If you identify any patches/commits which do not get properly attributed to you, please submit a pull request which extends "fix_authors" and/or "mod_renames".
(3) ignoring whitespace edits, renamed files and auto-generated files
Table 2.2. Most recently active contributors(1) to this module
Name | Commit Activity | |
---|---|---|
1. | Alexandra Titoc | Jul 2024 - Sep 2024 |
2. | Razvan Crainea (@razvancrainea) | Aug 2024 - Aug 2024 |
(1) including any documentation-related commits, excluding merge commits
Last edited by: Razvan Crainea (@razvancrainea), Alexandra Titoc.
Documentation Copyrights:
Copyright © 2024 www.opensips-solutions.com