Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Is aws lambda只能公开一个spring引导api_Java_Amazon Web Services_Spring Boot_Aws Lambda_Microservices - Fatal编程技术网

Java Is aws lambda只能公开一个spring引导api

Java Is aws lambda只能公开一个spring引导api,java,amazon-web-services,spring-boot,aws-lambda,microservices,Java,Amazon Web Services,Spring Boot,Aws Lambda,Microservices,我使用SpringBoot开发了4个API。现在我正在尝试为无服务器启用aws lambda。是否可以使用单个lambda公开4个api 是否可以使用单个lambda公开4个api AWS lambda是FaaS的一种服务,每个lambda有一个功能 但是,您可以使用包装器/代理函数作为入口点来实现预期的功能,并根据需要将请求路由到上游方法/函数 这里描述了它 请参阅以下有关创建API网关=>Lambda代理集成的文档: 下面只是对这里给出的内容的重新解释 AWS示例有很好的解释;Lambd

我使用SpringBoot开发了4个API。现在我正在尝试为无服务器启用aws lambda。是否可以使用单个lambda公开4个api

是否可以使用单个lambda公开4个api

AWS lambda是FaaS的一种服务,每个lambda有一个功能

但是,您可以使用包装器/代理函数作为入口点来实现预期的功能,并根据需要将请求路由到上游方法/函数

这里描述了它

请参阅以下有关创建API网关=>Lambda代理集成的文档:

下面只是对这里给出的内容的重新解释

AWS示例有很好的解释;Lambda请求如下所示:

POST /testStage/hello/world?name=me HTTP/1.1
Host: gy415nuibc.execute-api.us-east-1.amazonaws.com
Content-Type: application/json
headerName: headerValue

{
    "a": 1
}
最终将向AWS Lambda函数发送以下事件数据:

{
  "message": "Hello me!",
  "input": {
    "resource": "/{proxy+}",
    "path": "/hello/world",
    "httpMethod": "POST",
    "headers": {
      "Accept": "*/*",
      "Accept-Encoding": "gzip, deflate",
      "cache-control": "no-cache",
      "CloudFront-Forwarded-Proto": "https",
      "CloudFront-Is-Desktop-Viewer": "true",
      "CloudFront-Is-Mobile-Viewer": "false",
      "CloudFront-Is-SmartTV-Viewer": "false",
      "CloudFront-Is-Tablet-Viewer": "false",
      "CloudFront-Viewer-Country": "US",
      "Content-Type": "application/json",
      "headerName": "headerValue",
      "Host": "gy415nuibc.execute-api.us-east-1.amazonaws.com",
      "Postman-Token": "9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f",
      "User-Agent": "PostmanRuntime/2.4.5",
      "Via": "1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)",
      "X-Amz-Cf-Id": "pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==",
      "X-Forwarded-For": "54.240.196.186, 54.182.214.83",
      "X-Forwarded-Port": "443",
      "X-Forwarded-Proto": "https"
    },
    "queryStringParameters": {
      "name": "me"
    },
    "pathParameters": {
      "proxy": "hello/world"
    },
    "stageVariables": {
      "stageVariableName": "stageVariableValue"
    },
    "requestContext": {
      "accountId": "12345678912",
      "resourceId": "roq9wj",
      "stage": "testStage",
      "requestId": "deef4878-7910-11e6-8f14-25afc3e9ae33",
      "identity": {
        "cognitoIdentityPoolId": null,
        "accountId": null,
        "cognitoIdentityId": null,
        "caller": null,
        "apiKey": null,
        "sourceIp": "192.168.196.186",
        "cognitoAuthenticationType": null,
        "cognitoAuthenticationProvider": null,
        "userArn": null,
        "userAgent": "PostmanRuntime/2.4.5",
        "user": null
      },
      "resourcePath": "/{proxy+}",
      "httpMethod": "POST",
      "apiId": "gy415nuibc"
    },
    "body": "{\r\n\t\"a\": 1\r\n}",
    "isBase64Encoded": false
  }
}
现在您可以访问所有的头、url参数、主体等,因此您可以使用它们在包装器/代理Lambda函数中以不同的方式处理请求,并根据您的路由需要路由到上游函数

今天,许多人使用这种方法,而不是为每个方法和api网关资源创建lambda函数

这种方法有优点也有缺点

  • 部署:如果每个lambda函数都是离散的,那么您可以独立部署它们,这可能会降低代码更改的风险(微服务策略)。相反地,您可能会发现需要单独部署函数会增加复杂性和负担
  • 自我描述:API网关的界面使得查看RESTful端点的布局非常直观——名词和动词一目了然。实现自己的路由可能会以牺牲这种可见性为代价
  • Lambda大小和限制:如果代理所有对象,则需要选择一个实例大小、超时等,以适应所有RESTful端点。如果创建离散函数,则可以更仔细地选择最符合特定调用需要的内存占用、超时、死信行为等
更多关于
单片lambda
微型lambda
的信息,请点击此处: