aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
250 stars 117 forks source link

AppSync realtime endpoint URL is not correct for AWS China regions #2945

Open wulianer opened 4 days ago

wulianer commented 4 days ago

Before opening, please confirm:

Language and Async Model

Java

Amplify Categories

GraphQL API

Gradle script dependencies

```groovy // Put output below this line ```

Environment information

``` # Put output below this line ```

Please include any relevant guides or documentation you're referencing

No response

Describe the bug

Working on Android projects with AWS China service region. The AppSync Query/Mutation methods work well but no subscription method works. Looking into the network traffic detail, I found that the Amplify SDK mistakenly processes the AWS China's realtime endpoint URL to a not existing endpoint URL thus causes the subscription failure . Below is the block of source code that needs update:

private val standardEndpointRegex =
    "^https://\\w{26}\\.appsync-api\\.\\w{2}(?:-\\w{2,})+-\\d\\.amazonaws.com/graphql$".toRegex()

 private val realtime by lazy {
        if (standardEndpointRegex.matches(urlString)) {
            // For standard URLs we insert "realtime" into the domain
            URL(urlString.replace("appsync-api", "appsync-realtime-api"))
        } else {
            // For custom URLs we append "realtime" to the path
            URL("$urlString/realtime")
        }
    }   

All AWS China region AppSync endpoint URLs end with amazonaws.com.cn thus they will not met the stanadardEndpointRegex and will be added /realtime. This is not correct for these URLs.

Besides above code snippet, there are multiple places that have this similar logic to check if an endpoint is a custom domain URL. All of them need update to support China AWS region

Reproduction steps (if applicable)

No response

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

amplifyconfiguration.json

No response

GraphQL Schema

```graphql // Put your schema below this line ```

Additional information and screenshots

No response

mattcreaser commented 3 days ago

Hi @wulianer, thanks for the report. We'll check with the AppSync team about this and get back to you.

mattcreaser commented 7 hours ago

The fix for this issue has been merged and will be included in our next release.