I want to connect to my ec2 instance using aws ssm sdk for rust. What is the best way to create an interactive terminal session? Here is the following code I am using to create an ssm session:
pub async fn create_ssh_session(&self, instance_id: &str) -> Result<()> {
let output = self
.client
.start_session()
.document_name("SSM-SessionManagerRunShell")
.target(instance_id)
.send()
.await?;
let wss_url = output.stream_url().unwrap();
let (mut ws_stream, response) = tokio_tungstenite::connect_async(Url::parse(wss_url)?).await?;
// Print response to confirm successful connection
println!("Connected: {}", response.status());
let output = self
.client
.terminate_session()
.session_id(output.session_id().unwrap())
.send()
.await?;
// println!("{:#?}", output);
Ok(())
}
I have tried to connect using tokio tungstenite to connect to the WSS url but I am not sure if this is the best way.