Closed jrjespersen closed 4 years ago
Additonally, I think this issue exists in the PowerShell implementation because I can execute the following snippet and get the expected results:
import-module awspowershell.netcore $cred = Get-AWSTemporaryCredential "AWS CORP LAB" #custom function to get temp creds $ec2 = new-object "Amazon.EC2.AmazonEC2Client"($cred,[Amazon.RegionEndPoint]::USEast1) $resp = $ec2.DescribeRegionsAsync((new-object "Amazon.EC2.Model.DescribeRegionsRequest")) $resp.result.regions
Hello, thank you for reporting this. Could you try if
Get-EC2Region -RegionToCall us-east-1
solves your problem?
The Get-EC2Region cmdlets has two parameters (see here):
RegionName
- a static parameter with a RegionNames
alias,Region
- a dynamic parameter with a RegionToCall
alias.All the Common Credential and Region Parameters are dynamic parameters.
Unfortunately PowerShell has an anomalous behavior where the parameter you specify binds with a higher priority to a static parameter prefix than to the full name of a dynamic parameter. So Region
binds to RegionName instead of Region. This makes the Region
parameter unusable unless you use the RegionToCall
alias which works because it is not a prefix of a static parameter name.
We are considering to change the Common Credential and Region Parameters to static parameters in the next release of AWS.Tools. We are hesitant to do the same in AWSPowerShell
and AWSPowerShell.NetCore
for backward compatibility concerns.
Yes, this does provide an adequate solution for scripting. It's an annoyance for interactive use/development since it breaks splatting to this cmdlet using the same collection that I splat to every other cmdlet.
I support the change for AWS.Tools - I came across this issue in converting/updating/testing scripts in preparation for migration from AWSPowerShell/NetCore to AWS.Tools, so I'm less concerned with getting it fixed in AWSPowerShell/NetCore.
Hello, as announced in https://github.com/aws/aws-tools-for-powershell/issues/61, we will change all parameters to static in the upcoming major version (v4). This change is already available in preview in the latest release of AWS.Tools. Thanks for reporting this issue.
Get-EC2Region appears to have no different functionality between the -Region and -RegionName parameters.
Expected Behavior
-Region should declare which region to execute the API call against, but not filter the output (consistent with how the AWS CLI works for this command) -RegionName should filter the output of the API to the list of regions provided.
Current Behavior Both -Region and -RegionName parameters filter the output.
Steps to Reproduce (for bugs)
Import-Module AWSPowerShell.NetCore Set-DefaultAWSRegion us-east-1 Get-EC2Region -Region us-east-1 -ProfileName "AWS CORP LAB" #returns only us-east-1 Get-EC2Region -RegionName us-east-1 -ProfileName "AWS CORP LAB" #returns only us-east-1 aws ec2 describe-regions --region us-east-1 --profile "AWS CORP LAB" #returns all enabled regions
Context
We use Get-EC2Region because we do not enable all regions in all of our accounts, so for scripts which iterate over multiple accounts and regions, we must obtain which regions are active to avoid time-outs when attempting to make an API call to a disabled region.
Your Environment
Include as many relevant details about the environment where the bug was discovered.
$PSVersionTable.OS
: Darwin 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64$PSVersionTable.PSEdition
: Core (6.2.1)