Search code examples
amazon-web-servicespowershellamazon-cognitoaws-cliaws-powershell

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=\"[email protected]\"'

I get the expected result.

When I use the equivalent cmdlet from the module

Get-CGIPUserList -UserPoolId $user_pool_id -Region $region -Filter 'email=\"[email protected]\"'

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?


Solution

  • The powershell module is failing to parse your filter string 'email=\"[email protected]\"' 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="[email protected]"'
    

    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=`"[email protected]`""