Lambda Integration vs. Lambda Proxy: Pros and Cons

前端 未结 4 1428
滥情空心
滥情空心 2020-12-13 00:22

What do you think are the Pros and Cons of using Lambda integration with and without the proxy feature in AWS API Gateway (and more specifically, when using the Serverless f

4条回答
  •  执笔经年
    2020-12-13 00:50

    Because of body mapping template - proxy is better.

    I do not like body mapping template because in exported Swagger it is escaped, for example:

            uri: "arn:aws:apigateway:us-east-1:dynamodb:action/UpdateItem"
            responses:
              default:
                statusCode: "200"
            requestTemplates:
              application/json: "{\n    \"TableName\": \"happy-marketer\",\n    \"Key\"\
                : {\n        \"pk\": {\n            \"S\": \"project\"\n        },\n \
                \       \"sk\": {\n            \"S\": \"$context.authorizer.claims.email\
                \ $util.urlDecode($input.params('name'))\"\n        }\n    },\n    \"\
                UpdateExpression\": \"SET projectStatus = :c\",\n    \"ExpressionAttributeValues\"\
                : {\n        \":c\": {\n            \"S\": \"Completed\"\n\n        }\n\
                \    }\n}"
            passthroughBehavior: "never"
            httpMethod: "POST"
            type: "aws"
      /projects/{name}/status/restore:
        options:
          consumes:
          - "application/json"
          produces:
          - "application/json"
          parameters:
          - name: "name"
            in: "path"
    

    And as you understand - this is bad to edit such "code" locally and deploy this swagger file. Also when you edit body mapping template in the browser - you will not receive errors about your wrong JSON / Apache Velocity. For example here we have a mistake:

    {
      "email": "$context.authorizer.claims.email",
      "nameOld": "$util.urlDecode($input.params('name'))",
    
      #if ($input.path('$.nameNew') != "")
      "nameNew": "$util.urlDecode($input.path('$.nameNew'))",
      #end
    
      #if ($input.path('$.ownerNew') != "")
      "ownerNew": "$input.path('$.ownerNew')",
      #end
    
      #if ($input.path('$.shared') != "")
      "shared": $input.json('$.shared')
      #end
    
      #if ($input.path('$.StartDate') != "")
      , "startDate": "$input.path('$.StartDate')"
      #end
    
      #if ($input.path('$.DueDate') != "")
      , "dueDate": "$input.path('$.DueDate')"
      #end
    }
    

    The mistake is - wrong , before startDate. My backend code in Go is free from such mistakes. I do not want to write tests for Apache Velocity.

    Also, maybe Proxy Integrations are faster - because of missing "service-in-the-middle".

提交回复
热议问题