liveBook · Manning

AWS SDK for Rust

As explained in Write Powerful Rust Macros

AWS SDK for Rust is a Rust library providing programmatic clients for interacting with AWS services.

AWS SDK for Rust lets Rust code communicate with AWS services instead of calling cloud REST endpoints directly. It is used here to turn infrastructure declarations into real AWS resources: Amazon S3 buckets for object storage and AWS Lambda functions for managed compute. section 9.1

Resource creation is asynchronous. A coordinator creates S3 and Lambda clients, creates a requested Lambda, creates a requested bucket, and can then link the bucket to the Lambda through an event. Keeping AWS communication separate from input parsing and error translation gives each part a focused responsibility. section 9.5

Coordinate S3 and Lambda creation

An async create_infra function awaits S3Client::new and LambdaClient::new, conditionally calls create_lambda and create_bucket, and propagates failures with ?. A procedural macro can run that future with a Tokio runtime and convert an AWS-related failure into a compile error. section 9.5 section 9.5

Creating cloud resources from macro expansion has practical hazards. Re-running creation fails when names already exist, and recently created resources may briefly appear absent when they are linked. Production code should check existing resources or retain state, and retry transient linking failures. section 9.5

Listing 9.17 async create_infra function coordinating the infrastructure setup
async fn create_infra(iac_input: IacInput) -> Result<(), IacError> {
    let s3_client = S3Client::new() #1
        .await;                  
    let lambda_client = LambdaClient::new()
        .await;                  
    let mut output = None;

    if let Some(lambda) = &iac_input.lambda {
        eprintln!("creating lambda...");
        output = Some(lambda_client.create_lambda(lambda).await?); #2
    }                            

    if let Some(bucket) = &iac_input.bucket {
        eprintln!("creating bucket...");
        s3_client.create_bucket(bucket).await?;      #3

        if bucket.has_event {
            eprintln!("linking bucket and lambda by an event...");
            let lambda_arn_output = output
                .expect("when we have an event, we should have a lambda");
            let lambda = iac_input.lambda
                .expect("when we have an event, we should have a lambda");

            let lambda_arn = lambda_arn_output.function_arn()
                .expect("creating a lambda should return its ARN");
            lambda_client.add_bucket_permission(
                &lambda, &bucket.name
            ).await?;                       #4
            s3_client.link_bucket_with_lambda(
                bucket, lambda_arn
            ).await?;                      
        }
    }
    Ok(())
}

This coordinator shows the ordering and conditional async calls used to create a Lambda, create a bucket, and connect event-driven resources. section 9.5

How Write Powerful Rust Macros covers it

How deep it goes
Works through async client setup, conditional service calls, error translation, and production caveats; defers robust retry and state management.
Examples
Uses an infrastructure DSL that creates a bucket and Lambda, optionally linking them through an event.
What it assumes
Assumes Rust procedural-macro parsing while separating that existing work from AWS communication.
What you can do after
Apply it via AWS SDK clients to asynchronously create requested S3 and Lambda resources from Rust.
How it connects
Connects infrastructure as code with Amazon S3, AWS Lambda, procedural macros, Tokio, and REST endpoints.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Write Powerful Rust Macros. The section links point to the parts of the book it draws on.