score:1
you are correct, in aws appsync, to trigger a subscription publish you must trigger a graphql mutation.
but i found out that subscriptions are tied to mutations and thus an update to the database from step functions will not trigger a subscription update on the frontend.
if you update your dynamodb table directly via step functions or via dynamodb streams, then appsync has no way to know the data refreshed. why don't you have your step function use an appsync mutation instead of updating your table directly? that way you can link a subscription to the mutation and have your interested clients get pushed updates when the data is refreshed.
score:1
assuming you are using cognito as your authentication for your appsync application, you could set a lambda trigger on the dynamo table that generates a cognito token, and uses that make an authorized request to your mutation endpoint. note: in your cognito userpool>app clients page, you will need to check the enable username password auth for admin apis for authentication (allow_admin_user_password_auth) box to generate a client secret.
const aws = require('aws-sdk');
const crypto = require('crypto');
var jwt = require('jsonwebtoken');
const secrets = require('./secrets.js');
var cognitoidentityserviceprovider = new aws.cognitoidentityserviceprovider();
var config;
const adminauth = () => new promise((res, rej) => {
const digest = crypto.createhmac('sha256', config.secrethash)
.update(config.username + config.clientid)
.digest('base64');
var params = {
authflow: "admin_no_srp_auth",
clientid: config.clientid, /* required */
userpoolid: config.userpoolid, /* required */
authparameters: {
'username': config.username,
'password': config.password,
"secret_hash":digest
},
};
cognitoidentityserviceprovider.admininitiateauth(params, function(err, data) {
if (err) {
console.log(err.stack);
rej(err);
}
else {
data.authenticationresult ? res(data.authenticationresult) : rej("challenge requested, to verify, login to app using admin credentials");
}
});
});
const decode = auth => new promise( res => {
const decoded = jwt.decode(auth.accesstoken);
auth.decoded = decoded
res(auth);
});
//example gql query
const testgql = auth => {
const url = config.gqlendpoint;
const payload = {
query: `
query listmembers {
listmembers {
items{
firstname
lastname
}
}
}
`
};
console.log(payload);
const options = {
headers: {
"authorization": auth.accesstoken
},
};
console.log(options);
return axios.post(url, payload, options).then(data => data.data)
.catch(e => console.log(e.response.data));
};
exports.handler = async (event, context, callback) => {
await secrets() //some promise that returns your keys object (i use secrets manager)
.then( keys => {
#keys={clientid:your_cognito_client,
# userpoolid:your_userpool_id,
# secrethash:(obtained from cognito>userpool>app clients>app client secret),
# gqlendpoint:your_graphql_endpoint,
# username:your_cognito_user,
# password:your_cognito_user_password,
# }
config = keys
return adminauth()
})
.then(auth => {
return decode(auth)
})
.then(auth => {
return testgql(auth)
})
.then( data => {
console.log(data)
callback(null, data)
})
.catch( e => {
callback(e)
})
};
Source: stackoverflow.com
Related Query
- React Application Update Data from DynamoDB Change
- Change route from store in React application
- react meteor data container doesn't update child when props change
- How to fix the state update in react while getting data from firestore database
- react .map doesn't update data from array
- When to update local react state based on data from redux?
- React - Update data in the parent component after a change in child component
- How to update Firebase data to the React application in realtime
- Refreshing the state from the database only if there is a change in the database in react redux application
- Update Passed Data from Parent to Child After Axios Request React
- How to update react context after pulling data from firebase
- How to update React Google Map after receive data from server
- Is this the correct way to show data in React from a fetch request, if not how do I change JSX being rendered to a component?
- React redux update input field with user text after data filled from API
- React JS (Form Update Not Working) - How to set state immediately after getting data from API using mapDispatchToProps?
- React Application does not display data fetched from MongoDB Atlas
- Axios get method response in React cannot be displayed getting data from firebase as an array in my blog application
- React - Using componentDidUpdate to update state based on data passed from another function
- Using react to get data from server and update component's state
- In Next.js, how can I update React Context state with data from getServerSideProps?
- React Chart.js Match API data to what Title is displaying, then update chart on data/Title change
- Update data from API fetch request with React Hooks?
- Better way to extract data from HTML table and update react state?
- I have a component which is receiving data from the store. How can I update the data received and rerender the component on change
- How to refresh onscreen data from state change in react and redux
- Load data from external API when route change in isomorphic app using Flux and React
- Struggling in passing data from Child to Parent React Component. Cannot update a component (`App`) while rendering a different component (`Table`)
- How to change active nav color in react js while getting data from an array?
- Cant Update The state after getting data from the input React js
- how to send data from android application running on kotlin to a react js application which is opened on webview?
More Query from same tag
- No routes matched location
- MERN Upload file with multer
- Slice of Redux state returning undefined, initial state not working in mapStateToProps
- React Router Redux upgrade from v3 to v4
- How to handle logout + redirect in a centralized manner
- How to update state of nested array of array of objects without mutating
- ReactJS Hooks incrementing value issue
- How to render a reactjs component stored in a redux reducer?
- React.js application flow error
- Publishing a bare-workflow expo React-Native app to Google Play which was previously published in the managed workflow
- What is the difference between Jest and enzyme?
- How to use react.js with a multi page website (Non SPA)?
- When I try to rename a favicon in a react project to "favicon.ico" the icon changes to react logo
- Why does TS do not get React state assertion from Interface?
- axios cannot get public/[name].json folder in reactjs
- React Native Fetch on Android returns Network request failed
- How does placing an event handler in an anonymous function in React fix bind issues?
- Redux: Two components load same resource, show loader in only one
- Is there a way to test private methods?
- Why Am I getting this "document is not defined" error?
- React: show object as working JS format?
- How to iterate over HTML content in ReactJS
- Transition for moving objects with position: fixed?
- Materialize navbar links conditional rendering
- Making `td`s span throughout the whole row
- ReactJs: Parent or child component responsible for processing data to render view?
- How to use the window.location.assign with ReactJS?
- Copy Props From Parent in ReactJs?
- Map function returns an empty array
- How to access the JWT token value from a response object getting back in axios?