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

Push Notifications

The Amazon Connect Customer Profiles APIs let your application send profile information for the current user and manage that person's registered push devices. Devices are stored separately from the Customer Profile, in a DynamoDB device store, associated by principalId, rather than embedded inside the profile. Requests are signed with Signature Version 4 using Amazon Cognito identity pool credentials, and your backend derives the profile identity from the signed request.

These APIs are provided by AmplifyConnectClient, a standalone client in the aws-connect library. It exposes three methods: identifyUser, registerDevice, and removeDevice.

This page assumes you have already deployed a notifications resource. See Set up notifications.

Install the library

Add the dependency to your module's build.gradle.kts:

dependencies {
implementation("com.amplifyframework:aws-connect:LATEST_VERSION")
}

The client is annotated as an experimental Amplify API, so opt in at the use site:

@OptIn(ExperimentalAmplifyApi::class)

Create the client

The endpoint and Region that your backend deployed are read from the notifications.amazon_connect section of amplify_outputs.json. Create the client with a Cognito-backed credentials provider:

import com.amplifyframework.auth.CognitoCredentialsProvider
import com.amplifyframework.connect.AmplifyConnectClient
import com.amplifyframework.connect.ChannelType
import com.amplifyframework.connect.ConnectClientConfiguration
import com.amplifyframework.core.configuration.AmplifyOutputs
import com.amplifyframework.core.configuration.AmplifyOutputsData
import com.amplifyframework.foundation.credentials.toAwsCredentialsProvider
val configuration = ConnectClientConfiguration.fromAmplifyOutputs(
AmplifyOutputsData.deserialize(context, AmplifyOutputs(R.raw.amplify_outputs))
)
val client = AmplifyConnectClient(
context = applicationContext,
configuration = configuration,
credentialsProvider = CognitoCredentialsProvider().toAwsCredentialsProvider(),
platform = "Android",
appVersion = "1.0.0",
channelType = ChannelType.GCM
)

platform and appVersion are optional strings stored on the device registration. channelType selects the push channel for this device and defaults to ChannelType.GCM; APNS and APNS_SANDBOX are also available.

You can also construct the configuration manually:

val configuration = ConnectClientConfiguration(
endpoint = "https://<api-id>.execute-api.<region>.amazonaws.com",
region = "us-east-1"
)

The endpoint must be an https:// URL.

Call removeDevice before signing a user out. De-registration is signed with the current user's credentials, so it cannot succeed after sign-out has completed. See Remove a device.