Name:
interface
Value:
Extend your Amplify Gen 2 app with AWS Blocks — self-contained backend capabilities you compose into your existing backend.

Identify a user

Use identifyUser to send profile information for the current user to Amazon Connect Customer Profiles. The values you send populate the Customer Profile that your Amazon Connect journeys target and personalize messages with.

import com.amplifyframework.connect.UserProfile
import com.amplifyframework.connect.UserProfileLocation
val result = client.identifyUser(
UserProfile(
email = "jane@example.com",
name = "Jane Doe",
phone = "+15551234567",
location = UserProfileLocation(
city = "Seattle",
country = "US",
postalCode = "98101",
region = "WA"
),
customAttributes = mapOf(
"plan" to "premium",
"favoriteCategory" to "outdoors"
)
)
)

Every field is optional, so send only the values your application has. Each call replaces the fields you provide on the profile.

User profile fields

FieldTypeDescription
emailstringThe user's email address.
namestringThe user's name.
phonestringThe user's phone number.
locationobjectThe user's location. Accepts city, country, postalCode, and region, each a string.
customAttributesmapAdditional string key-value pairs to store on the profile.

Values are validated before the request is sent. customAttributes values must be strings, and every string, along with each customAttributes key, must be 255 characters or fewer. A profile that violates these bounds produces a validation error.

principalId is a reserved customAttributes key and is rejected. Your backend uses it to store the profile identity.

How the profile identity is resolved

Your application does not send a user identifier. Requests are signed with Signature Version 4 using Amazon Cognito identity pool credentials, and your backend derives the principalId for the profile from the signer identity of the request. A caller therefore cannot write to another user's profile, and there is no identifier for your application to manage.

Because the identity comes from the credentials, identifyUser works for both signed-in and guest users. See Guest and authenticated users.

When to call identifyUser

Call identifyUser when the profile information you hold changes, for example:

  • After a user signs in, to associate their profile details with their authenticated identity.
  • After a user updates their contact details or preferences.

identifyUser sends profile information only and performs no device work. To manage push devices, use registerDevice and removeDevice.

Personalize messages with profile values

Message templates reference profile values with the Attributes namespace, so a customAttributes entry named favoriteCategory is available to a template as {{Attributes.favoriteCategory}}. See Author message templates.

Handle errors

identifyUser returns a Result with an AmplifyConnectException failure type, so no call throws. Inspect the result to handle failures:

import com.amplifyframework.connect.ConnectValidationException
import com.amplifyframework.foundation.result.Result
when (val result = client.identifyUser(UserProfile(email = "jane@example.com"))) {
is Result.Success -> { /* profile sent */ }
is Result.Failure -> when (result.error) {
is ConnectValidationException -> { /* a value exceeded the bounds */ }
else -> { /* network, credentials, or service error */ }
}
}