Skip to content

Subscriptions not receiving events in Amplify Gen 2 with authorization owner and defaultAuthorizationMode userPool #4062

@cesmejia

Description

@cesmejia

Describe the bug

DynamoDB/AppSync not firing subscriptions with the following settings:

data - resource.ts

import { type ClientSchema, a, defineData } from '@aws-amplify/backend';

const schema = a.schema({
  Todo: a.model({
      content: a.string(),
      isDone: a.boolean()
    })
    .authorization(allow => [allow.owner()])
});

// Used for code completion / highlighting when making requests from frontend
export type Schema = ClientSchema<typeof schema>;

// defines the data resource to be deployed
export const data = defineData({
  schema,
  authorizationModes: {
    defaultAuthorizationMode: 'userPool'
  }
});

Client:

private var subscription: AmplifyAsyncThrowingSequence<GraphQLSubscriptionEvent<Todo>>
    
    init() {
        self.subscription = Amplify.API.subscribe(request: .subscription(of: Todo.self, type: .onCreate, authMode: .amazonCognitoUserPools))
    }

func subscribe() async {
        do {
            for try await subscriptionEvent in subscription {
                handleSubscriptionEvent(subscriptionEvent)
            }
        } catch {
            print("Subscription has terminated with \(error)")
        }
    }
    
    private func handleSubscriptionEvent(_ subscriptionEvent: GraphQLSubscriptionEvent<Todo>) {
        switch subscriptionEvent {
        case .connection(let subscriptionConnectionState):
            print("Subscription connect state is \(subscriptionConnectionState)")
        case .data(let result):
            switch result {
            case .success(let createdTodo):
                print("Successfully got todo from subscription: \(createdTodo)")
                todos.append(createdTodo)
            case .failure(let error):
                print("Got failed result with \(error.errorDescription)")
            }
        }
    }

Steps To Reproduce

Steps to reproduce the behavior:
1. Set TODO authorization to allow.owner()
2. Set defaultAuthorizationMode to 'userPool'
3. On client, subscribe to TODO .onCrete with authMode: .amazonCognitoUserPools
4. Run your app... 
5. Subscription says its connected
6. Add a Todo with createTodo()
7. No Todo is fired through web sockets

Expected behavior

Newly created TODO is fired and received through web sockets subscription.
With these settings CRUD functions work as expected.
Subscriptions works whenever you remove the TODO authorization allow.owner()

Amplify Framework Version

2.51.0

Amplify Categories

DataStore

Dependency manager

Swift PM

Swift version

6.0

CLI version

2.2.1

Xcode version

26.0

Relevant log output

<details>
<summary>Log Messages</summary>


Subscription connect state is connecting
Subscription connect state is connected

</details>

Is this a regression?

No

Regression additional context

No response

Platforms

No response

OS Version

iOS 26

Device

iPhone Air

Specific to simulators

No

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiIssues related to the API categorybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions