Skip to content

Instantly share code, notes, and snippets.

@ran-isenberg
Created November 16, 2024 06:54
Show Gist options
  • Save ran-isenberg/7775872929811c98f24fdbd056499a3e to your computer and use it in GitHub Desktop.
Save ran-isenberg/7775872929811c98f24fdbd056499a3e to your computer and use it in GitHub Desktop.
appsync main.js
import { Amplify } from 'aws-amplify';
import { events } from 'aws-amplify/data';
// set your API endpoint and API key
Amplify.configure({
"API": {
"Events": {
"endpoint": "https://<YOUR_APPSYNC_ENDPOINT>/event",
"region": "us-east-1",
"defaultAuthMode": "apiKey",
"apiKey": "<YOUR_API_KEY>"
}
}
});
const channel = await events.connect('/default/test');
channel.subscribe({
next: (data) => {
document.getElementById("eventsLog").insertAdjacentText("beforeend", data.event.message + '\n');
},
error: (err) => console.error('error', err),
});
window.publishEvent = () => {
const message = document.getElementById('messageId');
events.post('/default/test', { message: message.value });
message.value = "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment