【问题标题】:create request body and template API GATEWAY CDK创建请求正文和模板 API GATEWAY CDK
【发布时间】:2020-05-17 03:16:09
【问题描述】:

请告诉我两件事: 1.如何通过sdk配置请求体 2.如何配置模板,用于拉取pass或查询参数,转换为json,然后传递给lambda 这一切都在 api 网关中并通过 cdk

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-ec2 aws-lambda amazon-elastic-beanstalk


    【解决方案1】:

    假设您有以下设置

        const restapi = new apigateway.RestApi(this, "myapi", {
                // detail omit
        });
    
        const helloWorld = new lambda.Function(this, "hello", {
           runtime: lambda.Runtime..PYTHON_3_8,
           handler: 'index.handler',
           code: Code.asset('./index.py')
        })
    
        restapi.root.addResource("test").addMethod("POST", new apigateway.LambdaIntegration(helloWorld))
    

    在 lambda 函数内部(在 python 中)

    def handler(event, context):
      request_body = event['body']
      parameters = event[queryStringParameters]
    

    【讨论】:

      猜你喜欢
      • 2018-01-20
      • 2021-12-06
      • 1970-01-01
      • 2017-11-30
      • 1970-01-01
      • 2016-01-21
      • 2016-06-28
      • 2022-10-14
      • 2016-12-03
      相关资源
      最近更新 更多