Skip to content

Commit

Permalink
get-console-output
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed Jul 4, 2024
1 parent b82b5e5 commit 85392ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ I was hoping to hack together some sort of reflection technique to auto-generate
aws ec2 delete-key-pair # Deletes a key pair
aws ec2 describe-images TAG # describe images with tag
aws ec2 describe-instances TAG # get instances with tag
aws ec2 describe-instances TAG # get_console_output from and instance
aws ec2 describe-key-pairs # Describes all of your key pairs
aws ec2 describe-subnetss # Describes subnets`s
aws ec2 get-windows-password instance_id pem_path # Gets the windows password for an instance
aws ec2 help [COMMAND] # Describe subcommands or one specific subcommand

aws iam list-access-keys # List access keys for User
aws iam list-users # List users in account
Expand Down
17 changes: 17 additions & 0 deletions lib/awscli_ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Ec2 < SubCommandBase
map ['describe-subnets'] => :describe_subnets
map ['delete-key-pair'] => :delete_key_pair
map ['get-windows-password'] => :get_windows_password
map ['get-console-output'] => :get_console_output

desc 'create-key-pair NAME', 'create a new key-pair'
method_option :endpoint, type: :string, desc: 'Endpoint to connect to'
Expand Down Expand Up @@ -49,6 +50,22 @@ def describe_instances(tag)
puts JSON.pretty_generate(resp.to_h)
end

desc 'describe-instances TAG', 'get_console_output from and instance'
method_option :endpoint, type: :string, desc: 'Endpoint to connect to'
# aws ec2 get-console-output
def get_console_output(instance)
require 'base64'
endpoint = options[:endpoint]
client = Aws::EC2::Client.new(endpoint ? { endpoint: endpoint } : {})
resp = client.get_console_output(
{
instance_id: instance
}
)

puts Base64.decode64(resp.output)
end

desc 'describe-key-pairs', 'Describes all of your key pairs'
method_option :endpoint, type: :string, desc: 'Endpoint to connect to'
# aws ec2 describe-key-pairs
Expand Down

0 comments on commit 85392ac

Please sign in to comment.