Encountered an issue with AWS S3: unable to retrieve the certificate from the local issuer

After completing my Protractor test suite execution, I am encountering an error while trying to upload my HTML result file to AWS S3 using JavaScript in my automation script. Can someone assist me in resolving this issue?

  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: 'my.bucket',
      Key: 'automation_report.html',
      Body: fileStream,
      ContentType: "text/html",
      ContentMD5: hash,
      ACL: 'public-read',
    };

    const s3 = new AWS.S3({
      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);
      }
    });
  }

Error: unable to get local issuer certificate at TLSSocket.onConnectSecure (_tls_wrap.js:1049:34) at TLSSocket.emit (events.js:182:13) at TLSSocket.EventEmitter.emit (domain.js:442:20) at TLSSocket._finishInit (_tls_wrap.js:631:8)

Answer №1

I managed to get it working by adding the certificate in AWS.Config. Below is the complete code that worked for me. Hopefully, this will be useful for someone else facing a similar issue. Please note that the credentials and URLs mentioned below are just placeholders and not real:

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

AWS.config.update({
  httpOptions: {
    agent: new https.Agent({
      // rejectUnauthorized: false, // Avoid using this as it is insecure, similar to --no-verify-ssl in AWS CLI
      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);

// Use S3 to upload the file to the 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 the file
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);
  }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for locating the ID of an object in an array when only one attribute in the "child" array is known

Seeking assistance in creating a JavaScript function that efficiently determines the id of the "parent" object based on the code of a "child" object from the dataArray. For example: getIdParent("240#code") -> should return "1" [ { id: 0, ...

Images are not being shown by Glide JS

I have implemented the Glide JS carousel within a VueJS project to showcase multiple images, however, I am encountering an issue where only the first image is being displayed. The <img/> tag has the correct src URL for all three images, but only th ...

Issue: unable to establish a connection to [localhost:27017]

Upon executing node app.js, an error message is displayed: Failed to load c++ bson extension, using pure JS version Express server listening on port 3000 events.js:85 throw er; // Unhandled 'error' event ^ Error: failed to conn ...

What are some methods for resolving the problem of CORS policy blocking access to retrieve data from Yahoo Finance?

Currently, I am attempting to retrieve the price of a stock within my pure React App by utilizing fetch. When I try to fetch without any options or configurations, using fetch(url), I encounter the following error: Access to fetch at 'https://quer ...

What is the best way to align a box once another one has been placed?

I have integrated both Bootstrap and Masonry plugins into my website design. The issue I am facing is that the Masonry plugin box goes under the top Bootstrap bar. I tried adding a margin-top: 50, but this resulted in a horizontal scroll bar appearing. To ...

Synchronize JSON data with the Document Object Model (DOM

My current project is built using React, where I am rendering the page dynamically based on JSON data. The page consists of various component types, ranging from images to text content. Each component includes a delete option, allowing users to change im ...

PHP move_uploaded_file() function encountering an issue

As a newcomer to PHP, I am exploring the move_uploaded_file() function. I initiate an HTTP POST request from JavaScript/jQuery to a PHP file hosted on a Microsoft Azure server. The request includes an audio blob like so... mediaRecorder.ondataavailab ...

Enhance with Laravel combined with AngularJS

I've encountered some issues with the "edit" part while working on a Laravel + AngularJS CRUD application. An internal server error is being displayed, and I'm seeking assistance to understand its cause. Error "GET localhost/crudtcc/public/ap ...

Is it possible to display the content below the row of the clicked element when it is selected?

I am currently working on building a team page similar to the layout at My goal is to create a row of elements that float or display inline, with hidden content revealed beneath each selected element, pushing subsequent rows further down. Unfortunately, m ...

Is it possible to transfer the reactivity of a Vue ref to another ref while reassigning it?

Below is a simplified version of my Vue component: <template> <div @click="loadEvents">{{ loading }}</div> </template> <script setup> import { ref } from 'vue' let loading = ref(false) loadEvents() func ...

The size of my React Native app is significantly larger than expected once installed

I recently developed a React Native app, and while the release APK size is only 28 MBs, I was shocked to see that the storage size is a whopping 62 MBs. I am desperately looking for a solution as I need to deliver this project soon. Please help me resolv ...

What are the steps to start up a NodeJS API using an Angular app.js file?

Currently, I am following various online tutorials to develop a web application using the MEAN stack and utilizing a RESTful API. I have encountered some challenges in integrating both the API server and Angular routes. In my project, I have a server.js f ...

How to remove the horizontal scrollbar from material-ui's Drawer element

My drawer is displaying a horizontal scroll, despite my efforts to prevent it. I've tried adjusting the max-width and width settings in Menu and MenuItems, as well as using box-sizing: border-box. I also attempted setting overflow: hidden on the Drawe ...

Creating a CSS animation to repeat at regular intervals of time

Currently, I am animating an SVG element like this: .r1 { transform-box: fill-box; transform-origin: 50% 50%; animation-name: simpleRotation,xRotation; animation-delay: 0s, 2s; animation-duration: 2s; animation-iterat ...

How can I efficiently make multiple API calls using redux-thunk?

This is the approach I took. const redux = require('redux') const thunkMiddleware = require('redux-thunk').default const axios = require('axios') const reduxLogger = require('redux-logger') const createStore = redu ...

Implementing real-time time updates using php ajax technology

It's fascinating how websites can update the time dynamically without using ajax requests. I currently have a comment system in place. $('#comment').click(function(){ $.post(url,{ comment : $(this).siblings('textarea.#commen ...

Expanding the capabilities of jQuery UI event handling

I am looking for a way to enhance dialog functionality by automatically destroying it when closed, without the need to add additional code to each dialog call in my current project. My idea is to override the default dialog close event. After researching ...

Exploring MongoDB's Aggregation Framework: Finding the Mean

Is there a way to use the Aggregation Framework in MongoDB to calculate the average price for a specific Model within a given date range? Model var PriceSchema = new Schema({ price: { type: Number, required: true }, date: { ...

Utilizing JavaScript to iterate through objects retrieved via Ajax calls

Recently, I've been diving into the world of Javascript and delving deep into AJAX. Utilizing Vanilla JS along with simple AJAX, my current task involves fetching a user object from a URL based on the user's input ID. Despite attempting to use .d ...

Assigning a variable in jQuery to a PHP variable that has not been defined can halt the script

Here is the code snippet for a document ready function: $(document).ready(function(){ var id = <?php echo "" ?>; alert('boo'); if(id!=0){ $(' ...