部署后,AWS Elastic beantalk Express服务502 Bad Gateway

时间:2020-07-29 23:37:32

标签: node.js amazon-web-services express amazon-elastic-beanstalk aws-codestar

我使用aws cloud9进行开发,并使用codestar进行部署。 该服务在本地运行良好,部署后有一种发布方法提示我502错误。

server.js中的方法:

app.post('/upload', async function(req, res) {
  const url = "https://m.media-amazon.com/images/M/MV5BMjIxMjgxNTk0MF5BMl5BanBnXkFtZTgwNjIyOTg2MDE@._V1_UX182_CR0,0,182,268_AL_.jpg";
  const id = "tt0993846";
  const stream = request(url).pipe(fs.createWriteStream(`images/${id}.jpg`));

  const putObjectWrapper = (params) => {
    return new Promise((resolve, reject) => {
      const s3 = new AWS.S3({ params: { Bucket: 'my-upload-bucket-idan', Key: id+'.jpg' } })
      s3.putObject(params, function (err, result) {
        if(err) reject(err);
        if(result) resolve(result);
      });
    })
  }

  const store = async function() {
    try {
      const data_stream = fs.createReadStream(`images/${id}.jpg`);
      const s3 = new AWS.S3({ params: { Bucket: 'my-upload-bucket-idan', Key: id+'.jpg' } });
      const request = s3.putObject({Body: data_stream});
      const result = await request.promise();
      handleSuccess(result.ETag, res);
    } catch (err) {
      console.log(err);
      handleError(err, res);
    }
  }
  
  stream.on('close', () => {
  store();
});
});

错误:

<html>
<head>
    <title>502 Bad Gateway</title>
</head>

<body>
    <center>
        <h1>502 Bad Gateway</h1>
    </center>
    <hr>
    <center>nginx/1.16.1</center>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

我修复了它。问题是我的服务器上没有“ images”文件夹。不知道为什么它给了我502。