Table of Contents

aws-vault

Examples

 def aws_vault_exec(profile, command):
     result = subprocess.run(['aws-vault', 'exec', profile, '--'] + command, capture_output=True, text=True)
     print(result.stdout)
     if result.stderr:
         print(f"Error: {result.stderr}")
 # Example usage: list S3 buckets with a specific profile
 aws_vault_exec('my-profile', ['aws', 's3', 'ls'])
 ```

 public class AwsVaultExample {
     public static void awsVaultExec(String profile, String[] command) {
         String[] execCommand = new String[command.length + 3];
         execCommand[0] = "aws-vault";
         execCommand[1] = "exec";
         execCommand[2] = profile;
         execCommand[3] = "--";
         System.arraycopy(command, 0, execCommand, 4, command.length);
         try {
             Process process = new ProcessBuilder(execCommand).start();
             BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
             String line;
             while ((line = reader.readLine()) != null) {
                 System.out.println(line);
             }
             reader.close();
             int exitCode = process.waitFor();
             if (exitCode != 0) {
                 BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                 while ((line = errorReader.readLine()) != null) {
                     System.err.println("Error: " + line);
                 }
                 errorReader.close();
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
     public static void main(String[] args) {
         // Example usage: list S3 buckets with a specific profile
         awsVaultExec("my-profile", new String[]{"aws", "s3", "ls"});
     }
 }
 ```

Summary