-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement AWS key value store #2883
base: main
Are you sure you want to change the base?
Conversation
Kia ora @ogghead and thanks for this. We've got work going on in #2895 to implement some additional key-value interfaces, and I think it works better to land that one first, then have this PR include all the AWS stuff. This is partly down to what has the biggest compatibility implications combined with the present release timeline, but also will hopefully provide enough infrastructure to make extending this PR to the new interfaces easy! I hope that's okay with you. In the meantime, I'll try to have a look at your points for thought! |
I'd say this is fine for now. We could call this a DynamoDB KV store, which would leave us flexibility to later to add a S3 KV backend if users had large object use cases - nothing here would preclude that as long as we think of it as an "AWS product X" store rather than an "AWS" store.
I don't think we are bound to offer a "tokens in the runtime config" option if that doesn't make sense or is painful to implement. I'm not sure we can rely on the workload identity idea from that SKIP across all Spin runtime environments, but absolutely open to doing things differently as appropriate.
This is what we do in the SQS trigger. There's no credential configuration, we just load the SDK and let figure out the credentials, whether from ambient EVs or whatever. I'm told that's idiomatic enough, so I'd have no problem with doing the same thing here. I'm sure someone will shout out if they do - but we could presumably retrofit additional configuration methods if need be - the Cosmos one certainly went through a few sets of extensions... |
Sounds good to me! I'm excited to see that work land. It makes sense to hold off on this for now, then rework after that is merged and support all WASI KV interfaces for AWS. Thanks for taking a look! |
Great callout! The config specifies "Dynamo" as the KV store type, so should hopefully be flexible to add other backends. I will keep this in mind when implementing the full WASI KV interface
The runtime config token setup is (from local testing) working -- but the "use the default SDK config loading" is proving challenging with the current interface constraints. Mainly as the default AWS config loader is implemented as an async function.
Agreed, this is the pattern I followed in the Kinesis trigger as well. I would love to have this here too! The challenge is function coloring from AWS config default loader function -- using that async function here appeared to require a chain of refactoring across the general KV traits, but I must admit that my async Rust knowledge hit a wall when trying to reconcile the changes required for that. |
Ah, I misread your comment about using the default SDK config - sorry about that. It seems like you could call Tokio's |
Good callout -- I tried using
as well as
While these do compile, I see crashes immediately on Spin app startup with
Alternatively, when I went down the path of asyncifying everything required to await this function, I hit a wall at store_from_toml_fn where closures are returned. Async closure enhancements in Rust might be needed to make the closures returned there async, but this is where my knowledge of async Rust was lacking. If any Giant Async Brains (or anyone) have ideas on the best path forward on this, much appreciated! |
All right. I think I have a way around this for you. "But," in the words of Deep Thought, "you're not going to like it." So I asked the Giant Async Brains about blocking on Here is what I did, which seems to work (but you may find a less awful way, this was just the first stab that didn't make the compiler mad at me):
let client_fut: std::pin::Pin<Box<dyn std::future::Future<Output = Client> + Send>> = Box::pin(async move {
let config = match auth_options {
KeyValueAwsDynamoAuthOptions::RuntimeConfigValues(config) => /* as current */,
KeyValueAwsDynamoAuthOptions::Environmental => {
aws_config::load_defaults(BehaviorVersion::latest()).await // as before but uncommented
}
};
Client::new(&config)
});
let client_cell = async_once_cell::Lazy::from_future(client_fut);
Ok(Self { client: client_cell, table }) (Some of the naming here is poor, this was throwaway code.)
async fn get(&self, name: &str) -> Result<Arc<dyn Store>, Error> {
Ok(Arc::new(AwsDynamoStore {
_name: name.to_owned(),
client: self.client.get_unpin().await.clone(), // <-- this bit
table: self.table.clone(),
}))
} NOTE: this breaks Let me know if you need more info or want a proper diff. |
Excellent! This is exactly the Galaxy Async Brain thinking I was sorely lacking 😄 I will give this a go tonight, thanks for the tips! |
74e7705
to
0ecf501
Compare
Can confirm this worked like a charm! Pushed the changes to reflect and I will keep an eye on the full WASI KV implementation PR. I am in your debt for your help on this @itowlson :) One does not simply walk into |
I'm delighted to have helped! Thanks once again for your effort, your patience, and your good humour throughout this... ... ...because you will need them when I call that debt in. ominous music and cheesy lightning FX in which the viewer can vaguely make out the looming shape of (also, and at the risk of bathos, please ignore MQTT CI failures - it's a known flake) |
Signed-off-by: Darwin Boersma <[email protected]>
…ons easier Signed-off-by: Darwin Boersma <[email protected]>
Signed-off-by: Darwin Boersma <[email protected]>
891cdc7
to
917f811
Compare
Signed-off-by: Darwin Boersma <[email protected]>
Signed-off-by: Darwin Boersma <[email protected]>
Hi folks! I am creating this draft PR to solicit feedback on an initial AWS key value store implementation. I appreciate any and all discussions on this PR!
Some points for thought: