본문 바로가기

Backend/AWS

[AWS] Batch (How to Submit Job)

Batch (How to Submit Job)

클라이언트에서 어떻게 작업을 제출할 수 있을까? 

 

AWS 에서는 submit job 에 대한 API 명세를 제공하고 있다. 

https://docs.aws.amazon.com/ko_kr/batch/latest/APIReference/API_SubmitJob.html

 

SubmitJob - AWS Batch

Jobs that run on Fargate resources can't be guaranteed to run for more than 14 days. This is because, after 14 days, Fargate resources might become unavailable and job might be terminated.

docs.aws.amazon.com

 

위의 API 명세를 따라하면 작업을 제출할 수 있다. 그러나 클라이언트에서 직접 API 요청을 하는 것은 위험하다. 토큰이나 Job Queue 와 같은 정보가 샐 수 있기 때문이다. 이를 이용하여 악의적인 클라이언트가 의도적으로 수많은 Batch Job을 생성할 수 있다. 

 

서버에서 하는 것이 안전하다. AWS 에서는 언어별로 API 사용을 쉽게 할 수 있도록 SDK (Software Development Kit) 를 제공한다. 이를 이용하면 직접적으로 API를 호출하지 않고 쉽고 안전하게 작업을 제출할 수 있다. 아래는 파이썬 용 SDK 인 Boto를 이용해서 작업을 제출하는 것에 대한 공식 문서이다. 

 

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/batch/client/submit_job.html

 

submit_job - Boto3 1.33.6 documentation

Previous register_job_definition

boto3.amazonaws.com

 

SubmitJob 내에 다양한 변수를 오버라이딩 할 수 있다. 이를 통해 각각의 작업이 해야하는 일, 환경에 대해서 구체화할 수 있다. 만일 userId 를 받아야 하는 경우, parameter 로 넘길 수 있다. 이는 command 에서 Ref::userId 로 받아 사용할 수 있다. 아래 공식 사이트에 관련 예시가 잘 나와 있다. 

 

 parameters={"userId": "s2rjss2"},
    containerOverrides={
        "command": ["echo", "Ref::userId"],
        "resourceRequirements": [],
        "environment": [],
    },

 

 

https://docs.aws.amazon.com/batch/latest/userguide/example-job-definitions.html

 

Example job definitions - AWS Batch

Example job definitions The following example job definitions illustrate how to use common patterns such as environment variables, parameter substitution, and volume mounts. Use environment variables The following example job definition uses environment va

docs.aws.amazon.com