-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawslaunchconsole.py
executable file
·44 lines (33 loc) · 1.13 KB
/
awslaunchconsole.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import boto3
import boto3.session
import botocore
import json
import requests
import sys
import webbrowser
from botocore.exceptions import ClientError
from urllib.parse import urlencode
# You should change this
issuer_url = 'https://nokaut.pl'
console_url = 'https://console.aws.amazon.com/'
sign_in_url = 'https://signin.aws.amazon.com/federation'
session = boto3.session.Session()
try:
creds = session.get_credentials()
except botocore.exceptions.CredentialRetrievalError as e:
print("\n You have to get valid AWS Session token. ")
print(" You can get it from: `get_aws_credentials.sh`, `Vault`, `aws-vault`, or via `awscli` \n")
sys.exit(1)
creds = creds.get_frozen_credentials()
awsdata = {'sessionId': creds.access_key,
'sessionKey': creds.secret_key,
'sessionToken': creds.token}
params = {'Action': 'getSigninToken','Session': json.dumps(awsdata)}
response = requests.get(url=sign_in_url, params=params)
ds = json.loads(response.text)
ds['Action'] = 'login'
ds['Issuer'] = issuer_url
ds['Destination'] = console_url
uri = sign_in_url + '?' + urlencode(ds)
webbrowser.open(uri)