Menu
Amazon Cognito
Developer Guide (Version Last Updated: 08/26/2017)

Logging Amazon Cognito API Calls with AWS CloudTrail

Amazon Cognito is integrated with AWS CloudTrail, a service that captures specific API calls and delivers log files of the calls to an S3 bucket that you specify. CloudTrail captures API calls made from the Amazon Cognito console or from your code to the Amazon Cognito APIs. With the information collected by CloudTrail, you can determine which request was made to Amazon Cognito, the IP address from which the request was made, who made the request, when it was made, and so on.

To learn more about CloudTrail, including how to configure and enable it, see the AWS CloudTrail User Guide.

You can also create Amazon CloudWatch alarms for specific CloudTrail events. For example, you can set up CloudWatch to trigger an alarm if an identity pool configuration is changed. For more information, see Creating CloudWatch Alarms for CloudTrail Events: Examples.

Amazon Cognito Information in CloudTrail

When CloudTrail logging is enabled in your AWS account, API calls made to specific Amazon Cognito actions are tracked in CloudTrail log files, where they are written with other AWS service records. CloudTrail determines when to create and write to a new file based on a time period and file size.

The following actions are supported:

Amazon Cognito Your User Pools

  • AddCustomAttributes

  • CreateUserImportJob

  • CreateUserPool

  • CreateUserPoolClient

  • DeleteUserPool

  • DeleteUserPoolClient

  • DescribeUserImportJob

  • DescribeUserPool

  • DescribeUserPoolClient

  • GetCSVHeader

  • ListUserImportJobs

  • ListUserPoolClients

  • ListUserPools

  • StartUserImportJob

  • StopUserImportJob

  • UpdateUserPool

  • UpdateUserPoolClient

Every log entry contains information about who generated the request. The user identity information in the log helps you determine whether the request was made with root or AWS Identity and Access Management (IAM) user credentials, with temporary security credentials for a role or federated user, or by another AWS service. For more information, see the CloudTrail userIdentity Element.

You can store log files in your S3 bucket for as long as you want, but you can also define Amazon Simple Storage Service (Amazon S3) lifecycle rules to archive or delete log files automatically. By default, your log files are encrypted by using Amazon S3 server-side encryption (SSE).

If you want to take quick action upon log file delivery, you can have CloudTrail publish Amazon Simple Notification Service (Amazon SNS) notifications when new log files are delivered. For more information, see Configuring Amazon SNS Notifications.

You can also aggregate Amazon Cognito log files from multiple AWS regions and multiple AWS accounts into a single S3 bucket. For more information, see Receiving CloudTrail Log Files From Multiple Regions.

Understanding Amazon Cognito Log File Entries

CloudTrail log files contain one or more log entries, where each entry lists multiple JSON-formatted events. A log entry represents a single request from any source and includes information about the requested operation, including the date and time of the operation, request parameters, and so on. Log entries are not an ordered stack trace of the public API calls, so they do not appear in any specific order.

The following example is a log entry for a request for the CreateIdentityPool action. The request was made by an IAM user named Alice.

Copy
{ "eventVersion":"1.03", "userIdentity":{ "type":"IAMUser", "principalId":"PRINCIPAL_ID", "arn":"arn:aws:iam::123456789012:user/Alice", "accountId":"123456789012", "accessKeyId":"['EXAMPLE_KEY_ID']", "userName":"Alice" }, "eventTime":"2016-01-07T02:04:30Z", "eventSource":"cognito-identity.amazonaws.com", "eventName":"CreateIdentityPool", "awsRegion":"us-east-1", "sourceIPAddress":"127.0.0.1", "userAgent":"USER_AGENT", "requestParameters":{ "identityPoolName":"TestPool", "allowUnauthenticatedIdentities":true, "supportedLoginProviders":{ "graph.facebook.com":"000000000000000" } }, "responseElements":{ "identityPoolName":"TestPool", "identityPoolId":"us-east-1:1cf667a2-49a6-454b-9e45-23199EXAMPLE", "allowUnauthenticatedIdentities":true, "supportedLoginProviders":{ "graph.facebook.com":"000000000000000" } }, "requestID":"15cc73a1-0780-460c-91e8-e12ef034e116", "eventID":"f1d47f93-c708-495b-bff1-cb935a6064b2", "eventType":"AwsApiCall", "recipientAccountId":"123456789012" }