Page updated Nov 11, 2023

Configure user allow list

Each Amplify authenticated user can be configured to have their own unique logging configuration. This is helpful in enabling you debug issues more granularly for your users.

Retrieve userIDs with Amplify Auth.

You can use the Amplify Auth category to retrieve the userId for a specific user if needed. You can also retrieve the userId by visiting the Amazon Cognito console and inspecting the User ID in User pools.

1Amplify.Auth.getCurrentUser().userId

Configure user allow list

Below is an example of setting different default and category log level for an authenticated user.

Add a userLogLevel section and for each user identifier add a defaultLogLevel and categoryLogLevel.

1{
2 "awsCloudWatchLoggingPlugin": {
3 "enable": true,
4 "logGroupName": "<log-group-name>",
5 "region": "<region>",
6 "localStoreMaxSizeInMB": 1,
7 "flushIntervalInSeconds": 60,
8 "loggingConstraints": {
9 "defaultLogLevel": "ERROR",
10 "userLogLevel": {
11 "xyz-123": {
12 "defaultLogLevel": "DEBUG",
13 "categoryLogLevel": {
14 "Storage": "VERBOSE",
15 "Api": "VERBOSE"
16 }
17 }
18 }
19 }
20 }
21}

Provide a dictionary of UserLogLevel at initialization and configuration of the AWSCloudWatchLoggingPlugin.

1do {
2 let categoryLogLevels: [String: LogLevel] = ["Storage": .verbose, "API": .verbose]
3 let userLogLevel = UserLogLevel(defaultLogLevel: .debug, categoryLogLevel: categoryLogLevels)
4 let userLogLevels: [String: UserLogLevel] = ["xyz-123": userLogLevel]
5 let loggingConstraints = LoggingConstraints(defaultLogLevel: .warn, userLogLevel: userLogLevels)
6 let loggingConfiguration = AWSCloudWatchLoggingPluginConfiguration(logGroupName: "<log-group-name>", region: "<region>", loggingConstraints: loggingConstraints)
7 let loggingPlugin = AWSCloudWatchLoggingPlugin(loggingPluginConfiguration: loggingConfiguration)
8 try Amplify.add(plugin: loggingPlugin)
9} catch {
10 assert(false, "Error initializing Amplify: \(error)")
11}