How to change AWS Amplify Appsync default authorization mode form API KEY to cognito user pool?
Asked Answered
H

1

2

I'm working with Amplify, I added the authentication to my application and my graphQL schema is with rule private, all things work good in my local, each graphQl api called, It contains the access token and appSync accept my request. But when I deploy my App, I get an error because all my graphQl request still with api-key not with access token.

my schema.graphQl enter image description here

My AWSAppSyncClient enter image description here

In the console I use this configuration: enter image description here

In my local : all thins work good after authentication.

enter image description here

In production : graphQl still with api-key after authentication

enter image description here

Hydromel answered 28/5, 2022 at 18:0 Comment(0)
V
9

Based on this documentation I ran amplify update api:

From there the command line prompts you to select the API type:

? Please select from one of the below mentioned services:
    > `GraphQL`
? Select a setting to edit:
    > `Authorization modes`
? Choose the default authorization type for the API
  API key
  Amazon Cognito User Pool
❯ IAM
  OpenID Connect

I updated the default authorization type for the API to be Amazon Cognito User Pool instead of API key.

Then I had to run amplify push --appId YOUR_APP_ID --envName YOUR_STAGING_ENV to sync up the changes.

Voroshilov answered 28/10, 2022 at 12:49 Comment(1)
Thanks for this. I saw your answer on #73142349Gravy

© 2022 - 2024 — McMap. All rights reserved.