AWS lambda和AWS lambda代理有什么区别?

时间:2017-08-18 11:34:46

标签: python amazon-web-services aws-lambda

我是AWS新手。我知道这可能是个非常外行的问题。 但我试图传递并接受AWS lambda代理中的参数。我能够使用body mapping模板在AWS lambda中执行此操作,是否有任何方法可以在Lambda代理中使用AWS lambda中的queryString映射

2 个答案:

答案 0 :(得分:2)

如果您使用的是Lambda Proxy,API Gateway会将整个客户端请求映射到后端lambda函数的输入事件参数,如下所示。

{
   "resource": "Resource path",
   "path": "Path parameter",
   "httpMethod": "Incoming request's method name"
   "headers": {Incoming request headers}
   "queryStringParameters": {query string parameters }
   "pathParameters":  {path parameters}
   "stageVariables": {Applicable stage variables}
   "requestContext": {Request context, including authorizer-returned key-value pairs}
   "body": "A JSON string of the request payload."
   "isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode"}

请参阅AWS的设置代理集成documentation

以下是解析事件数据(如查询字符串)的example

答案 1 :(得分:0)

如果有人使用无服务器框架来开发和部署lambdas和API网关,那么有一种不同的方法可以将API网关配置为使用开放API规范(即Swagger)的AWS lambda代理!请参阅以下配置示例。



resources:
  Resources:
    SupportProxy:
      Type: "AWS::ApiGateway::RestApi"
      Properties:
        Name: lambda-proxy
        Description: "The API proxy entry point."
        Body:
          swagger: '2.0'
          info:
            version: '2016-09-12T23:19:28Z'
            title: ProxyResource
          basePath: /myapp
          schemes:
            - https
          # Work-around to prevent API Gateway from trying to re-encode binary files (images, fonts, etc) as unicode text.
          x-amazon-apigateway-binary-media-types:
            - '*/*'
          paths:
            /myapp/service1/{proxy+}:
              x-amazon-apigateway-any-method:
                parameters:
                  - name: proxy
                    in: path
                    required: true
                    type: string
                responses: {}
                x-amazon-apigateway-integration:
                  responses:
                    default:
                      statusCode: '200'
                  requestParameters:
                    integration.request.path.proxy: method.request.path.proxy
                  uri: ${service1.url}/{proxy}
                  passthroughBehavior: when_no_match
                  httpMethod: ANY
                  type: http_proxy