I am writing an app in Flutter and use AWS Amplify for this.
Now I am creating a simple Blacklist check in an AWS Amplify function. For this this function needs access to my database table given in my resource.ts file like this:
BlacklistData: a.model({
Word: a.string().required(),
})
//.authorization(allow => [allow.resource(blacklistPost), allow.authenticated()])
.authorization(allow => [allow.authenticated()])
.identifier(['Word']),
When I now take the aws amplify documentation it says you should use .authorization(allow => [allow.resource(functionWithDataAccess)]);
But when I add this in my ressource.ts file like this:
BlacklistData: a.model({
Word: a.string().required(),
})
//.authorization(allow => [allow.resource(blacklistPost), allow.authenticated()])
.authorization(allow => [allow.authenticated(), allow.resource(blacklist)])
.identifier(['Word']),
It always gives me an error in VS Code:
and in the aws cli sandbox it writes me the following lines:
What is wrong with my implementation that it is not working like in the documentation? Am I missing something obvious or is this a bug? Badly I was not able to solve this with KI or Googeling.
You are doing it wrong. You should apply authorization on entire schema, not just a specific model.
Try this, it should work.
const schema = a
.schema({
BlacklistData: a.model({
Word: a.string().required(),
})
})
.authorization(allow => [allow.resource(blacklistPost), allow.authenticated()]);