0

I'm trying to store images from my Node.js Backend to an AWS S3 Bucket. The app is hosted on heroku. This works perfectly fine in my local environment but once I deploy the app to heroku with gitlab CI/CD, I get the following error:

Missing credentials in config, if using AWS_CONFIG_FILE, set 
AWS_SDK_LOAD_CONFIG=1","errno":"ECONNREFUSED","code":"CredentialsError","syscall":"connect"

On my local environment I store the API Keys in an .env file like this:

BUCKET_NAME=XYZ
AWS_KEY_ID=XYZ
AWS_ACCESS_KEY=XYZ

and my Node server gets the variables like this:

const s3 = new AWS.S3({
 accessKeyId: process.env.AWS_KEY_ID,
 secretAccessKey: process.env.AWS_ACCESS_KEY
});
const BUCKET_NAME = process.env.BUCKET_NAME

This works in my local environment. On Gitlab, I store the same variables with the exact same names enter image description here

but I get the above error when I try to store a file.

ping pong
  • 225
  • 6
  • 16
  • Does this answer your question? [AWS Missing credentials when i try send something to my S3 Bucket (Node.js)](https://stackoverflow.com/questions/26284181/aws-missing-credentials-when-i-try-send-something-to-my-s3-bucket-node-js) maybe this one too https://stackoverflow.com/questions/61028751/missing-credentials-in-config-if-using-aws-config-file-set-aws-sdk-load-config – Ersoy Jun 04 '20 at 10:57
  • 1
    I'll try renaming the variables as suggested, maybe this solves it – ping pong Jun 04 '20 at 13:27

1 Answers1

0

The env vars need to be present on your Heroku instance.

Maxim Orlov
  • 1,942
  • 15
  • 18
  • I have ENV vars for my Database connection as well, and they are defined in gitlab and work well on heroku.. Why would the AWS vars don't work the same way? – ping pong Jun 04 '20 at 13:27
  • I'm not sure why it works for your DB. Your server runs on Heroku therefore it's Heroku that makes the env vars available to Node.js, not Gitlab. – Maxim Orlov Jun 04 '20 at 13:29
  • 1
    Thanks, that worked (heroku config:set GITHUB_USERNAME=joesmith from heroku doku) – ping pong Jun 04 '20 at 17:45