Amazon web services 如何从Lambda内部测试GET和POST调用

Amazon web services 如何从Lambda内部测试GET和POST调用,amazon-web-services,aws-lambda,Amazon Web Services,Aws Lambda,我正在学习Lambda,已经创建了一个每分钟触发一次Lambda的云观察指标。目前,Lambda函数正在正确执行。但我想在Lambda的内部打一个虚假的电话。如下所示: var https = require('https'); exports.handler = (event, context, callback) => { var params = { host: "example.com",

我正在学习Lambda,已经创建了一个每分钟触发一次Lambda的云观察指标。目前,Lambda函数正在正确执行。但我想在Lambda的内部打一个虚假的电话。如下所示:

var https = require('https');
       exports.handler = (event, context, callback) => {
       var params = {
                    host: "example.com",
                    path: "/api/v1/yourmethod"

                    };

  var req = https.request(params, function(res) {
    let data = '';
    console.log('STATUS: ' + res.statusCode);
    res.setEncoding('utf8');
    res.on('data', function(chunk) {
        data += chunk;
    });
    res.on('end', function() {
        console.log("DONE");
        console.log(JSON.parse(data));
    });
  });
   req.end();
 };

问题-由于AWS中没有托管任何GET和POST端点/代码,是否有任何方法可以测试Lambda内部的GET调用和POST调用是否正常工作?在AWS中是否有任何方法可以在AWS中组合一个伪端点或其他东西,并为测试目的对其进行REST调用

您可以使用JSONPlaceholder的API来测试对外部API的调用,
他们发布了用于测试和原型制作的假冒在线REST API
您可以测试调用不同的http方法调用,如
GET、PUT、POST、DELETE


如果您使用的是Lambda代理集成事件,则会包含许多有关请求的附加信息:


很酷的服务。我不知道。谢谢
{
  "message": "Hello me!",
  "input": {
    "resource": "/{proxy+}",
    "path": "/hello/world",
    "httpMethod": "POST",
    "headers": {
      "Accept": "*/*",
      "Accept-Encoding": "gzip, deflate",
      "cache-control": "no-cache",
      "CloudFront-Forwarded-Proto": "https",
      "CloudFront-Is-Desktop-Viewer": "true",
      "CloudFront-Is-Mobile-Viewer": "false",
      "CloudFront-Is-SmartTV-Viewer": "false",
      "CloudFront-Is-Tablet-Viewer": "false",
      "CloudFront-Viewer-Country": "US",
      "Content-Type": "application/json",
      "headerName": "headerValue",
      "Host": "gy415nuibc.execute-api.us-east-1.amazonaws.com",
      "Postman-Token": "9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f",
      "User-Agent": "PostmanRuntime/2.4.5",
      "Via": "1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)",
      "X-Amz-Cf-Id": "pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==",
      "X-Forwarded-For": "54.240.196.186, 54.182.214.83",
      "X-Forwarded-Port": "443",
      "X-Forwarded-Proto": "https"
    },
    "multiValueHeaders":{
      'Accept':[
        "*/*"
      ],
      'Accept-Encoding':[
        "gzip, deflate"
      ],
      'cache-control':[
        "no-cache"
      ],
      'CloudFront-Forwarded-Proto':[
        "https"
      ],
      'CloudFront-Is-Desktop-Viewer':[
        "true"
      ],
      'CloudFront-Is-Mobile-Viewer':[
        "false"
      ],
      'CloudFront-Is-SmartTV-Viewer':[
        "false"
      ],
      'CloudFront-Is-Tablet-Viewer':[
        "false"
      ],
      'CloudFront-Viewer-Country':[
        "US"
      ],
      '':[
        ""
      ],
      'Content-Type':[
        "application/json"
      ],
      'headerName':[
        "headerValue"
      ],
      'Host':[
        "gy415nuibc.execute-api.us-east-1.amazonaws.com"
      ],
      'Postman-Token':[
        "9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f"
      ],
      'User-Agent':[
        "PostmanRuntime/2.4.5"
      ],
      'Via':[
        "1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)"
      ],
      'X-Amz-Cf-Id':[
        "pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A=="
      ],
      'X-Forwarded-For':[
        "54.240.196.186, 54.182.214.83"
      ],
      'X-Forwarded-Port':[
        "443"
      ],
      'X-Forwarded-Proto':[
        "https"
      ]
    },
    "queryStringParameters": {
      "name": "me",
      "multivalueName": "me"
    },
    "multiValueQueryStringParameters":{
      "name":[
        "me"
      ],
      "multivalueName":[
        "you",
        "me"
      ]
    },
    "pathParameters": {
      "proxy": "hello/world"
    },
    "stageVariables": {
      "stageVariableName": "stageVariableValue"
    },
    "requestContext": {
      "accountId": "12345678912",
      "resourceId": "roq9wj",
      "stage": "testStage",
      "requestId": "deef4878-7910-11e6-8f14-25afc3e9ae33",
      "identity": {
        "cognitoIdentityPoolId": null,
        "accountId": null,
        "cognitoIdentityId": null,
        "caller": null,
        "apiKey": null,
        "sourceIp": "192.168.196.186",
        "cognitoAuthenticationType": null,
        "cognitoAuthenticationProvider": null,
        "userArn": null,
        "userAgent": "PostmanRuntime/2.4.5",
        "user": null
      },
      "resourcePath": "/{proxy+}",
      "httpMethod": "POST",
      "apiId": "gy415nuibc"
    },
    "body": "{\r\n\t\"a\": 1\r\n}",
    "isBase64Encoded": false
  }
}