Skip to content

Can I run the async code inside non-async application? #713

Answered by Velfi
CaliViking asked this question in Q&A
Discussion options

You must be logged in to vote

The SDK is async and that won't change in the foreseeable future. However, running async code is as simple as creating a tokio runtime:

use aws_sdk_dynamodb::{Client, Error};
use tokio::runtime::Runtime;

fn make_a_request_with_the_sdk() -> Result<(), Error>> {
    // Create the runtime
    let rt  = Runtime::new()?;

    // Spawn the root task
    rt.block_on(async {
        let config = aws_config::load_from_env().await;
        let client = Client::new(&config);

        let resp = client.list_tables().send().await?;

        println!("Tables:");

        let names = resp.table_names().unwrap_or_default();

        for name in names {
            println!("  {}", name);
        }

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@nielsthinkiq
Comment options

@CaliViking
Comment options

Answer selected by Velfi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants