Export Users from Cognito in AWS

Export Cognito Users in AWS

As of today, there is no way to directly export users from Cognito in AWS.

But we can use AWS CLI or AWS SDK to get the list of users.

  • First step is to install AWS CLI on your machine

Click here to download and install AWS CLI

  • Next, step is to configure AWS on your machine. To do this, open cmd (command prompt) and do the following –
$ aws configure
AWS Access Key ID [None]: YourAccessKeyId
AWS Secret Access Key [None]: YourSecretAccessKey
Default region name [None]: YourRegion
Default output format [None]: json

Replace the above with your values. For more info, click here.

  • To get the list of all users in Cognito, run the following command
aws cognito-idp list-users --region <region> --user-pool-id <userPoolId> 
--output json > users.json

The above will return the list of users in a json format. If you want to get the result in a table format, run the following command

aws cognito-idp list-users --region <region> --user-pool-id <userPoolId>  --output table > users.txt
  • Now if you want to convert the result json to csv. Use the following code snippet.
private static void ConvertJsonToCsv()
{
 using (var csv = new ChoCSVWriter("users.csv").WithFirstLineHeader())
 {
   using (var json = new ChoJSONReader("CognitoUsers.json")
             .WithField("Username")
             .WithField("Email", jsonPath: "$.Attributes[?(@.Name == 
              'email')].Value", isArray: true)
             .WithField("UserStatus")
         )
  {
     csv.Write(json);
  }
 }
}
Advertisement

How to replace space with underscore in an xml file using Notepad++

It is very easy to achieve this using a regex expression. Suppose we have below in an xml file and we want to replace the space inside DisplayName node with underscore.

Sample xml –

<User id="11068577">
	<UserId>11068577</UserId>
	<DisplayName>Dolcese Vita</DisplayName>
	<Address>Texas, US</Address>
</User>
  1. Open Notepad++
  2. Click Ctrl+H to open replace dialog box
  3. Add below in Find What:
(?i)(<DisplayName>.*?)[\s](?=.*</DisplayName>)

4. Add below in Replace with:

\1_\2

5. Result –

<User id="11068577">
	<UserId>11068577</UserId>
	<DisplayName>Dolcese_Vita</DisplayName>
	<Address>Texas, US</Address>
</User>


Interested in Cryptocurrency. Register and start investing here

Earn a side income by affiliate marketing. Learn here how to do it.

How to Add a Container in Google Tag Manager

Add a Container in Google Tag Manager

  1. Open Google Tag Manager and login. You will see the the Accounts screen with a list of all existing GTM containers.

2. To create/add a new container, click the three dots on the right – next to the settings icon as below

3. Click on Create Container and you will see the below screen

Note: In order to Create a Container, you need to have permission for it. Please ask the account admin, if you don’t have it

4. Add the container name, e.g. techiespice.com and select the Target Platform, e.g. Web. Click Create and your container is ready.

5. Once you click Create, you will see the below screen with all the container settings (Tags, Variables, Triggers, etc.) along with the GoogleTagManagerID (marked in red) on the right.

6. Click the GoogleTagManagerID and you will see the popup with GTM script that you need to add to your site.

Interested in Cryptocurrency. Register and start investing here

Earn a side income by affiliate marketing. Learn here how to do it.

Rebuild examine index programmatically

Rebuild examine index

You can rebuild the examine index programmatically by using the following code –

ExamineManager.Instance.IndexProviderCollection["InternalIndexer"].RebuildIndex();
               

Interested in Cryptocurrency. Register and start investing here

Earn a side income by affiliate marketing. Learn here how to do it.

Combine one or more generic lists in C#

Combine one or more lists in C#

One or more generic lists can be combined or merged using zip() method in C#.

Below is an example of combining 4 lists by creating an extension method.

public static IEnumerable<TResult> ZipFour<T1, T2, T3, T4, TResult>(
            this IEnumerable<T1> source,
            IEnumerable<T2> second,
            IEnumerable<T3> third,
            IEnumerable<T4> fourth,
            Func<T1, T2, T3, T4, TResult> func)
        {
            using (var e1 = source.GetEnumerator())
            using (var e2 = second.GetEnumerator())
            using (var e3 = third.GetEnumerator())
            using (var e4 = fourth.GetEnumerator())
            {
                while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext())
                    yield return func(e1.Current, e2.Current, e3.Current, e4.Current);
            }
        }

Usage

list1.ZipFour(list2, list3, list4, (a, b, c, d) => new { A = a, B = b, C = c, D = d });

Interested in Cryptocurrency. Register and start investing here

Earn a side income by affiliate marketing. Learn here how to do it.

%d bloggers like this: