Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created July 28, 2013 08:30
Show Gist options
  • Save hnakamur/6097947 to your computer and use it in GitHub Desktop.
Save hnakamur/6097947 to your computer and use it in GitHub Desktop.
Open a new tab in Google Chrome and login to the AWS console automatically.
on main()
openAndLoginAwsConsoleWithChrome(system attribute "USERID", system attribute "PASSWD")
end main
on openAndLoginAwsConsoleWithChrome(aUserID, aPassword)
chrome_launchAndActivate()
chrome_openUrlWithNewTab("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=&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&forceMobileLayout=0")
chrome_waitLoading()
chrome_executeJavascript("document.getElementById('ap_email').value = '" & string_escapeSingleQuote(aUserID) & "';")
chrome_executeJavascript("document.getElementById('ap_password').value = '" & string_escapeSingleQuote(aPassword) & "';")
chrome_executeJavascript("document.getElementById('signInSubmit').click();")
end openAndLoginAwsConsoleWithChrome
on chrome_launchAndActivate()
tell application "Google Chrome"
launch
activate
end tell
end chrome_launchAndActivate
on chrome_openUrlWithNewTab(aURL)
tell application "Google Chrome"
tell front window to make new tab with properties {URL:aURL}
end tell
end chrome_openUrlWithNewTab
on chrome_waitLoading()
repeat
tell application "Google Chrome"
set tabLoading to loading of active tab of front window
end tell
if not tabLoading then exit repeat
delay 0.5
end repeat
end chrome_waitLoading
on chrome_executeJavascript(aScript)
tell application "Google Chrome"
tell active tab of front window
execute javascript aScript
end tell
end tell
end chrome_executeJavascript
on string_replace(theText, searchStr, replaceStr)
set tmp to AppleScript's text item delimiters
set AppleScript's text item delimiters to searchStr
set theList to every text item of theText
set AppleScript's text item delimiters to replaceStr
set theText to theList as string
set AppleScript's text item delimiters to tmp
return theText
end string_replace
on string_escapeSingleQuote(theText)
return string_replace(theText, "'", "\\'")
end string_escapeSingleQuote
main()
@hnakamur
Copy link
Author

Usage:

USERID='_YOUR_USER_ID_HERE_' PASSWD='_YOUR_PASSWORD_HERE_' osascript chrome_aws_console.scpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment