AWS S3 InvalidAccessKeyId Error Fix for Node.js

Setting up cloud storage for your application is almost essential for storing long-format information such as videos, high-definition photos, and other pieces of critical user information for your web application. Thankfully there are many resources out there that we can set up for free that allow us to do this in a simple way, particularly Amazon S3. However, you can run into the issue of setting this up properly with your Node application. Thus I will be discussing how to fix a particular bug:

InvalidAccessKeyId: The AWS Key Id you provided does not exist in our records.

I received this error after I set up my application correctly with the AWS-SDK. As you can see here I have a component that allows me to upload any document to my S3 bucket. 

However after trying to upload something I was hit with the above error, InvalidAccessKeyId. To fix this I took the following steps:

Step 1-) Reinstall aws-sdk in Node

It may be that your npm version is out of date, this can cause this error. Simple npm install once more.

  • npm install aws-sdk

Step 2-) Ensure the credentials are properly set from the shared credentials file

When the SDK for JS loads, it auto-searches the shared credentials file which is simply named "credentials". Depending on whether you are using Mac, Linux, or Windows, the paths for the credentials are shown here:

  • The shared credentials file on Linux, Unix, and macOS: ~/.aws/credentials
  • The shared credentials file on Windows: C:\Users\USER_NAME\.aws\credentials

If you do not have the file already you can simply create it in the above paths (do not use any other path). 

The contents of the file are supposed to resemble the above. However, you need to fill in your access key id and secret access key by simply editing the file. You need to generate these credentials if you do not have them. 

To generate the credentials:

  • Go to the Security Credentials page in your AWS account, which will be shown in the dropdown menu after clicking your email in the top-right.

Create an access key, make sure to save this, and keep it stored safely

Insert the corresponding information into your credentials file and save the file.

Conclusion:

It is as simple as that, you just have to re-install the npm package and ensure you have the proper keys in your credentials file. This will resolve many of the cases, however, do note there may be some edge cases where you will need to take other steps to solve the issue. Hope this helped someone, let me know what you think in the comments! Thanks for reading.

Create a free account to access full content.

All access to code and resources on ShillehTek.

Signup Now

Already a member? Sign In

Explore More on Our Blog

How to Use ADS1115 with the Raspberry Pi (Part 1)

How to Use ADS1115 with the Raspberry Pi (Part 1)

Discover how to expand your Raspberry Pi projects by integrating the ADS1115 ADC for precise analog signal reading....

How to Install Pip Packages in AWS Lambda Using Docker and ECR

How to Install Pip Packages in AWS Lambda Using Docker and ECR

Learn how to streamline AWS Lambda deployments by using Docker and Amazon Elastic Container Registry (ECR) to package...

Create Tabular Product Descriptions on Your Shopify Store

Create Tabular Product Descriptions on Your Shopify Store

Enhance your Shopify store's product pages with our comprehensive guide on implementing tabular descriptions. Learn how to add a...

SSH Into Raspberry Pi with Tailscale VPN

SSH Into Raspberry Pi with Tailscale VPN

Effortlessly access and manage your Raspberry Pi from anywhere using Tailscale's secure mesh VPN.

Send Email with Lua and the ESP32

Send Email with Lua and the ESP32

In this tutorial, we delve into sending emails with the ESP32-S3 using Lua, focusing on the Xedge IDE's built-in SMTP...

How to Code with Lua on ESP32 with XEdge32

How to Code with Lua on ESP32 with XEdge32

Learn how to set up Xedge32 and start coding on the ESP32-S3 with Lua programming!

Stream Audio From Raspberry Pi to Local Computer

Stream Audio From Raspberry Pi to Local Computer

Discover the simplicity of streaming live audio directly from a USB microphone connected to your Raspberry Pi to...

SSH Raspberry Pi via Cell Phone

SSH Raspberry Pi via Cell Phone

This beginner-friendly guide will walk you through remotely controlling your Raspberry Pi using SSH through your cell phone.

Remotely Control Raspberry Pi via SSH from External Network

Remotely Control Raspberry Pi via SSH from External Network

Learn how to SSH into your Raspberry Pi from any network. This is critical in IoT since you can control...

Stream Video from Raspberry Pi Camera to YouTube Live

Stream Video from Raspberry Pi Camera to YouTube Live

Learn how to stream to YouTube from a Raspberry Pi Camera.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.