AWS S3-错误:无法获取本地发行者证书

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AWS S3-错误:无法获取本地发行者证书相关的知识,希望对你有一定的参考价值。

我在完成Protractor测试套件执行后,尝试将html结果文件上传到AWS S3。我在自动化中使用javascript。请在这里帮助我解决错误:

  static uploadtoS3() {
    const AWS = require('aws-sdk');
    var FILE_NAME_LOCAL;
    var crypt = require("crypto");

    fs.readdirSync("./reports/html/").forEach(file => {
      if (file.startsWith("execution_report")) {
        FILE_NAME_LOCAL = process.cwd() + "\reports\html\" + file;
      }
    });
    console.log("File name: " + FILE_NAME_LOCAL);
    // Get file stream
    const fileStream = fs.createReadStream(FILE_NAME_LOCAL);

    var hash = crypt.createHash("md5")
      .update(new Buffer.from(FILE_NAME_LOCAL, 'binary'))
      .digest("base64");
    console.log("Hash: "+hash);
    // Call S3 to retrieve upload file to specified bucket
    const uploadParams = {
      Bucket: 'cosyn.dev',
      Key: 'automation_report.html',
      Body: fileStream,
      ContentType: "text/html",
      ContentMD5: hash,
      // CacheControl: "max-age=0,no-cache,no-store,must-revalidate",
      ACL: 'public-read',
    };

    const s3 = new AWS.S3({
      // TODO: use this `accessKeyId: <key>` annotation to indicate the presence of a key instead of placing the actual key here. 
      endpoint: "https://3site-abc-wip1.nam.nsroot.net",
      accessKeyId: <access_key_id>,
      secretAccessKey: <secret_access_key>,
      signatureVersion: 'v4',
      ca: fs.readFileSync('C:\Users\AB11111\InternalCAChain_PROD.pem'),
      sslEnabled: true
    });
    // Create S3 service object and upload
    s3.upload(uploadParams, function (err, data) {
      console.log("Inside upload..");
      if (err) {
        throw err;
      } if (data) {
        console.log('Upload Success. File location:' + data.Location);
      }
    });
  }

错误:无法在以下位置获取本地颁发者证书TLSSocket.emit上的TLSSocket.onConnectSecure(_tls_wrap.js:1049:34)(events.js:182:13)位于TLSSocket.EventEmitter.emit(domain.js:442:20)在TLSSocket._finishInit(_tls_wrap.js:631:8)

答案

我成功了。我需要在AWS.Config中添加证书。完整的工作代码如下。这可能会帮助某人。注意:以下凭据和网址不是真实的:

const AWS = require('aws-sdk');
const https = require('https');
var FILE_NAME_LOCAL;

AWS.config.update({
  httpOptions: {
    agent: new https.Agent({
      rejectUnauthorized: false,
      ca: fs.readFileSync('./support/InternalCAChain_PROD.pem')
    })
  }
});

const s3 = new AWS.S3({
  s3BucketEndpoint: true,
  endpoint: "https://my.bucket.3site-abc.nam.nsroot.net/",
  accessKeyId: "abABcdCD",
  secretAccessKey: "kjlJLlklkLlUYt",
});

// Get file stream
fs.readdirSync("./reports/html/").forEach(file => {
  if (file.startsWith("execution_report")) {
    FILE_NAME_LOCAL = process.cwd() + "\reports\html\" + file;
  }
});
const fileStream = fs.readFileSync(FILE_NAME_LOCAL);

// Call S3 to retrieve upload file to specified bucket
const uploadParams = {
  Bucket: 'my.bucket',
  Key: path.basename(FILE_NAME_LOCAL),
  Body: fileStream,
  ContentType: "text/html",
  ContentEncoding: 'UTF-8',
  ACL: 'public-read',
};

// Create S3 service object and upload
s3.upload(uploadParams, function (err, data) {
  console.log("Inside upload..");
  if (err) {
    throw err;
  } if (data) {
    s3FileLocation = data.Location;
    console.log('Upload Success. File location:' + data.Location);
  }
});

以上是关于AWS S3-错误:无法获取本地发行者证书的主要内容,如果未能解决你的问题,请参考以下文章

Guzzle Curl 错误 60 SSL 无法获取本地发行者

AWS HTTP错误:cURL错误60:无法使用gi证书对对等证书进行身份验证

AWS CLI S3:使用终端在本地复制文件:致命错误:调用 HeadObject 操作时发生错误(404)

我应该为 elb 和 aws S3 设置两个不同的 Cloudfront 发行版吗?

获取对象时发生 AWS S3 错误。 S3 错误代码:带有 Terraform 的 NoSuchKey

无法识别本地发行人