Amazon web services AWS Lambda上的外部http请求存在问题

Amazon web services AWS Lambda上的外部http请求存在问题,amazon-web-services,http,aws-lambda,Amazon Web Services,Http,Aws Lambda,我正在使用DynamoDB表中存储的城市来调用外部天气API,以确定当天该城市是否会下雨。然后,它调用一个单独的Lambda,该Lambda使用该信息向SNS主题的订户发送消息,告知将下雨 const AWS = require('aws-sdk'); AWS.config.update({ region: 'eu-west-2' }); const lambda = new AWS.Lambda(); const axios = require('axios'); const tableNam

我正在使用DynamoDB表中存储的城市来调用外部天气API,以确定当天该城市是否会下雨。然后,它调用一个单独的Lambda,该Lambda使用该信息向SNS主题的订户发送消息,告知将下雨

const AWS = require('aws-sdk');
AWS.config.update({ region: 'eu-west-2' });
const lambda = new AWS.Lambda();
const axios = require('axios');
const tableName = process.env.CITY_TABLE;
const docClient = new AWS.DynamoDB.DocumentClient();
const publishMessageLambda = process.env.PUBLISH_MESSAGE_LAMBDA_NAME;
const weatherApiKey = process.env.WEATHER_API_KEY;

exports.handler = async (event) => {
  const scanParams = {
TableName: tableName,
AttributesToGet: ['city'],
};

try {
let citiesArr = await docClient.scan(scanParams).promise();

citiesArr.Items.forEach(async (cityObj) => {
  // console.log('cityObj', cityObj);
  // console.log('city', cityObj.city);
  // console.log('weatherApiKey:', weatherApiKey);
  let weatherReport = await axios({
    method: 'get',
    url: 'http://api.weatherapi.com/v1/forecast.json',
    params: {
      key: weatherApiKey,
      q: cityObj.city,
      days: 1,
    },
  });

  // console.log(weatherReport);

  let city = cityObj.city;

  let dailyChanceOfRain = Number(
    weatherReport.data.forecast.forecastday[0].day.daily_chance_of_rain
  );
  let totalPrecip =
    weatherReport.data.forecast.forecastday[0].day.totalprecip_mm;
  let lambdaParams = {
    FunctionName: publishMessageLambda,
    InvocationType: 'RequestResponse',
    Payload: JSON.stringify({
      body: { dailyChanceOfRain, totalPrecip, city },
    }),
  };
  console.log('dailyChanceOfRain: ', dailyChanceOfRain);
  console.log('totalPrecip: ', totalPrecip);
  if (dailyChanceOfRain > 50 && totalPrecip > 3) {
    let data = await lambda.invoke(lambdaParams).promise();
  }
  // console.log(
  //   'weatherReport: ',
  //   weatherReport.data.forecast.forecastday[0].day
  // );
});
} catch (error) {
console.log(error);
}
};
在本地运行该函数会在命令行上生成所需的日志,但是,在Lambda上运行该函数时,涉及外部http请求的日志不会显示在冷启动上,并且只有在多次调用该函数且通常不会同时调用该函数时,日志才会显示


任何建议都将不胜感激。

您是说冷启动失败,但随后的呼叫成功了吗?你能更详细地说明这意味着什么吗?“涉及的日志不会在第一次调用中显示,所有日志只在函数被多次调用后显示。”是的,很抱歉造成混淆。我的意思是,每当我使用无服务器框架部署函数时,部署后的第一次调用(即冷启动)不会生成任何所需的日志。这些日志只在以后的调用中出现在cloudWatch中,通常不会一起出现。@MarkB您能解释一下吗?它已经困扰了我好几天了。我会非常感激的。