AWS Lambda is used here as a compute resource in an infrastructure-as-code workflow. A Lambda function runs supplied code without the caller managing its infrastructure; configuration includes memory and a maximum execution time, and billing is tied to the time the code requires. section 9.1
A Rust infrastructure DSL parses requested resources, then uses the AWS SDK for Rust to create Lambda functions alongside Amazon S3 buckets. Resource creation is asynchronous: clients are initialized, the requested Lambda is created, and an optional bucket event can link the bucket to that Lambda. section 9.5
A practical Lambda provisioning flow separates responsibilities:
- Parse the DSL input into a resource request. section 9.5
- Keep Lambda creation in a dedicated Lambda module and translate AWS SDK failures into useful compiler errors. section 9.5
- Create the Lambda before connecting an event-producing S3 bucket when the bucket declares an event. section 9.5
- Plan for retries and state or existence checks in production, because recently created resources can appear unavailable and repeat creation fails when names already exist. 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 coordinator illustrates the async sequence: construct S3 and Lambda clients, create a requested Lambda, create a requested bucket, then use the Lambda result when wiring a bucket event. section 9.5
Avoiding accidental provisioning during IDE macro expansion
A procedural macro can have side effects: IDE macro expansion may invoke infrastructure creation and claim a resource name. Guard creation by detecting IDE completion, so parsing and expansion can proceed without creating Lambda or S3 resources. section 9.5

