AWS Api Gateway 使用 2 个路径参数创建资源

问题描述 投票:0回答:1

我正在尝试使用 lambda 在 Api 网关中创建一个带有 2 个参数的 api url。我已经尝试过映射查询参数并且工作正常,但我想在 url 中添加参数。使用 1 个参数可以正常工作,但是使用 2 个参数则显示错误

Resource's path part only allow a-zA-Z0-9._-: or a valid greedy path variable and curly braces at the beginning and the end.

如果我只使用

{userid+}
工作正常,但我需要添加 2 个参数

amazon-web-services aws-lambda aws-api-gateway
1个回答
0
投票

具有内部包含

+
符号的基于路径的参数称为贪婪路径,这意味着端点的下游集成将处理多个路由。因此,在单个 URL 中拥有第二个贪婪路径是无效的。

也许您可能想考虑使用 POST 资源来处理将接受请求正文的请求。

path: /users
method: POST

然后,您必须使用流行的库(例如

fetch

)向其发出 POST 请求
const url = 'https://api.example.com/post-endpoint';
const data = {
  key1: 'value1',
  key2: 'value2'
};

// Making the POST request using fetch
const response = await fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json', // Set the content type to JSON
    // Add other headers if needed
  },
  body: JSON.stringify(data) // Convert data to JSON string
})
© www.soinside.com 2019 - 2024. All rights reserved.