没有 lambda 的 ApiGateway CloudFormation [英] ApiGateway CloudFormation without lambda

查看:27
本文介绍了没有 lambda 的 ApiGateway CloudFormation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个模板,以便当我调用 api/divide/inputvalue 时,api 会从 DynamoDB 发回对应于 inputvalue 映射.

I am trying to create a template so that when i call api/divide/inputvalue, The api sends back response from DynamoDB which corresponds to inputvalue mapping.

它非常简单,因为我直接从数据库中获取值而没有任何业务逻辑,因此我不需要任何 lambda.但是我谷歌搜索的所有示例或他们使用的所有教程都使用了 lambda,我现在迷失了如何在没有 lambda 的情况下使其工作

Its pretty straight forward since i am fetching value directly from db without any business logic hence I don't need any lambda. But all the examples that I google or all tutorials they are using lambdas and i am now lost that how can i make it working without lambda

这是我目前所拥有的.由于我没有在 ApiGateway::Method 中提供 Uri,所以这个模板现在存在错误.这就是我目前遇到的问题.

This is what I have so far. There is bug in this template right now since I haven't provided Uri in ApiGateway::Method. Which is what I am currently stuck at.

{

  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "Deployment": {
      "Type": "AWS::ApiGateway::Deployment",
      "Properties": {
        "RestApiId": { "Ref": "restApiName" },
        "Description": "First Deployment",
        "StageName": "StagingStage"
      },
      "DependsOn" : ["restApiMethod"]
    },
    "restApiMethod": {
      "Type": "AWS::ApiGateway::Method",
      "Properties": {
        "AuthorizationType": "NONE",
        "HttpMethod": "GET",
        "ResourceId": {"Ref": "apiRestResource"},
        "RestApiId": {"Ref": "restApiName"},
        "Integration": {
          "Type": "AWS",
          "IntegrationHttpMethod": "GET",
          "IntegrationResponses": [{"StatusCode": 200}],
          "Uri": { "Fn::Sub":"arn.aws.apigateway:${AWS::Region}:dynamodb:action/${restApiName.Arn}"}
        },
        "MethodResponses": [{"StatusCode": 200}]
      },
      "DependsOn": ["apiRestResource"]
    },
    "apiRestResource": {
      "Type": "AWS::ApiGateway::Resource",
      "Properties": {
        "RestApiId": {"Ref": "restApiName"},
        "ParentId": {
          "Fn::GetAtt": ["restApiName","RootResourceId"]
        },
        "PathPart": "divide"
      },
      "DependsOn": ["restApiName"]
    },
    "restApiName": {
      "Type": "AWS::ApiGateway::RestApi",
      "Properties": {
        "Name": "CalculationApi"
      }
    }
 }
}

推荐答案

根据文档,Uri 属性的结构如下 AWS 服务代理集成类型:

According to the documentation, the Uri property is structured as follows for AWS service-proxy integration types:

如果您为 Type 属性指定 AWS,请指定遵循以下格式的 AWS 服务:arn:aws:apigateway:region:subdomain.service|service:path|action/service_api.例如,Lambda 函数 URI 遵循以下格式:arn:aws:apigateway:region:lambda:path/path.路径通常采用 /2015-03-31/functions/LambdaFunctionARN/invocations 的形式.有关更多信息,请参阅 uri 中的 Integration 资源的属性Amazon API Gateway REST API 参考.

If you specify AWS for the Type property, specify an AWS service that follows the form: arn:aws:apigateway:region:subdomain.service|service:path|action/service_api. For example, a Lambda function URI follows the form: arn:aws:apigateway:region:lambda:path/path. The path is usually in the form /2015-03-31/functions/LambdaFunctionARN/invocations. For more information, see the uri property of the Integration resource in the Amazon API Gateway REST API Reference.

uri API 网关属性参考提供了更多详细信息:

The uri API Gateway property reference provides more details:

对于 AWS 集成,URI 的格式应为 arn:aws:apigateway:{region}:{subdomain.service|service}:{path|action}/{service_api}.Regionsubdomainservice 用于确定正确的端点.对于使用 Action= 查询字符串参数的 AWS 服务,service_api 应该是所需服务的有效操作.对于 RESTful AWS 服务 API,path 用于指示 URI 中剩余的子字符串应视为资源的路径,包括初始的 /.

For AWS integrations, the URI should be of the form arn:aws:apigateway:{region}:{subdomain.service|service}:{path|action}/{service_api}. Region, subdomain and service are used to determine the right endpoint. For AWS services that use the Action= query string parameter, service_api should be a valid action for the desired service. For RESTful AWS service APIs, path is used to indicate that the remaining substring in the URI should be treated as the path to the resource, including the initial /.

对于调用 dynamodb 服务的 AWS 服务代理"nofollow noreferrer">查询 ActionUri 应该是这样的(使用 Fn::Sub 插入 Ref 适用于当前 AWS 区域):

For an AWS service proxy to the dynamodb service calling the Query Action, the Uri should be something like this (using the YAML short-form of Fn::Sub to insert a Ref for the current AWS region):

!Sub "arn:aws:apigateway:${AWS::Region}:dynamodb:action/Query"

至于使用 API Gateway 访问 DynamoDB 而不使用 Lambda 函数的更广泛用例,请参阅 Andrew Baird 的教程博客文章,"Using Amazon API Gateway as a Proxy for DynamoDB",并将指定的管理控制台步骤转换为相应的CloudFormation 模板资源.

As for your broader use-case of using API Gateway to access DynamoDB without using Lambda functions, refer to Andrew Baird's tutorial blog post, "Using Amazon API Gateway as a Proxy for DynamoDB", and translate the specified Management Console steps to corresponding CloudFormation template resources.

这篇关于没有 lambda 的 ApiGateway CloudFormation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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