Hacking AWS CloudShell with Rust

· 4min · Pragmatic AI Labs

Hacking AWS CloudShell with Rust: Building an S3 Bucket Lister

Introduction

AWS CloudShell provides a browser-based shell environment with AWS credentials pre-configured. While Rust isn't officially supported, we can hack it to work by using the /tmp directory to circumvent space limitations.

Do you want to learn AWS Advanced AI Engineering?

Production LLM architecture patterns using Rust, AWS, and Bedrock.

Check out our course!

Getting Started with CloudShell

  1. Open CloudShell and switch to ZSH for better AI-powered completions:
zsh
  1. Check available space:
df -h

Note: Your home directory has limited space (~1GB), but /tmp has more room for our hack.

Setting Up Rust in CloudShell

  1. Configure Rust installation paths:
export RUSTUP_HOME=/tmp/.rustup
export CARGO_HOME=/tmp/.cargo
  1. Install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Choose standard installation when prompted.

  1. Add Rust to your path:
source "/tmp/.cargo/env"
  1. Install the C compiler:
sudo yum install -y gcc

Creating the S3 Bucket Lister

  1. Create a new Rust project:
cd /tmp
cargo new s3-lister
cd s3-lister
  1. Add AWS SDK dependencies:
cargo add aws-config aws-sdk-s3 tokio --features tokio/full
  1. Replace src/main.rs content:
use aws_config::{load_defaults, BehaviorVersion};
use aws_sdk_s3::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = load_defaults(BehaviorVersion::latest()).await;
    let client = Client::new(&config);

    let buckets = client.list_buckets().send().await?;

    for bucket in buckets.buckets() {
        if let Some(name) = bucket.name() {
            println!("{}", name);
        }
    }

    Ok(())
}

Building and Running

  1. Debug build (larger but faster compilation):
cargo build
./target/debug/s3-lister
  1. Release build (smaller binary, optimized):
cargo build --release
./target/release/s3-lister

Binary size comparison:

  • Debug: ~151MB
  • Release: ~15MB

Important Notes

  1. This is an ephemeral setup:

    • Everything in /tmp is cleared when CloudShell session ends
    • You'll need to reinstall Rust in new sessions
  2. CloudShell advantages:

    • Pre-configured AWS credentials
    • No local setup required
    • ZSH with Amazon Q completion

Troubleshooting

If cargo command isn't found:

export PATH="/tmp/.cargo/bin:$PATH"

If compilation fails:

sudo yum install -y gcc

Conclusion

While not officially supported, this hack lets you use Rust in CloudShell for quick AWS development. The release build produces an efficient binary that you can use for testing AWS services directly in the browser.

Want expert ML and AI training?

From the fastest growing platform in the world.

Start for Free

Based on this article's content, here are some courses that might interest you:

  1. AWS Advanced AI Engineering (1 week)
    Production LLM architecture patterns using Rust, AWS, and Bedrock.

  2. Rust-Powered AWS Serverless (4 weeks)
    Learn to develop serverless applications on AWS using Rust and AWS Lambda. Master the fundamentals of serverless architecture while building practical applications and understanding performance optimizations.

  3. Enterprise AI Operations with AWS (2 weeks)
    Master enterprise AI operations with AWS services

  4. Natural Language AI with Bedrock (1 week)
    Get started with Natural Language Processing using Amazon Bedrock in this introductory course focused on building basic NLP applications. Learn the fundamentals of text processing pipelines and how to leverage Bedrock's core features while following AWS best practices.

  5. Natural Language Processing with Amazon Bedrock (2 weeks)
    Build production NLP systems with Amazon Bedrock

Learn more at Pragmatic AI Labs