### Install dependencies and start the development server Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/react/setup.mdx Navigates to the project directory, installs required packages, and launches the local development server. ```bash cd react-amplified npm install npm run dev ``` -------------------------------- ### Install Dependencies and Run Dev Server Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/start/quickstart/index.mdx Navigate into the project directory, install npm dependencies, and start the development server to view the application. ```bash cd amplify-js-app npm install npm run dev ``` -------------------------------- ### CLI configuration prompts Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/restapi/js/getting-started/11_amplifyInit.mdx Example responses for the interactive API setup process. ```console ? Please select from one of the below mentioned services: `REST` ? Provide a friendly name for your resource to be used as a label for this category in the project: `todoApi` ? Provide a path (e.g., /book/{isbn}): `/todo` ? Choose a Lambda source `Create a new Lambda function` ? Provide the AWS Lambda function name: `todoFunction` ? Choose the function runtime that you want to use: `NodeJS` ? Choose the function template that you want to use: `Serverless ExpressJS function (Integration with API Gateway)` ? Do you want to access other resources created in this project from your Lambda function? `No` ? Do you want to invoke this function on a recurring schedule? `No` ? Do you want to edit the local lambda function now? `No` ? Restrict API access `No` ? Do you want to add another path? `No` ``` -------------------------------- ### Install Amplify Libraries and Start App Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/angular/setup.mdx Install the necessary Amplify Angular libraries and start the Angular development server. ```bash npm install --save aws-amplify @aws-amplify/ui-angular npm start ``` -------------------------------- ### Sign In with TOTP Setup - RxJava Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/auth/android/totp/sign_in.mdx This RxJava snippet shows how to perform a sign-in operation and react to the TOTP setup requirement. It logs the shared secret and the setup URI, guiding the user through the authenticator app configuration. ```java RxAmplify.Auth.signIn("username", "password") .subscribe( result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONTINUE_SIGN_IN_WITH_TOTP_SETUP && result.getNextStep().getTotpSetupDetails() != null ) { Log.d("SignIn", "Received next step as continue sign in by setting up TOTP"); Log.d("SignIn", "Shared Secret is" + result.getNextStep().getTotpSetupDetails().getSharedSecret()); // appName parameter will help distinguish the account in the Authenticator app Uri setupURI = result.getNextStep().getTotpSetupDetails().getSetupURI(""); Log.d("SignIn", "TOTP Setup URI: " + setupURI); // Prompt the user to enter the TOTP code generated in their authenticator app // Then invoke `confirmSignIn` api with the code } }, error -> Log.e("AuthQuickstart", error.toString()) ); ``` -------------------------------- ### Clone and Install Dependencies Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/start/quickstart/index.mdx Commands to clone the starter repository and install required packages. ```bash git clone https://github.com//amplify-vue-template.git cd amplify-vue-template && npm install ``` -------------------------------- ### Continue Sign In with TOTP Setup Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/frontend/auth/sign-in/index.mdx For TOTP setup, display the setup URI from `nextStep.totpSetupDetails.getSetupUri()` to the user, and then collect the OTP from the user to pass to `confirmSignIn`. ```typescript if (nextStep.signInStep === "CONTINUE_SIGN_IN_WITH_TOTP_SETUP") { // present nextStep.totpSetupDetails.getSetupUri() to user // collect OTP from user await confirmSignIn({ challengeResponse: "123456", }); } ``` -------------------------------- ### Sign In with TOTP Setup - Kotlin Callbacks Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/auth/android/totp/sign_in.mdx This Kotlin snippet demonstrates signing in a user and managing the TOTP setup flow. It logs the shared secret and the TOTP setup URI, which should be presented to the user. ```kotlin Amplify.Auth.signIn( "username", "password", { result -> if (result.nextStep.signInStep == AuthSignInStep.CONTINUE_SIGN_IN_WITH_TOTP_SETUP) { Log.d("SignIn", "Received next step as continue sign in by setting up TOTP") Log.d("SignIn", "Shared Secret is" + result.nextStep.totpSetupDetails?.sharedSecret) // appName parameter will help distinguish the account in the Authenticator app val setupURI = result.nextStep.totpSetupDetails?.getSetupURI(">") Log.d("SignIn", "TOTP Setup URI: $setupURI") // Prompt the user to enter the TOTP code generated in their authenticator app // Then invoke `confirmSignIn` api with the code } }, { Log.e("AuthQuickstart", "Failed to sign in", it) } ) ``` -------------------------------- ### Prompt for Amplify Authentication setup Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/develop-with-ai/mcp-server/amplify-workflows/index.mdx Example prompt for configuring email and social sign-in providers. ```text Guide me through setting up Amplify authentication with email sign-in and Google social login. ``` -------------------------------- ### Requesting CI/CD pipeline setup Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/develop-with-ai/mcp-server/amplify-workflows/index.mdx Use this prompt to get help configuring automatic deployments for an Amplify application. ```text Help me set up CI/CD following Amplify best practices so my app deploys automatically when I push to main. ``` -------------------------------- ### Clone and Install Dependencies Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/start/quickstart/index.mdx Commands to clone the starter repository and install required npm packages. ```bash git clone https://github.com//amplify-angular-template.git cd amplify-angular-template && npm install ``` -------------------------------- ### Run Amplify API Mock Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/react/api.mdx Starts the local API mock environment. Requires Java to be installed. ```bash amplify mock api ``` -------------------------------- ### Sign In with TOTP Setup in Swift Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/auth/ios/totp/sign_in.mdx Use this function to initiate sign-in and retrieve the setup URI for TOTP authentication. Ensure the user is prompted to enter the code generated by their authenticator app after receiving the setup URI. ```swift func signIn(username: String, password: String) async { do { let signInResult = try await Amplify.Auth.signIn( username: username, password: password ) if case .continueSignInWithTOTPSetup(let setUpDetails) = signInResult.nextStep { print("Received next step as continue sign in by setting up TOTP") print("Shared secret that will be used to set up TOTP in the authenticator app \(setUpDetails.sharedSecret)") // appName parameter will help distinguish the account in the Authenticator app let setupURI = try setUpDetails.getSetupURI(appName: ">") print("TOTP Setup URI: \(setupURI)") // Prompt the user to enter the TOTP code generated in their authenticator app // Then invoke `confirmSignIn` api with the code } } catch let error as AuthError { print("Sign in failed \(error)") } catch { print("Unexpected error: \(error)") } } ``` -------------------------------- ### Translate Text with Amplify Predictions Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/build-a-backend/add-aws-services/predictions/translate/index.mdx Use the Predictions API to translate text from a source language to a target language. Ensure you have completed the getting started guide for IAM role setup. ```typescript import { Predictions } from '@aws-amplify/predictions'; const result = await Predictions.convert({ translateText: { source: { text: textToTranslate, language : "es" }, targetLanguage: "en" } }) ``` -------------------------------- ### Initialize DataStore with a sync expression Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/datastore/android/sync/50-selectiveSync.mdx Use `syncExpression` to define a filter that gets applied when DataStore starts. This example shows how to set an initial filter based on a `rating` variable. ```Java public Integer rating = 5; public void initialize() { Amplify.addPlugin(AWSDataStorePlugin.builder().dataStoreConfiguration( DataStoreConfiguration.builder() .syncExpression(Post.class, () -> Post.RATING.gt(rating)) .build()) .build()); } ``` ```Kotlin - Callbacks var rating: Int = 5; fun initialize() { Amplify.addPlugin(AWSDataStorePlugin.builder().dataStoreConfiguration( DataStoreConfiguration.builder() .syncExpression(Post::class.java) { Post.RATING.gt(rating) } .build()) .build()) } ``` ```Kotlin - Coroutines var rating = 5 fun initialize() { Amplify.addPlugin(AWSDataStorePlugin.builder().dataStoreConfiguration( DataStoreConfiguration.builder() .syncExpression(Post::class.java) { Post.RATING.gt(rating) } .build()) .build()) } ``` ```RxJava public Integer rating = 5; public void initialize() { RxAmplify.addPlugin(AWSDataStorePlugin.builder().dataStoreConfiguration( DataStoreConfiguration.builder() .syncExpression(Post.class, () -> Post.RATING.gt(rating)) .build()) .build()); } ``` -------------------------------- ### Session Start Event Payload Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/analytics/js/autotrack/autotrack.mdx Example JSON structure of the event sent to Amazon Pinpoint when a session starts. ```json { "eventType": "_session_start", "attributes": { "customizableField": "attr" } } ``` -------------------------------- ### Set Up Backend Resources Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/auth/js/getting-started.mdx Initialize backend authentication resources using the Amplify CLI. ```bash amplify add auth amplify push ``` -------------------------------- ### Setup Commands Source: https://github.com/aws-amplify/docs/blob/main/AGENTS.md Commands to initialize the development environment using Node.js and Yarn. ```bash # Prerequisites: Node.js 20+ (below 22.0.0) corepack enable && yarn set version berry yarn && yarn dev # Site available at http://localhost:3000/ ``` -------------------------------- ### Perform a GET request with Amplify Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/frontend/rest-api/fetch-data/index.mdx Use the get function to invoke a REST endpoint. This example demonstrates overriding the default retry strategy. ```ts import { get } from 'aws-amplify/api'; async function getItem() { try { const restOperation = get({ apiName: 'myRestApi', path: 'items' options: { retryStrategy: { strategy: 'no-retry' // Overrides default retry strategy }, } }); const response = await restOperation.response; console.log('GET call succeeded: ', response); } catch (error) { console.log('GET call failed: ', JSON.parse(error.response.body)); } } ``` -------------------------------- ### Create project directory and files Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/vanillajs/setup.mdx Use these commands to scaffold the project structure and create necessary configuration files. ```bash mkdir -p amplify-js-app/src && cd amplify-js-app touch index.html src/app.js webpack.config.js ``` -------------------------------- ### Initialize Amplify Project Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/project-setup/ios/create-application/30_provisionBackend.mdx Run this command in your project directory to start provisioning backend resources. Follow the prompts to configure your project. ```bash cd ~/Developer/MyAmplifyApp/ amplify init ``` -------------------------------- ### Complete sample application Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/geo/js/maps.mdx A full HTML boilerplate demonstrating the integration of all required scripts, CSS, and initialization logic. ```html Display a map on a webpage
``` -------------------------------- ### Change sync expression by stopping and starting DataStore Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/datastore/android/sync/50-selectiveSync.mdx To reevaluate sync expressions with a new filter, stop and then start DataStore. This example changes the `rating` threshold and restarts DataStore. ```Java public void changeSync() { rating = 1; Amplify.DataStore.stop( () -> Amplify.DataStore.start( () -> Log.i("MyAmplifyApp", "DataStore started"), error -> Log.e("MyAmplifyApp", "Error starting DataStore: ", error) ), error -> Log.e("MyAmplifyApp", "Error stopping DataStore: ", error) ); } ``` ```Kotlin - Callbacks fun changeSync() { rating = 1; Amplify.DataStore.stop( { Amplify.DataStore.start( { Log.i("MyAmplifyApp", "DataStore started") }, { Log.e("MyAmplifyApp", "Error starting DataStore", it) } ) }, { Log.e("MyAmplifyApp", "Error stopping DataStore", it) } ) } ``` ```Kotlin - Coroutines suspend fun changeSync() { rating = 1 try { Amplify.DataStore.stop() Amplify.DataStore.start() Log.i("MyAmplifyApp", "DataStore started") } catch (error: DataStoreException) { Log.w("MyAmplifyApp", "Failed to restart DataStore", error) } } ``` ```RxJava public void changeSync() { rating = 1; RxAmplify.DataStore.stop() .andThen(RxAmplify.DataStore.start()) .subscribe( () -> Log.i("MyAmplifyApp", "DataStore restarted"), error -> Log.e("MyAmplifyApp", "Error restarting DataStore: ", error) ); } ``` -------------------------------- ### Clone and install project dependencies Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/start/quickstart/index.mdx Commands to clone the starter repository and install necessary dependencies for local development. ```bash git clone https://github.com//amplify-vite-react-template.git cd amplify-vite-react-template && npm install ``` -------------------------------- ### Inspect AWS Config Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/start/account-setup/index.mdx Example of the expected configuration structure in the ~/.aws/config file after SSO setup. ```ini [profile default] sso_session = amplify-admin sso_account_id = sso_role_name = AdministratorAccess region = [sso-session amplify-admin] sso_start_url = https://xxxxxx.awsapps.com/start# sso_region = sso_registration_scopes = sso:account:access ``` -------------------------------- ### Handle Sign-In Steps in Kotlin Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/frontend/auth/multi-step-sign-in/index.mdx Demonstrates handling various MFA setup and verification steps during sign-in using Kotlin callbacks. ```kotlin try { Amplify.Auth.signIn( "hello@example.com", "password", { result -> val nextStep = result.nextStep when(nextStep.signInStep){ AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE -> { Log.i("AuthQuickstart", "Received next step as confirm sign in with TOTP code") // Prompt the user to enter the TOTP code generated in their authenticator app // Then invoke `confirmSignIn` api with the code } AuthSignInStep.CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION -> { Log.i("AuthQuickstart", "Received next step as continue sign in by selecting an MFA method to setup") Log.i("AuthQuickstart", "Allowed MFA types for setup ${nextStep.allowedMFATypes}") // Prompt the user to select the MFA type they want to setup // Then invoke `confirmSignIn` api with the MFA type } AuthSignInStep.CONTINUE_SIGN_IN_WITH_EMAIL_MFA_SETUP -> { Log.i("AuthQuickstart", "Received next step as continue sign in by setting up email MFA") // Prompt the user to enter the email address they would like to use to receive OTPs // Then invoke `confirmSignIn` api with the email address } AuthSignInStep.CONTINUE_SIGN_IN_WITH_TOTP_SETUP -> { Log.i("AuthQuickstart", "Received next step as continue sign in by setting up TOTP") ``` -------------------------------- ### Make a GET Request with Amplify API (RxJava) Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/restapi/android/getting-started.mdx Example of making a GET request to a REST API using the Amplify SDK with RxJava. Includes adding path parameters and query parameters. ```rxjava RestOptions request = RestOptions.builder() .addPath("/items") .addQueryParameters(Collections.singletonMap("lang", "en_US")) .build(); RxAmplify.API.get("myAPI", request) .subscribe( response -> Log.i("ApiQuickStart", "GET succeeded: " + response.toString()), failure -> Log.e("ApiQuickStart", "GET failed", failure) ); ``` -------------------------------- ### Navigate to project directory Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/vue/setup.mdx Change into the newly created project directory. ```bash cd myamplifyproject ``` -------------------------------- ### Make a GET Request with Amplify API (Java) Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/restapi/android/getting-started.mdx Example of making a GET request to a REST API using the Amplify SDK in Java. Includes adding path parameters and query parameters. ```java RestOptions request = RestOptions.builder() .addPath("/items") .addQueryParameters(Collections.singletonMap("lang", "en_US")) .build(); Amplify.API.get("myAPI", request, response -> Log.i("ApiQuickStart", "GET succeeded: " + response.toString()), failure -> Log.e("ApiQuickStart", "GET failed", failure) ); ``` -------------------------------- ### Make a GET Request with Amplify API (Kotlin - Coroutines) Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/restapi/android/getting-started.mdx Example of making a GET request to a REST API using the Amplify SDK in Kotlin with coroutines. Includes adding path parameters and query parameters. ```kotlin val request = RestOptions.builder() .addPath("/items") .addQueryParameters(mapOf("lang" to "en_US")) .build() try { val response = Amplify.API.get("myAPI", request) Log.i("ApiQuickStart", "GET succeeded: $response") } catch (error: ApiException) { Log.e("ApiQuickStart", "GET failed", error) } ``` -------------------------------- ### Initialize Amplify Project Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/guides/hosting/nextjs.mdx Run `amplify init` to set up a new Amplify project. You will be prompted for project name, environment, and app details. ```bash $ amplify init ? Enter a name for the project: mynextapp ? Enter a name for the environment: dev ? Choose your default editor: Visual Studio Code (or your preferred editor) ? Choose the type of app that youre building: javascript ? What javascript framework are you using: react ? Source Directory Path: src ? Distribution Directory Path: out ? Build Command: npm run-script build ? Start Command: npm run-script start ? Do you want to use an AWS profile? Y ? Please choose the profile you want to use: ``` -------------------------------- ### Make a GET Request with Amplify API (Kotlin - Callbacks) Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/restapi/android/getting-started.mdx Example of making a GET request to a REST API using the Amplify SDK in Kotlin with callbacks. Includes adding path parameters and query parameters. ```kotlin val request = RestOptions.builder() .addPath("/items") .addQueryParameters(mapOf("lang" to "en_US")) .build() Amplify.API.get("myAPI", request, { Log.i("ApiQuickStart", "GET succeeded: $it") }, { Log.e("ApiQuickStart", "GET failed", it) } ) ``` -------------------------------- ### Handle TOTP Setup for Sign-in Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/frontend/auth/multi-step-sign-in/index.mdx This snippet addresses the `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` step, providing details to configure an authenticator app. It shows how to generate a setup URI and then confirms the sign-in with the TOTP code provided by the user. ```typescript import { type SignInOutput, confirmSignIn } from '@aws-amplify/auth'; async function handleSignInResult(result: SignInOutput) { switch (result.nextStep.signInStep) { case 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP': { const { totpSetupDetails } = result.nextStep; const appName = 'my_app_name'; const setupUri = totpSetupDetails.getSetupUri(appName); // Open setupUri with an authenticator app // Prompt user to enter OTP code to complete setup break; } } } // Then, pass the collected OTP code to `confirmSignIn` async function confirmTotpCode(totpCode: string) { const result = await confirmSignIn({ challengeResponse: totpCode }); return handleSignInResult(result); } ``` -------------------------------- ### Clone Amplify Backend Template Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/start/quickstart/index.mdx Clones the repository for backend template and installs dependencies. Use this to start implementing per-user authorization. ```bash git clone https://github.com//amplify-backend-template.git cd amplify-backend-template npm install ``` -------------------------------- ### Initialize Amplify Backend Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/reactnative/setup.mdx Initialize the Amplify backend and view the configuration prompts. ```bash amplify init ``` ```console ? Enter a name for the project (amplified_todo) The following configuration will be applied: Project information | Name: amplified_todo | Environment: dev | Default editor: Visual Studio Code | App type: javascript | Javascript framework: react-native | Source Directory Path: / | Distribution Directory Path: / | Build Command: npm run-script build | Start Command: npm run-script start ? Initialize the project with the above configuration? Yes Using default provider awscloudformation ? Select the authentication method you want to use: AWS profile ? Please choose the profile you want to use default ``` -------------------------------- ### Requesting Android authentication setup Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/develop-with-ai/mcp-server/amplify-workflows/index.mdx Use this prompt to get instructions on connecting a Kotlin Android application to Amplify with user authentication. ```text Walk me through connecting my Kotlin Android app to Amplify with user authentication. ``` -------------------------------- ### Start Frontend Development Server Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/gen2/quickstart/create-amplify.mdx Launches the local development server for the frontend application. ```bash npm run dev ``` -------------------------------- ### Full sample application Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/build-a-backend/add-aws-services/geo/maps/index.mdx A complete HTML boilerplate demonstrating the integration of map scripts, CSS, and initialization logic. ```html Display a map on a webpage
``` -------------------------------- ### Get Current User with RxJava Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/auth/android/signin_next_steps/80_current_user.mdx This RxJava example shows how to retrieve the current user. It subscribes to the observable to log the result or any errors. ```rxjava RxAmplify.Auth.getCurrentUser().subscribe( result -> Log.i("AuthQuickStart getCurrentUser: " + result.toString()), error -> Log.e("AuthQuickStart", error.toString()) ); ``` -------------------------------- ### Requesting Flutter authentication setup Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/develop-with-ai/mcp-server/amplify-workflows/index.mdx Use this prompt to get help configuring authentication in a Flutter application using the Amplify Authenticator widget. ```text Help me set up authentication in my Flutter app using the Amplify Authenticator widget. ``` -------------------------------- ### Install Amplify client libraries Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/ai/set-up-ai/index.mdx Install the necessary packages for your project. Use the UI-specific packages for React-based frameworks. ```bash npm add aws-amplify @aws-amplify/ui-react @aws-amplify/ui-react-ai ``` ```bash npm add aws-amplify ``` -------------------------------- ### Render PubSub fragments for multiple platforms Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/build-a-backend/add-aws-services/pubsub/set-up-pubsub/index.mdx Uses the Fragments component to map platform keys to the imported PubSub getting started documentation content. ```jsx import pubsubGettingStarted from '/src/fragments/lib/pubsub/js/getting-started.mdx'; ``` -------------------------------- ### Amplify initialization prompts Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/react/setup.mdx Example of the interactive prompts and configuration summary displayed during the amplify init process. ```console ? Enter a name for the project reactamplified The following configuration will be applied: ?Project information | Name: reactamplified | Environment: dev | Default editor: Visual Studio Code | App type: javascript | Javascript framework: react | Source Directory Path: src | Distribution Directory Path: build | Build Command: npm run-script build | Start Command: npm run-script start ? Initialize the project with the above configuration? Yes Using default provider awscloudformation ? Select the authentication method you want to use: AWS profile ... ? Please choose the profile you want to use default ``` -------------------------------- ### Get AWSLocationGeoPlugin Escape Hatch in Java Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/geo/android/escapehatch.mdx Obtain a reference to the AWSLocationGeoPlugin and its escape hatch client in Java. Ensure the 'awsLocationGeoPlugin' is configured in your Amplify setup. ```java import android.util.Log; import androidx.annotation.NonNull; import com.amplifyframework.core.Amplify; import com.amplifyframework.geo.location.AWSLocationGeoPlugin; import aws.sdk.kotlin.services.location.LocationClient; import aws.sdk.kotlin.services.location.model.ListMapsRequest; import aws.sdk.kotlin.services.location.model.ListMapsResponse; import kotlin.Unit; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlinx.coroutines.GlobalScope; ``` ```java // Obtain reference to the plugin AWSLocationGeoPlugin geoPlugin = (AWSLocationGeoPlugin) Amplify.Geo.getPlugin("awsLocationGeoPlugin"); LocationClient locationClient = geoPlugin.getEscapeHatch(); // Send a new request to the Location Maps endpoint directly using the client ListMapsRequest request = ListMapsRequest.Companion.invoke(requestBuilder -> Unit.INSTANCE); locationClient.listMaps(request, new Continuation() { @NonNull @Override public CoroutineContext getContext() { return GlobalScope.INSTANCE.getCoroutineContext(); } @Override public void resumeWith(@NonNull Object resultOrException) { Log.i("MyAmplifyApp", resultOrException.toString()); } }); ``` -------------------------------- ### Initialize Amplify Backend Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/start/quickstart/index.mdx Use the create-amplify command to scaffold the necessary backend files in your project directory. ```bash cd my_amplify_app npm create amplify@latest ? Where should we create your project? (.) # press enter ``` -------------------------------- ### Select Hosting Options Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/angular/hosting.mdx Interactive CLI prompts for selecting the hosting module and deployment type. ```console ? Select the plugin module to execute: # Hosting with Amplify Console (Managed hosting with custom domains, Continuous deployment) ? Choose a type: # Manual Deployment ``` -------------------------------- ### GraphQL Code Generation Prompts Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/reactnative/data-model.mdx These prompts guide the setup for generating GraphQL code. You can choose the target language, file name pattern, and operation depth. ```console ? Do you want to generate code for your newly created GraphQL API Yes ? Choose the code generation language target javascript ? Enter the file name pattern of graphql queries, mutations and subscriptions src/graphql/**/*.js ? Do you want to generate/update all possible GraphQL operations - queries, mutations and subscriptions Yes ? Enter maximum statement depth [increase from default if your schema is deeply nested] 2 ``` -------------------------------- ### Start Local Development Server Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/start/quickstart/index.mdx Command to launch the local development server for testing changes. ```bash npm run start ``` -------------------------------- ### Mock AI Conversation Component Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/frontend/ai/conversation/ai-conversation/index.mdx A basic example of rendering the AIConversation component with empty messages and a placeholder send handler. Useful for visual testing or initial setup. ```tsx import { AIConversation } from '@aws-amplify/ui-react-ai'; export default function Chat() { return ( {}} /> ) } ``` -------------------------------- ### Start DataStore in Java Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/datastore/android/other-methods/20_start.mdx Initiates the DataStore service using Java. Provides callbacks for success and error. ```java Amplify.DataStore.start( () -> Log.i("MyAmplifyApp", "DataStore started"), error -> Log.e("MyAmplifyApp", "Error starting DataStore", error) ); ``` -------------------------------- ### Reevaluate Sync Expressions at Runtime (Stop/Start) Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/datastore/js/sync/50-selectiveSync.mdx To reevaluate sync expressions with updated variables, stop and then start DataStore. This example changes the rating filter from 5 to 1. ```javascript let rating = 5; DataStore.configure({ syncExpressions: [ syncExpression(Post, () => { return (post) => post.rating.gt(rating); }) ] }); async function changeSync() { rating = 1; await DataStore.stop(); await DataStore.start(); } ``` -------------------------------- ### Subscribe to DataStore Network Status (Kotlin - Coroutines) Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/datastore/android/datastore-events.mdx Utilize this Kotlin coroutine example to subscribe to DataStore network status events. Requires Amplify setup and coroutine support. ```kotlin Amplify.Hub.subscribe(DATASTORE) { it.name == NETWORK_STATUS.toString() } .collect { val event = it.data as NetworkStatusEvent Log.i("MyAmplifyApp", "User has a network connection: ${event.active}") } ``` -------------------------------- ### Navigate to Nuxt Project Directory Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/guides/hosting/nuxt.mdx Change into the newly created Nuxt project directory to proceed with the setup. ```sh cd amplify-nuxt ``` -------------------------------- ### Define a global authorization rule Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/build-a-backend/data/customize-authz/index.mdx Applies an authorization rule to all data models that lack a specific model-level rule. Use this for getting started, but prefer specific rules for production environments. ```ts const schema = a.schema({ // Because no model-level authorization rule is present // this model will use the global authorization rule. Todo: a.model({ content: a.string() }), // Will use model-level authorization rule Notes: a.model({ content: a.string() // [Model-level authorization rule] }).authorization(allow => [allow.publicApiKey().to(['read'])]) // [Global authorization rule] }).authorization(allow => [ allow.publicApiKey() ]) ``` -------------------------------- ### Full Application Initialization Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/logging/android/setup_logging/30_initialize_without_config.mdx Complete implementation of the Application class with Amplify configuration. ```java public class MyAmplifyApp extends Application { @Override public void onCreate() { super.onCreate(); try { // Add these lines to add the AWSCognitoAuthPlugin and AWSCloudWatchLoggingPlugin plugins Amplify.addPlugin(new AWSCognitoAuthPlugin()); AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (,,1,60); Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config)); Amplify.configure(getApplicationContext()); Log.i("MyAmplifyApp", "Initialized Amplify"); } catch (AmplifyException error) { Log.e("MyAmplifyApp", "Could not initialize Amplify", error); } } } ``` ```kotlin class MyAmplifyApp : Application() { override fun onCreate() { super.onCreate(); try { // Add these lines to add the AWSCognitoAuthPlugin and AWSCloudWatchLoggingPlugin plugins Amplify.addPlugin(AWSCognitoAuthPlugin()) val config = AWSCloudWatchLoggingPluginConfiguration(logGroupName = , region = , localStoreMaxSizeInMB = 1, flushIntervalInSeconds = 60) Amplify.addPlugin(AWSCloudWatchLoggingPlugin(config)) Amplify.configure(applicationContext) Log.i("MyAmplifyApp", "Initialized Amplify") } catch (error: AmplifyException) { Log.e("MyAmplifyApp", "Could not initialize Amplify", error) } } } ``` ```java public class MyAmplifyApp extends Application { @Override public void onCreate() { super.onCreate(); try { // Add these lines to add the AWSCognitoAuthPlugin and AWSCloudWatchLoggingPlugin plugins RxAmplify.addPlugin(new AWSCognitoAuthPlugin()); AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (,,1,60); RxAmplify.addPlugin(new AWSCloudWatchLoggingPlugin(config)); RxAmplify.configure(getApplicationContext()); Log.i("MyAmplifyApp", "Initialized Amplify"); } catch (AmplifyException error) { Log.e("MyAmplifyApp", "Could not initialize Amplify", error); } } } ``` -------------------------------- ### Transcribe Audio to Text Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/build-a-backend/add-aws-services/predictions/transcribe-audio/index.mdx Use this snippet to transcribe a PCM Audio byte buffer to text. Ensure you have completed the getting started section and set up IAM roles with the correct policy actions. ```typescript import { Predictions } from '@aws-amplify/predictions'; const { transcription } = await Predictions.convert({ transcription: { source: { bytes } } }) ``` -------------------------------- ### Requesting Amplify sandbox environment setup Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/develop-with-ai/mcp-server/amplify-workflows/index.mdx Use this prompt to initiate the workflow for creating a personal cloud sandbox environment for backend testing. ```text Guide me through setting up an Amplify sandbox environment for testing backend changes. ``` -------------------------------- ### Sign In with TOTP Setup - Java Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/auth/android/totp/sign_in.mdx Use this snippet to sign in a user and handle the next step if it requires Two-Factor Authentication (TOTP) setup. Log the shared secret and the setup URI for the user's authenticator app. ```java Amplify.Auth.signIn( "username", "password", result -> { if (result.getNextStep().getSignInStep() == AuthSignInStep.CONTINUE_SIGN_IN_WITH_TOTP_SETUP && result.getNextStep().getTotpSetupDetails() != null) { Log.d("SignIn", "Received next step as continue sign in by setting up TOTP"); Log.d("SignIn", "Shared Secret is" + result.getNextStep().getTotpSetupDetails().getSharedSecret()); // appName parameter will help distinguish the account in the Authenticator app Uri setupURI = result.getNextStep().getTotpSetupDetails().getSetupURI(""); Log.d("SignIn", "TOTP Setup URI: " + setupURI); // Prompt the user to enter the TOTP code generated in their authenticator app // Then invoke `confirmSignIn` api with the code } }, error -> Log.e("SignIn", error.toString()) ); ``` -------------------------------- ### Sign In User with Username and Password (Kotlin Coroutines) Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/auth/android/sms/sign_in.mdx Implement user sign-in with username and password using Kotlin Coroutines. This example handles potential exceptions and checks for TOTP setup requirements. ```kotlin try { val result = Amplify.Auth.signIn("username", "password") if (result.nextStep.signInStep == AuthSignInStep.CONTINUE_SIGN_IN_WITH_TOTP_SETUP) { val destination = result.nextStep.codeDeliveryDetails?.destination Log.d("SignIn", "SMS code sent to $destination") Log.d("SignIn", "Additional Info $result.nextStep.additionalInfo") // Prompt the user to enter the SMSMFA code they received // Then invoke `confirmSignIn` api with the code } } catch (error: AuthException) { Log.e("AuthQuickstart", "Sign in failed", error) } ``` -------------------------------- ### Amplify Status Output Example Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/reactnative/data-model.mdx Example output showing the current environment and resource status. ```console Current Environment: dev | Category | Resource name | Operation | Provider plugin | | -------- | ------------- | --------- | ----------------- | | Api | myapi | No Change | awscloudformation | ``` -------------------------------- ### Listen to Auth Events with Amplify Hub Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/auth/js/hub_events/10_listen_events.mdx Set up a listener for authentication events. This example handles 'signIn', 'updateUserAttributes', and 'signOut' events, logging the event type. Ensure the 'aws-amplify' library is installed and configured. ```javascript import { Hub } from 'aws-amplify'; const listener = (data) => { switch (data.payload.event) { case 'signIn': logger.info('user signed in'); break; case 'updateUserAttributes': logger.info('user attributes update failed'); break; case 'signOut': logger.info('user signed out'); break; default: logger.info('unknown event type'); break; } }; Hub.listen('auth', listener); ``` -------------------------------- ### Configure Amplify and Initialize Client Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/graphqlapi/js/working-with-files.mdx Sets up the Amplify library with configuration and initializes the GraphQL client. ```javascript import { useState } from 'react'; import { Amplify } from 'aws-amplify'; import { generateClient } from 'aws-amplify/api'; import { getUrl, uploadData, remove } from 'aws-amplify/storage'; import { Authenticator } from '@aws-amplify/ui-react'; import '@aws-amplify/ui-react/styles.css'; import config from './amplifyconfiguration.json'; import * as queries from './graphql/queries'; import * as mutations from './graphql/mutations'; Amplify.configure(config, { Storage: { S3: { // configures default access level defaultAccessLevel: 'private' } } }); const client = generateClient(); ``` -------------------------------- ### List files in a path Source: https://github.com/aws-amplify/docs/blob/main/src/pages/[platform]/frontend/storage/list-files/index.mdx Use the `list` API to get a list of files within a specified path. Ensure the path ends with a '/' to match files within that directory. For example, `list({ path: 'album/photos/' })`. ```javascript import { list } from 'aws-amplify/storage'; const result = await list({ path: 'album/photos/', // Alternatively, path: ({identityId}) => `album/${identityId}/photos/` }); ``` -------------------------------- ### React App with AWS Amplify Delta Sync Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/lib/graphqlapi/js/delta-sync.mdx Integrate AWS Amplify client synchronization into a React application. This example shows client initialization, sync setup, and rendering components that fetch data from the cache. ```typescript const client = new AWSAppSyncClient({ url: awsconfig.aws_appsync_graphqlEndpoint, region: awsconfig.aws_appsync_region, auth: { type: awsconfig.aws_appsync_authenticationType, apiKey: awsconfig.aws_appsync_apiKey } }); client.hydrated().then(() => client.sync( buildSync("Post", { baseQuery: { query: DeltaSync.BaseQuery }, subscriptionQuery: { query: DeltaSync.Subscription }, deltaQuery: { query: DeltaSync.DeltaSync }, cacheUpdates: ({ id }) => [ { query: DeltaSync.GetItem, variables: { id } } ] }) ) ); const App = () => (

); ``` -------------------------------- ### Initialize Amplify Project Source: https://github.com/aws-amplify/docs/blob/main/src/fragments/start/getting-started/ios/setup.mdx Initialize your Amplify project with quickstart options for an iOS frontend. This command sets up the basic Amplify configuration for your project. ```bash amplify init --quickstart --frontend ios ```