首页 > 解决方案 > 如何在使用 boto3 创建 api-gateway 时添加命令“使用 Lambda 代理集成”

问题描述

我正在使用 boto3 在 aws 中为我的 lambda 函数创建一个 api。那么如何在为该 api 创建资源时添加具有 lambda 代理集成的选项。

我正在使用 put_method 为我的 api 及其方法类型创建资源

api_client.put_method(restApiId=api_id,
                              resourceId=name_api_id,
                              httpMethod='ANY',
                              authorizationType='NONE')

标签: python-3.xamazon-web-servicesaws-lambdaaws-api-gatewayboto3

解决方案


对于 aws lambda 集成,请改用 put_integration。

您应该在下面指定您的字符串,请记住,对于 lambda 代理集成,您应该指定

type='AWS_PROXY'
integrationHttpMethod='POST'
uri = lambda url 

这是整个

response = client.put_integration(
    restApiId='string',
    resourceId='string',
    httpMethod='string',
    type='HTTP'|'AWS'|'MOCK'|'HTTP_PROXY'|'AWS_PROXY',
    integrationHttpMethod='string',
    uri='string',
    connectionType='INTERNET'|'VPC_LINK',
    connectionId='string',
    credentials='string',
    requestParameters={
        'string': 'string'
    },
    requestTemplates={
        'string': 'string'
    },
    passthroughBehavior='string',
    cacheNamespace='string',
    cacheKeyParameters=[
        'string',
    ],
    contentHandling='CONVERT_TO_BINARY'|'CONVERT_TO_TEXT',
    timeoutInMillis=123
)

推荐阅读