0

I want to use API gateway with AWS batch

I already know how to use API Gateway with AWS lambda naad since there is a limit of 250 MB in lambda, I am not able to use it for integration and now trying AWS batch

1 Answer 1

1

I am assuming that you want to use API Gateway + Lambda to create an endpoint for submitting job requests to AWS Batch.

In order to do so create the following Lambda function, which submits a job to AWS Batch. Replace "jobQueueArn" with the arn of your job queue. Integrate the Lambda function with API Gateway.

import boto3

def lambda_handler(event, context):

    client = boto3.client('batch')

    JOB_NAME = event['JobName']
    JOB_QUEUE = "jobQueueArn"
    JOB_DEFINITION = "a-job-definition:1"

    response = client.submit_job(
        jobName = JOB_NAME,
        jobQueue = JOB_QUEUE,
        jobDefinition = JOB_DEFINITION,
        parameters = { 'key': 'value' }
        )
    print(response)
    return 0

Parameters can be passed using the parameters input.

parameters (dict) -- Additional parameters passed to the job that replace parameter substitution placeholders that are set in the job definition. Parameters are specified as a key and value pair mapping. Parameters in a SubmitJob request override any corresponding parameter defaults from the job definition.

Make sure to attach the proper IAM policy to the Lambda Function's role.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "batch:SubmitJob"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Yuke, but i have more question as to how I can pass input parameters coming from API to batch. Lets say a json goes as input into the API { "value" : 123"} how will it take this value as an input, since earlier lambda used to handle it
Hi Arpit, you can, simply add parameters as input for Client.submit_job function as described in the docs boto3.amazonaws.com/v1/documentation/api/latest/reference/…
I am not able to get the aws batch output in lambda. How can i see the batch result in lambda logs ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.