AWS Assume role [Powershell]

This is a handy 2 lines Powershell script to assume a role in AWS, create temporary credentials and run another command using the assumed roles:

$Response = (Use-STSRole -Region eu-west-1 -RoleArn arn:aws:iam::<accountID>:role/<RoleName> -RoleSessionName RoleSession1).Credentials

$Credentials = New-AWSCredentials -AccessKey $Response.AccessKeyId -SecretKey $Response.SecretAccessKey -SessionToken $Response.SessionToken

Get-S3Bucket -BucketName yourbucketnamehere -Credential $Credentials

Leave a Comment