Amplify API GraphQL - 无法使用在线生成的 API 密钥更改本地 API 密钥

Sim*_*rro 3 amazon-web-services aws-appsync aws-amplify

为了更新我的 API 密钥,我曾经使用 AWS AppSync \xe2\x86\x92 设置并生成一个新密钥。

\n

之后,在我的本地应用程序中,找到旧的 API 密钥并将其替换为新的 API 密钥...直到昨天,这都工作正常,但现在,无论我做什么,当我运行时,amplify status它都会输出我的旧 API 密钥。

\n

我也尝试过amplify update api但没有运气。后来我尝试amplify pull看看它是否使用网络应用程序(AppSync)中的新密钥更新我的本地 API 密钥,但仍然没有成功。

\n

我已经在线生成了有效的 API 密钥,为什么我无法使用相同的密钥更新本地 API 密钥?

\n

Nin*_*les 12

尝试这个解决方案:

\n
    \n
  1. 在项目中打开此文件夹amplify/backend/<api>/parameters.json

    \n
  2. \n
  3. 添加这些行:

    \n

    "APIKeyExpirationEpoch": -1,\n"CreateAPIKey": -1

    \n
  4. \n
  5. 从终端运行amplify push.

    \n
  6. \n
\n

这应该从堆栈中删除 API 密钥。现在,从 中删除APIKeyExpirationEpoch和,并使用 CLI 创建一个新密钥:CreateAPIKeyparameters.json

\n
amplify update api\n
Run Code Online (Sandbox Code Playgroud)\n

在这里,大多数情况下,您必须选择:

\n
? Select from one of the below mentioned services: -> GraphQL (or rest API, it depends on your needs)\n? Select a setting to edit -> Authorization modes\n? Choose the default authorization type for the API -> API key\n\xe2\x9c\x94 After how many days from now the API key should expire (1-365): ->365\n? Configure additional auth types? ->No\n
Run Code Online (Sandbox Code Playgroud)\n

最后运行:

\n
amplify push\n
Run Code Online (Sandbox Code Playgroud)\n

通过此解决方案,您可以将 API 密钥续订 1 年。

\n