Which Category is your question related to?
Amplify Cognito
What AWS Services are you utilizing?
Amplify CLI Function Admin Queries
Amplify CLI comes with the function AdminQueries
. It is a powerful tool to list users, add user to group and do all sorts of Cognito stuff. However, I struggle to find a complete documentation and examples. Is there a complete documentation and examples somewhere? Thanks
There's some limited information in the Amplify docs: https://aws-amplify.github.io/docs/cli-toolchain/quickstart#administrative-actions
For more detailed information, check out the cognito docs:
https://docs.aws.amazon.com/cognito/index.html
The API reference might be useful:
https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/Welcome.html
Let me know if that helps.
Thanks a bunch for prompt response. The examples seem to be a great starting point. I know I came across it at some point but struggle to find it this time (no luck searching for Amplify Admin Queries
on google). But this is exactly what I am looking for. Thanks again.
@xitanggg Although it's too late but it may help others.
This section has very short description of predefined AdminQueries api end-pints
https://docs.amplify.aws/cli/auth/admin#admin-queries-api
When we create a amplify cli project and allow AdminQueries, it creates a lambda function inside amplify/backend/function/AdminQueriesXXXXXXX
This folder contains following files
src/
- index.js
- app.js
- cognitoActions.js`
- package.json
app.js
contains express based api endpoints e.g.
app.post('/addUserToGroup', async (req, res, next) => {
if (!req.body.username || !req.body.groupname) {
const err = new Error('username and groupname are required');
err.statusCode = 400;
return next(err);
}
try {
const response = await addUserToGroup(req.body.username, req.body.groupname);
res.status(200).json(response);
} catch (err) {
next(err);
}
});
By default, you get following endpoints/sub-functions
You can add any endpoint and do any thing that AWS SDK (js) provides. e.g. you can add another endpoint to create a user as a post request. createUser
function used in code below is imported from cognitoActions.js
file (which you need to write and export in that file) or you can even write this logic right inside this api endpoint callback.
app.post('/createUser', async (req, res, next) => {
try {
const response = await createUser(req.body);
res.status(200).json(response);
} catch (err) {
next(err);
}
});
Most helpful comment
@xitanggg Although it's too late but it may help others.
This section has very short description of predefined AdminQueries api end-pints
https://docs.amplify.aws/cli/auth/admin#admin-queries-api
When we create a amplify cli project and allow AdminQueries, it creates a lambda function inside
amplify/backend/function/AdminQueriesXXXXXXX
This folder contains following files
src/
- index.js
- app.js
- cognitoActions.js`
- package.json
app.js
contains express based api endpoints e.g.By default, you get following endpoints/sub-functions
You can add any endpoint and do any thing that AWS SDK (js) provides. e.g. you can add another endpoint to create a user as a post request.
createUser
function used in code below is imported fromcognitoActions.js
file (which you need to write and export in that file) or you can even write this logic right inside this api endpoint callback.