在 SAM(亚马逊的无服务器应用程序模型)中创建代理资源的要求显然很简单。事实上如此简单以至于亚马逊的文档似乎将其保留为 exercise给读者!
我想创建一个 AWS API Gateway 全能端点来将所有内容代理到另一个 HTTP 服务。
在 AWS 控制台中,我尝试构建的配置如下所示:
我见过这个优秀的post作者:Christian Johansen 和他相关的 Stack Overflow 问题 here了解如何在 CloudFormation 中做同样的事情。我想我可以只在 SAM 中使用该代码,但是,SAM 具有其隐式和显式 API,因此如果“正确的方法”是引用隐式资源,我想避免创建显式资源。
有谁知道如何做到这一点?
最佳答案
经过大量的尝试,我相信我在一个例子中找到了答案here .相对于 SAM 开箱即用为您设置的 Hello World 示例的差异是:
diff --git a/sam-app/template.yaml b/sam-app/template.yaml
index 02cd901..f349dcc 100644
--- a/sam-app/template.yaml
+++ b/sam-app/template.yaml
@@ -17,11 +17,11 @@ Resources:
Variables:
PARAM1: VALUE
Events:
- HelloWorld:
+ ProxyApiGreedy:
Type: Api
Properties:
- Path: /hello
- Method: get
+ Path: /{proxy+}
+ Method: ANY
Outputs:
HelloWorldApi:
Description: API Gateway endpoint URL for Prod stage for Hello World function
换句话说,像这样:
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
...
Events:
ProxyApiGreedy:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
关于amazon-web-services - 使用 SAM 创建 API 网关代理资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54385621/