网站安全防护找谁做,郑州做网站企业,网络服务提供者不得为未满多少岁开展工作,网络营销推广方式怎么收费怎么运行aws的示例程序在之前的 几篇 文章中#xff0c;我描述了如何设置Spring Boot应用程序并在AWS Elastic Beanstalk上运行它。 尽管这是从物理服务器到云服务器的重要一步#xff0c;但还有更好的可能#xff01; 走向无服务器 。 这意味着无需花费任何服务器费用… 怎么运行aws的示例程序 在之前的 几篇 文章中我描述了如何设置Spring Boot应用程序并在AWS Elastic Beanstalk上运行它。 尽管这是从物理服务器到云服务器的重要一步但还有更好的可能 走向无服务器 。 这意味着无需花费任何服务器费用也无需维护或配置服务器 听起来不错吧 结合使用AWS Lambda和AWS API Gateway AWS使得无服务器变得非常容易。 在这篇文章中我将描述运行在Elastic BeanStalk上的Spring Boot应用程序运行相同的无服务器功能所需要的处理。 我采取的第一步是摆脱Spring Boot依赖关系因为我们不再需要该容器了。 我用Spring Core和Spring Configuration的依赖关系替换了它们。 此外还对插件进行了更改以构建可用于AWS Lambda的jar。 pom最重要的部分来自于此 ...dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-security/artifactId/dependency......plugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin... 对此 ...dependencygroupIdorg.springframework/groupIdartifactIdspring-core/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion${spring.version}/version/dependency......plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-shade-plugin/artifactIdconfigurationcreateDependencyReducedPomfalse/createDependencyReducedPom/configurationexecutionsexecutionphasepackage/phasegoalsgoalshade/goal/goals/execution/executions/plugin... 下一步是修改Java代码以便通过实现AWS Lambda接口来调用RestController功能 public class LambdaFunctionHandler implements RequestHandlerInvoiceRequest, InvoiceResponse {private static final Logger LOGGER LoggerFactory.getLogger(EasyInvoiceController.class);private EasyInvoiceController easyInvoiceController;Overridepublic InvoiceResponse handleRequest(InvoiceRequest input, Context context) {easyInvoiceController Application.getBean(EasyInvoiceController.class);InvoiceResponse result null;try {result easyInvoiceController.generate(input);} catch (ExecutionException e) {LOGGER.error(e);} catch (InterruptedException e) {LOGGER.error(e);}return result;}
} 使用此类以及一些简单的Spring配置最初由传入HTTP请求调用的RestController功能现在由Lambda请求调用。 就我而言由于我不需要在Lambda代码中保护传入的请求因此我也可以摆脱Spring Security代码因为这将在API网关中完成。 下一步是上传Lambda功能在目标文件夹中生成的jar文件并通过对其进行测试来确保其正常工作。 我利用了S3存储桶上传工具并添加了一些环境变量 最后一步是通过定义API从API网关调用Lambda。 有关示例请参见屏幕截图 我必须说这种无服务器架构可能不适用于所有用例但至少在设计新的应用程序/微服务时或无论如何对架构进行更改时都应该考虑它。 另一个需要注意的是我花了相当多的精力才能使API网关与我创建的Lambda一起使用但是我仍然认为这对于某些情况是一个很好的解决方案。 翻译自: https://www.javacodegeeks.com/2016/12/making-spring-boot-application-run-serverless-aws.html怎么运行aws的示例程序