admin管理员组

文章数量:1024582

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.

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.

本文标签: javascriptAmazon AWS Error Missing credentials in config nodejsStack Overflow