Hey! I'm trying to access AND update data from a LAMBDA function
import type { Schema } from "../../data/resource"
import { generateClient } from "aws-amplify/data";
import { Amplify } from "aws-amplify";
import { type AppSyncIdentityCognito } from 'aws-lambda';
import outputs from '../../../amplify_outputs.json';
Amplify.configure(
outputs
);
const client = generateClient<Schema>({
authMode: "iam",
});
export const handler: Schema["acceptOffers"]["functionHandler"] = async (event) => {
const { id } = event.arguments;
console.log((await client.models.Message.get({id: id as string})).errors);
const message = (await client.models.Message.get({id: id as string})).data;
if(!message) return false;
if(message.recipientId === (event.identity as AppSyncIdentityCognito).username)
{
await client.models.Message.update({id: id as string, offerAccepted: true});
return true;
}
return false;
};
Gives me the following error:
UnauthorizedException: Unknown error
recoverySuggestion: If you're calling an Amplify-generated API, make sure to set the "authMode" in generateClient({ authMode: '...' }) to the backend authorization rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')
And at the end of my data schema declaration (a.schema...), i've added .authorization((allow) => [allow.resource(acceptOffers)]) already
Is there maybe something i'm missing?