Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wulianer opened this issue Nov 11, 2024 · 1 comment
Open

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

wulianer opened this issue Nov 11, 2024 · 1 comment
Labels
api Issues related to the API category bug Something isn't working

Comments

@wulianer
Copy link

wulianer commented Nov 11, 2024

Describe the bug

Working on iOS 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 realtime endpoint URL. Below is the block of source code that needs update:

AmplifyPlugins/API/Sources/AWSAPIPlugin/SubscriptionFactory/AppSyncRealTimeClientFactory.swift

All AWS China AppSync endpoints end with suffix amazonaws.com.cn, not amazonaws.com. Due to the code below, this will cause all AWS China AppSync real time endpoint to have one extra /realtime in the end. The following replacing name logic will also not run.

extension AppSyncRealTimeClientFactory {

    /**
     Converting appsync api url to realtime api url
     1. api.example.com/graphql -> api.example.com/graphql/realtime
     2. abc.appsync-api.us-east-1.amazonaws.com/graphql -> abc.appsync-realtime-api.us-east-1.amazonaws.com/graphql
     */
    static func appSyncRealTimeEndpoint(_ url: URL) -> URL {
        guard let host = url.host else {
            return url
        }

        guard host.hasSuffix("amazonaws.com") else {
            return url.appendingPathComponent("realtime")
        }

        guard var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
            return url
        }

        urlComponents.host = host.replacingOccurrences(of: "appsync-api", with: "appsync-realtime-api")
        guard let realTimeUrl = urlComponents.url else {
            return url
        }

        return realTimeUrl
    }

Steps To Reproduce

As described in the description area.

Expected behavior

User can define the realtime endpoint in the amplifyconfig.json. Why not directly load it from the json instead of using such complex processing logic?

Amplify Framework Version

2.44.0

Amplify Categories

API

Dependency manager

Swift PM

Swift version

5.8

CLI version

12.1.1

Xcode version

15.4

Relevant log output

No response

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS 18.1

Device

iPad, iPhone

Specific to simulators

No response

Additional context

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Nov 11, 2024
@mattcreaser
Copy link
Member

Thanks for filing this issue @wulianer. We will check in with the AppSync team and get back to you soon.

@mattcreaser mattcreaser added bug Something isn't working api Issues related to the API category labels Nov 12, 2024
@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Nov 12, 2024
@mattcreaser mattcreaser removed the pending-triage Issue is pending triage label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the API category bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants