Hacking AWS CloudShell with Rust
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.
Getting Started with CloudShell
- Open CloudShell and switch to ZSH for better AI-powered completions:
zsh
- 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
- Configure Rust installation paths:
export RUSTUP_HOME=/tmp/.rustup
export CARGO_HOME=/tmp/.cargo
- Install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Choose standard installation when prompted.
- Add Rust to your path:
source "/tmp/.cargo/env"
- Install the C compiler:
sudo yum install -y gcc
Creating the S3 Bucket Lister
- Create a new Rust project:
cd /tmp
cargo new s3-lister
cd s3-lister
- Add AWS SDK dependencies:
cargo add aws-config aws-sdk-s3 tokio --features tokio/full
- 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
- Debug build (larger but faster compilation):
cargo build
./target/debug/s3-lister
- Release build (smaller binary, optimized):
cargo build --release
./target/release/s3-lister
Binary size comparison:
- Debug: ~151MB
- Release: ~15MB
Important Notes
-
This is an ephemeral setup:
- Everything in
/tmp
is cleared when CloudShell session ends - You'll need to reinstall Rust in new sessions
- Everything in
-
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/AI training? Visit paiml.com
For hands-on courses: DS500 Platform
Recommended Courses
Based on this article's content, here are some courses that might interest you:
-
AWS Advanced AI Engineering (1 week) Production LLM architecture patterns using Rust, AWS, and Bedrock.
-
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.
-
AWS AI Analytics: Enhancing Analytics Pipelines with AI (3 weeks) Transform analytics pipelines with AWS AI services, focusing on performance and cost optimization
-
AWS AI Analytics: Building High-Performance Systems with Rust (3 weeks) Build high-performance AWS AI analytics systems using Rust, focusing on efficiency, telemetry, and production-grade implementations
-
Generative AI with AWS (4 weeks) This GenAI course will guide you through everything you need to know to use generative AI on AWS
Learn more at Pragmatic AI Labs