[PYTHON] Easily log in to AWS with multiple accounts

Easily log in to AWS with multiple accounts

Switching is troublesome when using multiple accounts on AWS. In Chrome, it seems that you can deal with it by switching to secret mode or switching the Chrome account itself, but that is also troublesome.

That's why I decided to have the browser launched using Selenium and webdriver, and then log in.

First, save the following source with login.py. Please rewrite your email and password to your own.

#! /usr/bin/env python
#-*- coding: utf-8 -*-

from selenium import webdriver

email = 'EMAIL'
password = 'PASSWORD'

d = webdriver.Chrome("./chromedriver")
d.get('https://www.amazon.com/ap/signin?openid.assoc_handle=aws&openid.return_to=https%3A%2F%2Fsignin.aws.amazon.com%2Foauth%3Fresponse_type%3Dcode%26client_id%3Darn%253Aaws%253Aiam%253A%253A015428540659%253Auser%252Fhomepage%26redirect_uri%3Dhttps%253A%252F%252Fconsole.aws.amazon.com%252Fconsole%252Fhome%253Fstate%253DhashArgs%252523%2526isauthcode%253Dtrue%26noAuthCookie%3Dtrue&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&action=&disableCorpSignUp=&clientContext=&marketPlaceId=&poolName=&authCookies=&pageId=aws.ssop&siteState=pre-register%2Cja&accountStatusPolicy=P1&sso=&openid.pape.preferred_auth_policies=MultifactorPhysical&openid.pape.max_auth_age=120&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&server=%2Fap%2Fsignin%3Fie%3DUTF8&accountPoolAlias=&forceMobileApp=0&language=ja&forceMobileLayout=0')

inputEmail = d.find_element_by_id('ap_email')
inputEmail.send_keys(email)
inputPassword = d.find_element_by_id('ap_password')
inputPassword.send_keys(password)
signInBtn = d.find_element_by_id('signInSubmit-input')
signInBtn.click()

d.maximize_window()

So, if it is mac, create a batch like login.command in the same hierarchy.

cd `dirname $0`
./login.py
exit

After that, call spotlight with ⌘ + Space and call login.command to open the browser and log in. It's just like preparing the above files for each account.

It's pretty rough, but please tell me if there is another good way.

Recommended Posts

Easily log in to AWS with multiple accounts
Log in to the remote server with SSH
Log in to Yahoo Business with Selenium Python
Getting started with AWS IoT easily in Python
Create Amazon Linux with AWS EC2 and log in
How to embed multiple embeds in one message with Discord.py
[AWS] How to deal with "Invalid codepoint" error in CloudSearch
I can't log in to the admin page with Django3
I wanted to delete multiple objects in s3 with boto3
How to log in to AtCoder with Python and submit automatically
Connect to multiple databases with SQLAlchemy
Easily post to twitter with Python 3
How to log in to Docker + NGINX
Log in to Raspberry PI with ssh without password (key authentication)
Two ways to display multiple graphs in one image with matplotlib
I tried to log in to twitter automatically with selenium (RPA, scraping)
How to title multiple figures with matplotlib
Send email to multiple recipients in Python (Python 3)
Output Python log to console with GAE
How to work with BigQuery in Python
Log in to Slack using requests in Python
I want to play with aws with python
Process multiple lists with for in Python
If you want to get multiple statistics with groupby in pandas v1
Connect to s3 with AWS Lambda Python
Overwrite data in RDS with AWS Glue
To work with timestamp stations in Python
Upload what you got in request to S3 with AWS Lambda Python
Script to use multiple github accounts properly in the same repository on the same machine
How to deal with memory leaks in matplotlib.pyplot
[REAPER] How to play with Reascript in Python
How to delete log with Docker, not to collect log
Save multiple models in one form with Django
Convert PDFs to images in bulk with Python
I tried to integrate with Keras in TFv1.1
I want to display multiple images with matplotlib.
Easily convert Jupyter Notebooks to blogs with fastpages
How to deal with run-time errors in subprocess.call
How to use tkinter with python in pyenv
AWS Step Functions to learn with a sample
Easily connect Xillybus to user logic with cReComp
[Python] Dealing with multiple call errors in ray.init
Configure a module with multiple files in Django
Use pygogo to get the log in json.
[Python] Mention to multiple people with Slack API
How to return multiple indexes with index method
Describe the multi-stage ssh destination in the config, log in easily, and copy the file with scp
How to convert / restore a string with [] in python
I want to easily implement a timeout in python
Easily build HPC on AWS with genuine AWS Cfn Cluster
How to get multiple model objects randomly in Django
How to write string concatenation in multiple lines in Python
I want to transition with a button in flask
How to do hash calculation with salt in Python
Assign to any column in each row with np.array
Put AWS data in Google Spreadsheet with boto + gspread
How to deal with pyenv initialization failure in fish 3.1.0
How to do zero-padding in one line with OpenCV
How to run tests in bulk with Python unittest
How to load files in Google Drive with Google Colaboratory
Convert the image in .zip to PDF with Python