Connect to existing AWS resources
Amplify client libraries can be used independently without the Amplify backend workflow. If you've provisioned AWS resources with CDK, Terraform, CloudFormation, or the AWS Console, you can connect Amplify libraries directly to those resources.
This means you can adopt Amplify's client libraries for authentication, data, storage, and more, while keeping full control over your infrastructure.
When to use this approach
- You already have AWS resources provisioned with CDK, Terraform, or CloudFormation
- You want to use Amplify client libraries without adopting the Amplify backend (
ampx) workflow - You need to connect to shared infrastructure managed by a platform team
- You want programmatic control over configuration for testing or environment switching
How it works
There are two ways to configure Amplify client libraries with your own resources:
Option 1: Manual amplify_outputs.json
Create an amplify_outputs.json file in your app/src/main/res/raw/ directory. See the full specification for all supported fields.
{ "version": "1.5", "auth": { "aws_region": "us-east-1", "user_pool_id": "us-east-1_abc123", "user_pool_client_id": "abcdef123456", "identity_pool_id": "us-east-1:11111111-2222-3333-4444-555555555555" }}Then configure Amplify as usual:
Amplify.addPlugin(AWSCognitoAuthPlugin())Amplify.configure(applicationContext)Option 2: Programmatic configuration with AmplifyOutputsData
Build the configuration in code without any JSON files:
import com.amplifyframework.core.Amplifyimport com.amplifyframework.core.configuration.AmplifyOutputsDataimport com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin
val config = AmplifyOutputsData( auth = Auth( awsRegion = "us-east-1", userPoolId = "us-east-1_abc123", userPoolClientId = "abcdef123456" ))
Amplify.addPlugin(AWSCognitoAuthPlugin())Amplify.configure(config, applicationContext)This approach is ideal for:
- Unit testing: Configure Amplify without bundling JSON files
- Environment switching: Build different configurations for dev/staging/prod
- Dynamic configuration: Fetch configuration from a remote source at runtime
Configure Auth (Amazon Cognito)
Connect to an existing Cognito User Pool and Identity Pool.
val config = AmplifyOutputsData( auth = Auth( awsRegion = "us-east-1", userPoolId = "us-east-1_abc123", userPoolClientId = "abcdef123456", identityPoolId = "us-east-1:11111111-2222-3333-4444-555555555555", passwordPolicy = Auth.PasswordPolicy( minLength = 8, requireNumbers = true, requireLowercase = true, requireUppercase = true, requireSymbols = false ), oauth = Auth.Oauth( identityProviders = listOf( IdentityProviders.GOOGLE, IdentityProviders.SIGN_IN_WITH_APPLE ), domain = "myapp.auth.us-east-1.amazoncognito.com", scopes = listOf("openid", "email", "profile"), redirectSignInUri = listOf("myapp://callback"), redirectSignOutUri = listOf("myapp://signout"), responseType = ResponseType.Code ), standardRequiredAttributes = listOf( AmazonCognitoStandardAttributes.EMAIL ), usernameAttributes = listOf( UsernameAttributes.EMAIL ), userVerificationTypes = listOf( VerificationMechanism.EMAIL ), unauthenticatedIdentitiesEnabled = true, mfaConfiguration = MfaConfiguration.OPTIONAL, mfaMethods = listOf( MfaMethods.SMS, MfaMethods.TOTP ) ))
Amplify.addPlugin(AWSCognitoAuthPlugin())Amplify.configure(config, applicationContext)Auth required fields
| Field | Required | Description |
|---|---|---|
awsRegion | Yes | AWS region (e.g. us-east-1) |
userPoolId | Yes | Cognito User Pool ID |
userPoolClientId | Yes | Cognito app client ID |
Every other field is optional. See the amplify_outputs.json schema for the full shape.
Configure Data (AWS AppSync)
Connect to an existing AppSync GraphQL API.
val config = AmplifyOutputsData( data = Data( awsRegion = "us-east-1", url = "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql", apiKey = "da2-abcdefghijklmno", defaultAuthorizationType = AwsAppsyncAuthorizationType.API_KEY, authorizationTypes = listOf( AwsAppsyncAuthorizationType.API_KEY, AwsAppsyncAuthorizationType.AMAZON_COGNITO_USER_POOLS ) ))
Amplify.addPlugin(AWSApiPlugin())Amplify.configure(config, applicationContext)Data required fields
| Field | Required | Description |
|---|---|---|
awsRegion | Yes | AWS region |
url | Yes | AppSync GraphQL endpoint URL |
defaultAuthorizationType | Yes | Default auth mode: API key, Cognito user pools, IAM, Lambda, or OIDC |
authorizationTypes | Yes | Every auth mode the API accepts, from the same list |
apiKey | With API key auth | AppSync API key |
Every other field is optional. See the amplify_outputs.json schema for the full shape.
Configure Storage (Amazon S3)
Connect to an existing S3 bucket.
val config = AmplifyOutputsData( auth = Auth( awsRegion = "us-east-1", userPoolId = "us-east-1_abc123", userPoolClientId = "abcdef123456", identityPoolId = "us-east-1:11111111-2222-3333-4444-555555555555" ), storage = Storage( awsRegion = "us-east-1", bucketName = "my-app-bucket" ))
Amplify.addPlugin(AWSCognitoAuthPlugin())Amplify.addPlugin(AWSS3StoragePlugin())Amplify.configure(config, applicationContext)Multiple buckets
val config = AmplifyOutputsData( storage = Storage( awsRegion = "us-east-1", bucketName = "primary-bucket", buckets = listOf( Storage.Bucket( name = "media", bucketName = "my-media-bucket", awsRegion = "us-east-1" ), Storage.Bucket( name = "logs", bucketName = "my-logs-bucket", awsRegion = "us-west-2" ) ) ))Storage required fields
| Field | Required | Description |
|---|---|---|
awsRegion | Yes | AWS region |
bucketName | Yes | Default S3 bucket name |
buckets[].name, buckets[].bucketName, buckets[].awsRegion | With additional buckets | All three are required on every entry |
Every other field is optional. See the amplify_outputs.json schema for the full shape.
Configure Analytics (Amazon Pinpoint)
Connect to an existing Pinpoint application.
val config = AmplifyOutputsData( analytics = Analytics( amazonPinpoint = Analytics.AmazonPinpoint( awsRegion = "us-east-1", appId = "abc123def456" ) ))
Amplify.addPlugin(AWSPinpointAnalyticsPlugin())Amplify.configure(config, applicationContext)Analytics required fields
| Field | Required | Description |
|---|---|---|
amazonPinpoint.awsRegion | Yes | AWS region of the Pinpoint project |
amazonPinpoint.appId | Yes | Pinpoint application (project) ID |
Every other field is optional. See the amplify_outputs.json schema for the full shape.
Configure Geo (Amazon Location Service)
Connect to existing Location Service resources.
val config = AmplifyOutputsData( geo = Geo( awsRegion = "us-east-1", maps = Geo.Maps( items = mapOf( "myMap" to AmazonLocationServiceConfig( style = "VectorEsriStreets" ) ), default = "myMap" ), searchIndices = Geo.SearchIndices( items = listOf("myPlaceIndex"), default = "myPlaceIndex" ), geofenceCollections = Geo.GeofenceCollections( items = listOf("myGeofenceCollection"), default = "myGeofenceCollection" ) ))
Amplify.addPlugin(AWSLocationGeoPlugin())Amplify.configure(config, applicationContext)Geo required fields
| Field | Required | Description |
|---|---|---|
awsRegion | Yes | AWS region of the Location Service resources |
maps.items, maps.default | With maps | Maps keyed by name, plus the default map name |
searchIndices.items, searchIndices.default | With searchIndices | Place index names, plus the default index |
geofenceCollections.items, geofenceCollections.default | With geofenceCollections | Collection names, plus the default collection |
Every other field is optional. See the amplify_outputs.json schema for the full shape.
Each resource group is optional on its own, but configure the ones your app actually calls: the Geo APIs need a default for the resource type they use.
Configure Notifications (Push)
Connect to an existing Pinpoint application for push notifications.
val config = AmplifyOutputsData( notifications = Notifications( awsRegion = "us-east-1", amazonPinpointAppId = "abc123def456", channels = listOf( AmazonPinpointChannels.FCM, AmazonPinpointChannels.IN_APP_MESSAGING ) ))
Amplify.addPlugin(AWSPinpointPushNotificationsPlugin())Amplify.configure(config, applicationContext)Notifications required fields
Configure either a Pinpoint project or an Amazon Connect endpoint, or both:
| Field | Required | Description |
|---|---|---|
awsRegion | For Pinpoint | AWS region of the Pinpoint project |
amazonPinpointAppId | For Pinpoint | Pinpoint application ID |
channels | For Pinpoint | Channels to enable: APNS, FCM, in-app messaging, email, or SMS. At least one entry, no duplicates |
amazonConnect.awsRegion, amazonConnect.endpoint | For Amazon Connect | Amazon Connect Customer Profiles endpoint backing push device registration. Both are required on the entry |
A Pinpoint setup needs all three Pinpoint fields: the region, the app ID, and at least one channel.
Every other field is optional. See the amplify_outputs.json schema for the full shape.
Multi-category configuration
You can configure multiple services together. This example sets up Auth, Data, and Storage in a single configuration.
val config = AmplifyOutputsData( auth = Auth( awsRegion = "us-east-1", userPoolId = "us-east-1_abc123", userPoolClientId = "abcdef123456", identityPoolId = "us-east-1:11111111-2222-3333-4444-555555555555" ), data = Data( awsRegion = "us-east-1", url = "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql", defaultAuthorizationType = AwsAppsyncAuthorizationType.AMAZON_COGNITO_USER_POOLS, authorizationTypes = listOf( AwsAppsyncAuthorizationType.AMAZON_COGNITO_USER_POOLS, AwsAppsyncAuthorizationType.AWS_IAM ) ), storage = Storage( awsRegion = "us-east-1", bucketName = "my-app-bucket" ))
Amplify.addPlugin(AWSCognitoAuthPlugin())Amplify.addPlugin(AWSApiPlugin())Amplify.addPlugin(AWSS3StoragePlugin())Amplify.configure(config, applicationContext)Environment-specific configuration
Switch between dev, staging, and production without separate JSON files:
val (region, userPoolId, clientId) = when (BuildConfig.BUILD_TYPE) { "debug" -> Triple("us-east-1", "us-east-1_dev123", "devClient123") "staging" -> Triple("us-west-2", "us-west-2_staging456", "stagingClient456") else -> Triple("us-east-1", "us-east-1_prod789", "prodClient789")}
val config = AmplifyOutputsData( auth = Auth( awsRegion = region, userPoolId = userPoolId, userPoolClientId = clientId ))
Amplify.configure(config, applicationContext)amplify_outputs.json schema reference
For the full schema of all supported configuration fields, see the amplify_outputs.json reference.