2016-09-29 69 views
7

我一直在努力研究如何使用Lambda代理集成来表达(在cloudformation中)具有Lambda函数集成类型的API网关资源。如何通过lambda代理集成云端API网关资源

这很容易在AWS控制台做到,因为是一个复选框,您可以选择: API gateway console showing the Use Lambda Proxy Integration checkbox

但是,现在在AWS :: ApiGateway ::方法CloudFormation资源没有相应的字段(它应该在Integration property)。

如何在云端配置此功能?

+2

我们正在努力让CloudFormation更新他们的文档,但正如下面所述,您将集成类型设置为AWS_PROXY,并将HttpMethod设置为POST –

+0

您可以在此处看到一个工作示例:https://stackoverflow.com/questions/48740949 /λ-权限错误 - 当 - 设置 - 使用 - cloudformation和-API网关代理/ 48752056#48752056 – Ilya

回答

7

积分类型应设置为AWS_PROXY。下面是一个来自工作YAML CloudFormation模板的方法示例片段。

ProxyResourceAny: 
    Type: AWS::ApiGateway::Method 
    Properties: 
    AuthorizationType: NONE 
    HttpMethod: ANY 
    ResourceId: 
     Ref: ProxyResource 
    RestApiId: 
     Ref: API 
    Integration: 
     Type: AWS_PROXY 
     IntegrationHttpMethod: POST 
     Uri: !Sub 
     - arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Arn}/invocations 
     - Arn: 
      Fn::GetAtt: 
      - RestorerLambda 
      - Arn 

这是值得一说如何我想通了这一点......

抓我的头一会儿后,我检查了aws apigateway get-method CLI命令的输出已配置使用控制台这样的方法。这给了我以下的JSON,我意识到复选框可能被编码到类型中。我测试了我的假设,并提出了上面的CloudFormation。

{ 
    "apiKeyRequired": false, 
    "httpMethod": "ANY", 
    "methodIntegration": { 
     "integrationResponses": { 
      "200": { 
       "responseTemplates": { 
        "application/json": null 
       }, 
       "statusCode": "200" 
      } 
     }, 
     "passthroughBehavior": "WHEN_NO_MATCH", 
     "cacheKeyParameters": [], 
     "uri": "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:XXXXXXXXX:function:Shildrew-Restorer-Play-Lambda/invocations", 
     "httpMethod": "POST", 
     "cacheNamespace": "64bl3tgw4g", 
     "type": "AWS_PROXY" 
    }, 
    "requestParameters": {}, 
    "authorizationType": "NONE" 
} 
1

我已经通过简单的改变解决了这个相同的问题的

Integration: 
Type: AWS_PROXY 

Integration: 
Type: AWS 

云形成文档目前是稀缺的,API网关cloudformation文档不匹配在控制台上可以看到什么妨碍任何试图解决问题的人。

希望这会有所帮助!

相关问题