admin管理员组文章数量:1434217
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
1 Answer
Reset to default 2Access 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
版权声明:本文标题:javascript - Amazon AWS Error: Missing credentials in config node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745617240a2666473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论