aws-tools-for-powershell: AWS PowerShell NetCore module does not respect $env:AWS_PROFILE

Expected Behavior

Cmdlets in the AWSPowerShell.NetCore module should use the profile specified in $env:AWS_PROFILE.

Current Behavior

Cmdlets in the AWSPowerShell.NetCore module do not respect the $env:AWS_PROFILE variable.

Possible Solution

When the variable is specified, its value should be used as the value of “ProfileName”

Steps to Reproduce (for bugs)

  1. Create a named profile in ~/.aws/credentials
  2. Run a Cmdlet which allows specifying a profile via the -ProfileName parameter, but do not specify a value for that parameter.

Context

  • Writing documentation which targets both PowerShell and bash environments is more cumbersome because credentials are specified differently.
  • Explaining the use of the module to peers can be problematic because some environment variables are supported by the Cmdlets and some are not.
  • Tooling which indicates what profile is currently in use is significantly harder to write; the value needs to be maintained and managed as separate state rather than assuming that this variable is authoritative.
  • To my knowledge, it is not possible to check the currently active profile after running Set-AWSCredential

Your Environment

  • AWSPowerShell.NetCore version used: 3.3.365.0
  • Service assembly and version used: n/a
  • Operating System and version: Windows 10 1703
  • Visual Studio version: n/a
  • Targeted .NET platform: n/a

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 10
  • Comments: 17 (8 by maintainers)

Most upvoted comments

This issue appears to be Windows-specific. On MacOS the AWS_PROFILE environment variable does affect the behavior of the AWS PS commands as expected, while on Windows it does not.

Also, with the AWS IAM Identity Center supporting SSO, along with the CLI aws sso login command, the credentials file and credential profiles become non-applicable, so the Set-AWSCredential -ProfileName $env:AWS_PROFILE is no longer a work-around.

5 years is a good run for a bug to go unfixed. Let’s make AWS PS usable with sso.

We are currently looking to include this in our next major version update.

I just tested with version 4.1.8.0 and the behavior does not appear to have changed. I’ve set $env:AWS_PROFILE to a valid profile name, as tested by passing the profile flag in a previous command, but I still receive an error:

~> Get-STSCallerIdentity -region us-east-1
Get-STSCallerIdentity: No credentials specified or obtained from persisted/shell defaults.

Edit: Running the equivalent command via the AWS CLI, immediately afterward, functioned as expected.

@bgshacklett Thanks for your reply. AWS PowerShell tools use .NET Core SDK and it should work as per code https://github.com/aws/aws-sdk-net/blob/a7c91a25e5b78376d1bf91c13f55383518b4a57b/sdk/src/Core/Amazon.Runtime/Credentials/FallbackCredentialsFactory.cs#L56

However, I was able to verify the environment variable AWS_PROFILE somehow does not work with latest version of Powershell tools 4.1.8.0. This needs some investigation.