AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to get the console output for the specified instance. For Linux instances, the instance console output displays the exact console output that would normally be displayed on a physical monitor attached to a computer. For Windows instances, the instance console output includes the last three system event log errors.

# Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import boto3 import sys def get_console_output(instance_id): """ Using EC2 GetConsoleOutput API according """ ec2 = boto3.resource('ec2') ec2_instance = ec2.Instance(instance_id) json_output = ec2_instance.console_output() return json_output.get('Output', '') def main(): if len(sys.argv) == 1: print("Usage: {0} <instance-id>".format(sys.argv[0])) sys.exit(1) instance_id = sys.argv[1] output = get_console_output(instance_id) print(output) return 0 if __name__ == '__main__': sys.exit(main())

Sample Details

Service: ec2

Last tested: 2018-12-26

Author: jschwarzwalder (AWS)

Type: full-example

On this page: