liveBook · Manning

Amazon S3

As explained in Write Powerful Rust Macros

Amazon S3 is an object storage service whose data is organized into named storage containers called buckets.

Amazon S3 is AWS’s storage service. In an infrastructure-as-code workflow, it appears as a bucket resource: describe the bucket in Rust input, then let generated code create it through AWS rather than configuring it manually. section 9.1 section 9.5

A practical implementation separates parsing from cloud operations. The entry point parses the infrastructure input, checks whether any resources exist, starts asynchronous work only when needed, and coordinates bucket creation alongside optional Lambda creation. section 9.5

A bucket-creation path has these responsibilities:

  • Keep S3-specific creation code in an s3 module, separate from input parsing and Lambda handling. section 9.5
  • Initialize an AWS S3 SDK client asynchronously before issuing bucket operations. section 9.5
  • Create the declared bucket and, when configured, continue by linking its event to a Lambda. section 9.5
  • Translate AWS SDK failures into useful compile-time errors while leaving parsing errors as syn errors. section 9.5

Coordinate a bucket with other resources

An async create_infra routine constructs S3 and Lambda clients, creates a Lambda when present, then creates the bucket. If the bucket declares an event, the resulting Lambda output is used to connect the two resources. This ordering makes the dependency explicit while keeping each service behind its own client. 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(())
}

The listing shows the orchestration point where an S3 client creates a bucket after optional Lambda creation, with later event linkage guarded by bucket configuration. section 9.5

How Write Powerful Rust Macros covers it

How deep it goes
Explains bucket creation procedurally through modules, async SDK clients, orchestration, and error translation; it does not detail S3 storage behavior.
Examples
Demonstrates an s3 module, AWS SDK dependencies, resource detection, and an async routine that creates a bucket and optionally links Lambda events.
What it assumes
Assumes Rust parsing, procedural macros, modules, and asynchronous execution while introducing S3-specific resource creation.
What you can do after
Operate/configure it by declaring a bucket resource and invoking asynchronous AWS SDK creation from a Rust infrastructure workflow.
How it connects
Connects S3 with Infrastructure as Code, AWS SDK clients, Tokio, AWS Lambda, CloudFormation, and serverless applications.

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.