首页 文章

没有lambda的ApiGateway CloudFormation

提问于
浏览
0

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

它很直接,因为我直接从db获取值而没有任何业务逻辑,因此我不需要任何lambda . 但是我谷歌或所有教程的所有例子他们都在使用lambdas而我现在迷失了,我怎么能让它在没有lambda的情况下工作

这就是我到目前为止所拥有的 . 由于我没有在 ApiGateway::Method 中提供 Uri ,因此此模板中存在错误 . 这就是我目前所坚持的 .

{

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

1 回答

  • 1

    根据文档,对于 AWS service-proxy集成类型,Uri属性的结构如下:

    如果为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形式 . 有关更多信息,请参阅Amazon API Gateway REST API Reference中的Integration资源的uri属性 .

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

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

    对于调用Query Actiondynamodb 服务的AWS服务代理, Uri 应该是这样的(使用Fn::Sub的YAML短格式为当前AWS区域插入Ref):

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

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

相关问题