如何使用Lambda代理集成来云化API网关资源 [英] How do I cloudform an API gateway resource with a lambda proxy integration

查看:103
本文介绍了如何使用Lambda代理集成来云化API网关资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试找出如何使用Lambda代理集成表达(以cloudformation形式)具有Lambda函数集成类型的API网关资源。

I've been trying to work out how to express (in cloudformation) an API Gateway Resource that has a Lambda function integration type using the Lambda Proxy integration.

在AWS控制台中,这很容易做到,因为您可以选择一个复选框:

This is easy to do in the AWS console as there is a check box that you can select:

但是,AWS :: ApiGateway :: Method CloudFormation资源中没有对应的字段(它应该位于集成属性)。

However there is no corresponding field in the AWS::ApiGateway::Method CloudFormation resource (it should be in the Integration property).

如何在cloudformation中进行配置?

How can I configure this in cloudformation?

推荐答案

集成类型应设置为 AWS_PROXY 。下面是来自可用的YAML CloudFormation模板的方法的示例片段。

The Integration type should be set to AWS_PROXY. An example snippet of a method from a working YAML CloudFormation template is below.

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

值得一提的是我如何解决这个问题...

It's worth saying how a I figured this out...

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

After scratching my head for a while I examined the output of the aws apigateway get-method CLI command for a method that was configured this way using the console. That gave me the following JSON and I realised that the checkbox might be encoded into the type. I tested my assumption and came up with the CloudFormation above.

{
    "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"
}

这篇关于如何使用Lambda代理集成来云化API网关资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆