简体   繁体   中英

Issue with filter syntax in AWS tools for Powershell Core

I wrote a Powershell script that gets a filtered list of cognito-idp identities using AWS CLI. However, I wanted to make this a lambda script and realized that I could not use AWS CLI and instead needed to use the AWS for Powershell Core module.

When I use the AWS CLI command

aws cognito-idp  list-users --user-pool-id $user_pool_id --filter 'email=\"foo@bar.com\"'

I get the expected result.

When I use the equivalent cmdlet from the module

Get-CGIPUserList -UserPoolId $user_pool_id -Region $region -Filter 'email=\"foo@bar.com\"'

I get a filter parsing error

Get-CGIPUserList : One or more errors occurred. (Error while parsing filter.)
At line:1 char:9
+ Get-CGIPUserList -UserPoolId "****" -Region "u ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Amazon.PowerShe...PUserListCmdlet:GetCGIPUserListCmdlet) [Get-CGIPUserList], InvalidOperationException
+ FullyQualifiedErrorId : System.AggregateException,Amazon.PowerShell.Cmdlets.CGIP.GetCGIPUserListCmdlet

According to the module reference here: https://docs.aws.amazon.com/powershell/latest/reference/items/Get-CGIPUserList.html the syntax for the filter parameter should be the same. What am I doing wrong?

The powershell module is failing to parse your filter string 'email=\\"foo@bar.com\\"' because of the escaped double quotations.

Simply remove them and you should get past this error, as the single quote ' in powershell expresses content as string literal:

'email="foo@bar.com"'

You could also wrap your filter string in double quotes " . You would generally only need to do this if your string contained a powershell variable that you would like to interpolate. You would need to replace the \\ escape character in this case with powershell's escape character ` like so:

"email=`"foo@bar.com`""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM