api网关与AWS Batch集成 [英] api gateway integration with aws batch

查看:113
本文介绍了api网关与AWS Batch集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将API网关与AWS Batch配合使用

I want to use API gateway with AWS batch

我已经知道如何将API Gateway与AWS lambda naad一起使用,因为lambda限制为250 MB,我无法将其用于集成,现在尝试使用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

推荐答案

我假设您要使用API​​ Gateway + Lambda创建用于将作业请求提交到AWS Batch的终端节点.

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

为此,创建以下Lambda函数,该函数将作业提交到AWS Batch.用作业队列的arn替换"jobQueueArn".将Lambda函数与API网关集成.

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.

参数(dict)-传递给作业的其他参数将替换作业定义中设置的参数替换占位符.参数被指定为键和值对映射.SubmitJob请求中的参数会覆盖作业定义中的所有相应参数默认值.

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.

确保将正确的IAM策略附加到Lambda函数的角色.

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": [
                "*"
            ]
        }
    ]
}

这篇关于api网关与AWS Batch集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆