• AWS lambda 与API gateway 集成时,参数(mapping)的传递方式


    一、非代理lambda(自定义lambda) 需要自己构建映射

    eg:

    {
    
    "city": "$input.params('city')",
    
    "time": "$input.params('time')",
    
    "day": "$input.params('day')",
    
    "name": "$inputRoot.callerName"
    
    }
    

      

    https://oq7all40u3.execute-api.cn-north-1.amazonaws.com.cn/test/test?time=123456

    event 会收到您传递的数据

    {

    "time": "123456"

    }

    二、代理集成lambda

    在 Lambda 代理集成中,当客户端提交 API 请求时,API Gateway 会按原样将原始请求传递给集成的 Lambda 函数,但不会保留请求参数的顺序。

    eg: https://oq7all40u3.execute-api.cn-north-1.amazonaws.com.cn/test/test?time=123456

    Lambda event收到的数据

    {
    
    "resource": "/test",
    
    "path": "/test",
    
    "httpMethod": "GET",
    
    "headers": {
    
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
    
    "accept-encoding": "gzip, deflate, br",
    
    "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5,zh-TW;q=0.4",
    
    "Host": "oq7all40u3.execute-api.cn-north-1.amazonaws.com.cn",
    
    "sec-fetch-mode": "navigate",
    
    "sec-fetch-site": "none",
    
    "sec-fetch-user": "?1",
    
    "upgrade-insecure-requests": "1",
    
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
    
    "X-Amzn-Trace-Id": "Root=1-5d8d8250-1f8874904764cbb8b777e598",
    
    "X-Forwarded-For": "119.254.228.2",
    
    "X-Forwarded-Port": "443",
    
    "X-Forwarded-Proto": "https"
    
    },
    
    "multiValueHeaders": {
    
    "accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"],
    
    "accept-encoding": ["gzip, deflate, br"],
    
    "accept-language": ["zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5,zh-TW;q=0.4"],
    
    "Host": ["oq7all40u3.execute-api.cn-north-1.amazonaws.com.cn"],
    
    "sec-fetch-mode": ["navigate"],
    
    "sec-fetch-site": ["none"],
    
    "sec-fetch-user": ["?1"],
    
    "upgrade-insecure-requests": ["1"],
    
    "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"],
    
    "X-Amzn-Trace-Id": ["Root=1-5d8d8250-1f8874904764cbb8b777e598"],
    
    "X-Forwarded-For": ["119.254.228.2"],
    
    "X-Forwarded-Port": ["443"],
    
    "X-Forwarded-Proto": ["https"]
    
    },
    
    "queryStringParameters": {
    
    "time": "123456"
    
    },
    
    "multiValueQueryStringParameters": {
    
    "time": ["123456"]
    
    },
    
    "pathParameters": null,
    
    "stageVariables": null,
    
    "requestContext": {
    
    "resourceId": "e837yf",
    
    "resourcePath": "/test",
    
    "httpMethod": "GET",
    
    "extendedRequestId": "AqFMnH2NBTIFXSQ=",
    
    "requestTime": "27/Sep/2019:03:30:24 +0000",
    
    "path": "/test/test",
    
    "accountId": "936669166135",
    
    "protocol": "HTTP/1.1",
    
    "stage": "test",
    
    "domainPrefix": "oq7all40u3",
    
    "requestTimeEpoch": 1569555024662,
    
    "requestId": "dc58012d-438c-4298-bc8d-75dd4bee8562",
    
    "identity": {
    
    "cognitoIdentityPoolId": null,
    
    "accountId": null,
    
    "cognitoIdentityId": null,
    
    "caller": null,
    
    "sourceIp": "119.254.228.2",
    
    "principalOrgId": null,
    
    "accessKey": null,
    
    "cognitoAuthenticationType": null,
    
    "cognitoAuthenticationProvider": null,
    
    "userArn": null,
    
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
    
    "user": null
    
    },
    
    "domainName": "oq7all40u3.execute-api.cn-north-1.amazonaws.com.cn",
    
    "apiId": "oq7all40u3"
    
    },
    
    "body": null,
    
    "isBase64Encoded": false
    
    }
    

      

    三、参数格式为路径参数

    eg:传入参数123456 方式

    https://oq7all40u3.execute-api.cn-north-1.amazonaws.com.cn/test/test/123456

    需要使用代理资源{proxy+}

  • 相关阅读:
    C++11新特性
    Qt操作xml
    指针和引用的区别
    QT软件主题切换
    常见的临时变量的生成场景
    QQuickWidget+QML设置背景透明
    idea maven Could not transfer artifact
    Java项目启动时执行指定方法的几种方式
    解决bootstrap-table在切换分页后再次查询报错404问题
    bootstrap:表单必填项*标识,及提交前校验
  • 原文地址:https://www.cnblogs.com/heitaoq/p/11862987.html
Copyright © 2020-2023  润新知