最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Amazon AWS Error: Missing credentials in config node.js - Stack Overflow

matteradmin4PV0评论

I am just getting started using AWS and I'm trying to use their example code here. I am using dotenv to store my keys as environmental variables. Using coffee script my code looks like this:

require('dotenv').config()

express = require 'express'
router = express.Router()

AWS = require('aws-sdk')
AWS.config.region = 'us-west-2'

s3bucket = new (AWS.S3)(params: Bucket: 'new-bucket-name')

s3bucket.createBucket ->
  params = 
    Key: process.env.AWS_ACCESS_KEY_ID
    Body: 'Hello!'
  s3bucket.upload params, (err, data) ->
    if err
      console.log 'Error uploading data: ', err
    else
      console.log 'Successfully uploaded data to myBucket/myKey'
    return
  return

But I keep getting the following error:

message: 'Missing credentials in config',
  code: 'CredentialsError',
  errno: 'EHOSTDOWN',
  syscall: 'connect',
  address: '169.254.169.254',
  port: 80,
  time: 2016-10-13T14:14:03.605Z,
  originalError: 
   { message: 'Could not load credentials from any providers',
     code: 'CredentialsError',
     errno: 'EHOSTDOWN',
     syscall: 'connect',
     address: '169.254.169.254',
     port: 80,
     time: 2016-10-13T14:14:03.605Z,
     originalError: 
      { message: 'Missing credentials in config',
        code: 'CredentialsError',
        errno: 'EHOSTDOWN',
        syscall: 'connect',
        address: '169.254.169.254',
        port: 80,
        time: 2016-10-13T14:14:03.599Z,
        originalError: [Object] } } }

How do I fix this, do I also need to send my secret key somehow?

UPDATE: fixed it using

AWS.config = new AWS.Config();
AWS.config.accessKeyId = "accessKey";
AWS.config.secretAccessKey = "secretKey";

but now I am getting this new error:

  message: 'Access Denied',
  code: 'AccessDenied',
  region: null,
  time: 2016-10-13T14:38:19.651Z,
  requestId: '958BD7EA261F2DCA',
  extendedRequestId: 'xuBSmGL/GC5Tx1osMh9tBFIwXMLy15VtJXniwYVGutTcoBJgrCeOLZpQMlliF1Azrkmj1tsAX7o=',
  cfId: undefined,
  statusCode: 403,
  retryable: false,
  retryDelay: 11.225715031927086 }

I am just getting started using AWS and I'm trying to use their example code here. I am using dotenv to store my keys as environmental variables. Using coffee script my code looks like this:

require('dotenv').config()

express = require 'express'
router = express.Router()

AWS = require('aws-sdk')
AWS.config.region = 'us-west-2'

s3bucket = new (AWS.S3)(params: Bucket: 'new-bucket-name')

s3bucket.createBucket ->
  params = 
    Key: process.env.AWS_ACCESS_KEY_ID
    Body: 'Hello!'
  s3bucket.upload params, (err, data) ->
    if err
      console.log 'Error uploading data: ', err
    else
      console.log 'Successfully uploaded data to myBucket/myKey'
    return
  return

But I keep getting the following error:

message: 'Missing credentials in config',
  code: 'CredentialsError',
  errno: 'EHOSTDOWN',
  syscall: 'connect',
  address: '169.254.169.254',
  port: 80,
  time: 2016-10-13T14:14:03.605Z,
  originalError: 
   { message: 'Could not load credentials from any providers',
     code: 'CredentialsError',
     errno: 'EHOSTDOWN',
     syscall: 'connect',
     address: '169.254.169.254',
     port: 80,
     time: 2016-10-13T14:14:03.605Z,
     originalError: 
      { message: 'Missing credentials in config',
        code: 'CredentialsError',
        errno: 'EHOSTDOWN',
        syscall: 'connect',
        address: '169.254.169.254',
        port: 80,
        time: 2016-10-13T14:14:03.599Z,
        originalError: [Object] } } }

How do I fix this, do I also need to send my secret key somehow?

UPDATE: fixed it using

AWS.config = new AWS.Config();
AWS.config.accessKeyId = "accessKey";
AWS.config.secretAccessKey = "secretKey";

but now I am getting this new error:

  message: 'Access Denied',
  code: 'AccessDenied',
  region: null,
  time: 2016-10-13T14:38:19.651Z,
  requestId: '958BD7EA261F2DCA',
  extendedRequestId: 'xuBSmGL/GC5Tx1osMh9tBFIwXMLy15VtJXniwYVGutTcoBJgrCeOLZpQMlliF1Azrkmj1tsAX7o=',
  cfId: undefined,
  statusCode: 403,
  retryable: false,
  retryDelay: 11.225715031927086 }
Share Improve this question edited Oct 13, 2016 at 14:37 jmona789 asked Oct 13, 2016 at 14:31 jmona789jmona789 2,8497 gold badges26 silver badges61 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

Access Denied sounds like your IAM Permissions are not setup correctly. Check that user tied to those credentials can create buckets in your account.

Also usually the AWS SDKs can read out of your actual ENV variables so you probably do not need to use DotEnv in this case. And when you push code to production systems that might be running on EC2 or Lambda you should really be using a IAM Profile which handles the credentials for you. So again.. DotEnv isn't necessary.

Post a comment

comment list (0)

  1. No comments so far