AWS Batch 触发一个 Spring Boot 微服务。

huangapple go评论61阅读模式
英文:

AWS Batch Trigger a spring boot microservices

问题

  1. AWS Batch触发ECR Fargate(按需)
  2. AWS Batch触发部署在ECR中的Spring应用(持续运行)

所以对于选项1,我需要启动一个Spring Boot应用程序,该应用程序应在ECR Fargate中启动。我了解从AWS Batch中,我们可以指定Fargate的集群,这样当AWS Batch运行应用程序时,应用程序将启动。

对于选项2,我在ECR Fargate中部署了一个Spring Boot应用程序,它将持续运行,并且其中包含了Spring Batch。现在,AWS Batch需要触发Spring Batch。如果可能的话,您能否分享实现示例。

此外,从我的客户端应用程序或程序中,我需要更新AWS Batch,通知作业的成功或失败。您能分享这方面的示例吗?

英文:

I have below 2 requirements can you please help share any suggestion

  1. AWS Batch trigger a ECR Fargate ( On demand )
  2. AWS Batch trigger a Spring App deployed in ECR ( running permanently)

SO here Option 1, I need to start a spring boot app which should start in ECR Fargate. this I understood from AWS batch we can specify the Cluster of the Fargate so that when the AWS batch run the app will get started.

For Option 2, I have a spring boot App deployed in ECR Fargate and it will be running, and inside spring batch is there, Now AWS batch need to trigger the spring batch. it is possible if so can you please share the implementation sample.

Also from my client App or program I need to update the AWS batch, saying the job is success or failure. can you share any sample for those as well.

答案1

得分: 2

AWS Batch只执行ECS任务,而不是ECS服务。对于选项1 - 要在ECS Fargate中启动一个容器(运行所需的工作的应用程序),您需要指定AWS Batch计算环境为Fargate,一个引用计算环境的作业队列,以及一个任务定义(要运行的容器、要发送的命令、需要的CPU和内存资源)。有关更多信息,请参阅Learn AWS Batch workshop或AWS Batch的入门文档

对于选项2 - AWS Batch和Spring Batch是正交的解决方案。您应该直接调用Spring Batch API端点,或者依赖于AWS Batch。除非您无法控制,否则不建议同时使用两者。

但是,回答您的问题 - 调用非AWS API端点是在容器和应用程序代码中处理的。AWS Batch不会阻止这样做,但您需要确保容器能够安全地访问调用Spring Boot应用程序所需的凭据。一旦您的批处理作业调用API,您有两个选择:

  1. 立即退出,并在其他地方跟踪Spring批处理操作的状态(即,批处理作业的目的是调用API,成功=“能够成功发送API请求”,失败=“无法调用API”)
  2. 调用API,然后进入一个循环,轮询Spring批处理作业的状态,直到成功完成或失败,然后以与Spring批处理作业相同的状态退出AWS Batch作业。
英文:

AWS Batch only executes ECS tasks not ECS services. For option 1 - to launch a container (your app that does the work you want) within ECS Fargate, you would need to specify an AWS Batch compute environment as Fargate, a job queue that references the compute environment, and a job definition of the task (what container to run, what command to send, what CPU and memory resources are required). See the Learn AWS Batch workshop or the AWS Batch Getting Started documentation for more information on this.

For option 2 - AWS Batch and Spring Batch are orthogonal solutions. You should just call the Spring Batch API endpoint directly OR rely on AWS Batch. Using both is not recommended unless this is something you don't have control over.

But to answer your question - calling an non-AWS API endpoint is handled in your container and application code. AWS Batch does not prevent this but you would need to make sure that the container has secure access to the proper credentials to call the Spring boot app. Once your Batch job calls the API you have two choices:

  1. Immediately exit and track the status of the spring batch operations elsewhere (i.e. The Batch job is to call the API and SUCCESS = "able to send the API request successfully, FAIL = "not able to call the API" )
  2. Call the API, then enter a loop where you poll the status of the Spring batch job until it completes successfully or not, exiting the AWS Batch job with the same state as the Spring batch job did.

huangapple
  • 本文由 发表于 2023年2月7日 02:20:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75365152.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定