【问题标题】:Can I skip generating the {proxy+} when creating Rest API using Amplify我可以在使用 Amplify 创建 Rest API 时跳过生成 {proxy+}
【发布时间】:2021-11-25 20:19:11
【问题描述】:

我目前正在尝试使用 amplify 创建 rest-api:s。我正在尝试创建以下结构:

  • /helloText
  • /helloText/{name}

但是在尝试推送后端时出现以下错误:

Unable to create resource at path '/helloText/{proxy+}': A sibling ({name}) of this resource already has a variable path part -- only one is allowed

据我了解,这是因为 Amplify 默认创建“贪婪路径”。

当从模板文件 RestTest-cloudformation-template.json 手动删除这些“贪婪路径”时,它可以工作。

是否有可能仅使用命令行来创建这些路径?

【问题讨论】:

    标签: aws-api-gateway aws-amplify aws-amplify-cli


    【解决方案1】:

    在 amplify-cli 中没有配置开关。您需要创建一个覆盖。参考:Amplify override api。 运行:

    amplify override api
    

    然后编辑生成的 override.ts 比如:

    import { AmplifyApiRestResourceStackTemplate } from '@aws-amplify/cli-extensibility-helper';
    
    export function override(resources: AmplifyApiRestResourceStackTemplate) {
      const {paths} = resources.restApi.body;
      Object.keys(paths).forEach((path) => {
        if (path.includes('{proxy+}')) {
          delete paths[path];
        }
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 1970-01-01
      • 2022-11-10
      • 2021-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多