amazon web services - AWS Amplify Functions allow.resource() not working - Stack Overflow

admin2025-04-15  0

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.

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.

Share Improve this question asked Feb 4 at 12:44 LuZelLuZel 831 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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()]);  
转载请注明原文地址:http://www.anycun.com/QandA/1744718758a86663.html