Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/gamelift/getlog.py
1567 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import sys
14
from functools import partial
15
16
from awscli.compat import urlopen
17
from awscli.customizations.commands import BasicCommand
18
from awscli.utils import create_nested_client
19
20
21
class GetGameSessionLogCommand(BasicCommand):
22
NAME = 'get-game-session-log'
23
DESCRIPTION = 'Download a compressed log file for a game session.'
24
ARG_TABLE = [
25
{'name': 'game-session-id', 'required': True,
26
'help_text': 'The game session ID'},
27
{'name': 'save-as', 'required': True,
28
'help_text': 'The filename to which the file should be saved (.zip)'}
29
]
30
31
def _run_main(self, args, parsed_globals):
32
client = create_nested_client(
33
self._session, 'gamelift', region_name=parsed_globals.region,
34
endpoint_url=parsed_globals.endpoint_url,
35
verify=parsed_globals.verify_ssl
36
)
37
38
# Retrieve a signed url.
39
response = client.get_game_session_log_url(
40
GameSessionId=args.game_session_id)
41
url = response['PreSignedUrl']
42
43
# Retrieve the content from the presigned url and save it locally.
44
contents = urlopen(url)
45
46
sys.stdout.write(
47
'Downloading log archive for game session %s...\r' %
48
args.game_session_id
49
)
50
51
with open(args.save_as, 'wb') as f:
52
for chunk in iter(partial(contents.read, 1024), b''):
53
f.write(chunk)
54
55
sys.stdout.write(
56
'Successfully downloaded log archive for game '
57
'session %s to %s\n' % (args.game_session_id, args.save_as))
58
59
return 0
60
61