I get this error: "Not Authorized to access listLogins on type Query"
My Schema permissions (Login table).
type Login @model @auth(rules: [{allow: private, provider: iam}]) {
I followed the guides inside and out multiple times.https://docs.amplify.aws/guides/functions/graphql-from-lambda/q/platform/js/#iam-authorization
I setup API with IAM access, then I added my function using the PostAuthentication Trigger (Cognito), updated my function
but it still seems like Lambda is not authorised to use GraphQL API.
**My understanding is Amplify cli should have taken care of this...
or do I have to provision the policies separately (seems counter to the whole amplify vibe)
**
The command > amplify update function only offer these:
(*) api
( ) auth
( ) function
( ) storage
Here is my code:
exports.handler = async (event) => {
const query = /* GraphQL */ query LIST_LOGINS { listLogins { items { id Type Status Message }}};
const endpoint = new URL(GRAPHQL_ENDPOINT);
const signer = new SignatureV4({
credentials: defaultProvider(),
region: AWS_REGION,
service: 'appsync',
sha256: Sha256
});
const requestToBeSigned = new HttpRequest({
method: 'POST',
headers: {
'Content-Type': 'application/json',
host: endpoint.host
},
hostname: endpoint.host,
body: JSON.stringify({ query }),
path: endpoint.pathname
});
const signed = await signer.sign(requestToBeSigned);
const request = new Request(GRAPHQL_ENDPOINT, signed);
let statusCode = 200;
let body;
let response;
try {
response = await fetch(request);
body = await response.json();
if (body.errors) {
statusCode = 400;
console.log("body.errors: ", body.errors);
}else{ console.log("response: ", response); }
} catch (error) {
statusCode = 500;
body = {
errors: [
{
message: error.message
}]};
}
return { statusCode, body: JSON.stringify(body) };
};