Path: blob/develop/awscli/customizations/gamelift/getlog.py
1567 views
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12import sys13from functools import partial1415from awscli.compat import urlopen16from awscli.customizations.commands import BasicCommand17from awscli.utils import create_nested_client181920class GetGameSessionLogCommand(BasicCommand):21NAME = 'get-game-session-log'22DESCRIPTION = 'Download a compressed log file for a game session.'23ARG_TABLE = [24{'name': 'game-session-id', 'required': True,25'help_text': 'The game session ID'},26{'name': 'save-as', 'required': True,27'help_text': 'The filename to which the file should be saved (.zip)'}28]2930def _run_main(self, args, parsed_globals):31client = create_nested_client(32self._session, 'gamelift', region_name=parsed_globals.region,33endpoint_url=parsed_globals.endpoint_url,34verify=parsed_globals.verify_ssl35)3637# Retrieve a signed url.38response = client.get_game_session_log_url(39GameSessionId=args.game_session_id)40url = response['PreSignedUrl']4142# Retrieve the content from the presigned url and save it locally.43contents = urlopen(url)4445sys.stdout.write(46'Downloading log archive for game session %s...\r' %47args.game_session_id48)4950with open(args.save_as, 'wb') as f:51for chunk in iter(partial(contents.read, 1024), b''):52f.write(chunk)5354sys.stdout.write(55'Successfully downloaded log archive for game '56'session %s to %s\n' % (args.game_session_id, args.save_as))5758return 0596061