Generates STS token for cross account with MFA and update the local AWS credential.
Download this module from PowerShell Gallery via below Url https://www.powershellgallery.com/packages/AWSMFAProfile
Set-AWSCredential -AccessKey <YOURACCESSKEY> -SecretKey <YOURSECRETKEY>
Set-AWSMFAProfile -DeviceARN "arn:aws:iam::123456789123:mfa/[email protected]" -SessionName "john" -StoreAs "NorthWindTraders" -RoleARN "arn:aws:iam::9876543219876:role/CrossAccountRole" -MFAToken 123456
Get-EC2Instance -ProfileName "NorthWindTraders" -Region "ap-southeast-2"
- The defualt credential is defined.
- Cross account access to "NorthWindTraders (9876543219876)" with "CrossAccountRole" assumed role and stored under "NorthWindTraders" profile name.
- Retrieve EC2 instances from "NorthWindTraders" account.
Set-AWSCredential -AccessKey <YOURACCESSKEY> -SecretKey <YOURSECRETKEY> -StoreAs "Contoso"
Set-AWSMFAProfile -DeviceARN "arn:aws:iam::123456789123:mfa/[email protected]" -SessionName "john" -StoreAs "NorthWindTraders" -RoleARN "arn:aws:iam::9876543219876:role/CrossAccountRole" -ParentProfile "Contoso" -Duration 25200 -MFAToken 123456
Get-EC2Instance -ProfileName "NorthWindTraders" -Region "ap-southeast-2"
- Set "Contoso" profile name as parent/master account which used to login to AWS.
- Cross account access to "NorthWindTraders (9876543219876)" with "CrossAccountRole" assumed role and stored under "NorthWindTraders" profile name by using "Contoso" as parent/master profile where the session is expired after 7 hours.
- Retrieve EC2 instances from "NorthWindTraders" account.