-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2883 from ogghead/dynamo-key-value-store
Implement AWS key value store
- Loading branch information
Showing
13 changed files
with
1,216 additions
and
63 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "spin-key-value-aws" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
async-once-cell = "0.5.4" | ||
aws-config = "1.1.7" | ||
aws-credential-types = "1.1.7" | ||
aws-sdk-dynamodb = "1.49.0" | ||
serde = { workspace = true } | ||
spin-core = { path = "../core" } | ||
spin-factor-key-value = { path = "../factor-key-value" } | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
mod store; | ||
|
||
use serde::Deserialize; | ||
use spin_factor_key_value::runtime_config::spin::MakeKeyValueStore; | ||
use store::{ | ||
KeyValueAwsDynamo, KeyValueAwsDynamoAuthOptions, KeyValueAwsDynamoRuntimeConfigOptions, | ||
}; | ||
|
||
/// A key-value store that uses AWS Dynamo as the backend. | ||
#[derive(Default)] | ||
pub struct AwsDynamoKeyValueStore { | ||
_priv: (), | ||
} | ||
|
||
impl AwsDynamoKeyValueStore { | ||
/// Creates a new `AwsKeyValueStore`. | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
} | ||
|
||
/// Runtime configuration for the AWS Dynamo key-value store. | ||
#[derive(Deserialize)] | ||
pub struct AwsDynamoKeyValueRuntimeConfig { | ||
/// The access key for the AWS Dynamo DB account role. | ||
access_key: Option<String>, | ||
/// The secret key for authorization on the AWS Dynamo DB account. | ||
secret_key: Option<String>, | ||
/// The token for authorization on the AWS Dynamo DB account. | ||
token: Option<String>, | ||
/// The AWS region where the database is located | ||
region: String, | ||
/// Boolean determining whether to use strongly consistent reads. | ||
/// Defaults to `false` but can be set to `true` to improve atomicity | ||
consistent_read: Option<bool>, | ||
/// The AWS Dynamo DB table. | ||
table: String, | ||
} | ||
|
||
impl MakeKeyValueStore for AwsDynamoKeyValueStore { | ||
const RUNTIME_CONFIG_TYPE: &'static str = "aws_dynamo"; | ||
|
||
type RuntimeConfig = AwsDynamoKeyValueRuntimeConfig; | ||
|
||
type StoreManager = KeyValueAwsDynamo; | ||
|
||
fn make_store( | ||
&self, | ||
runtime_config: Self::RuntimeConfig, | ||
) -> anyhow::Result<Self::StoreManager> { | ||
let AwsDynamoKeyValueRuntimeConfig { | ||
access_key, | ||
secret_key, | ||
token, | ||
region, | ||
consistent_read, | ||
table, | ||
} = runtime_config; | ||
let auth_options = match (access_key, secret_key) { | ||
(Some(access_key), Some(secret_key)) => { | ||
KeyValueAwsDynamoAuthOptions::RuntimeConfigValues( | ||
KeyValueAwsDynamoRuntimeConfigOptions::new(access_key, secret_key, token), | ||
) | ||
} | ||
_ => KeyValueAwsDynamoAuthOptions::Environmental, | ||
}; | ||
KeyValueAwsDynamo::new( | ||
region, | ||
consistent_read.unwrap_or(false), | ||
table, | ||
auth_options, | ||
) | ||
} | ||
} |
Oops, something went wrong.