我已下载并安装了node.js,现在使用我的AWS账户设置我的开发环境。下载AWS Javascript SDK看起来很好,但是我在使用它的凭据初始化我的帐户时遇到了问题。使用多种方法后,它可能需要使用命令行(终端)配置?任何建议将不胜感激!!
Macintosh-27:d3 Examples patrickreynolds$ npm install aws-sdk
npm http GET https://registry.npmjs.org/aws-sdk
npm http 304 https://registry.npmjs.org/aws-sdk
npm http GET https://registry.npmjs.org/xml2js/0.2.4
npm http GET https://registry.npmjs.org/xmlbuilder
npm http 304 https://registry.npmjs.org/xmlbuilder
npm http 304 https://registry.npmjs.org/xml2js/0.2.4
npm http GET https://registry.npmjs.org/sax
npm http 304 https://registry.npmjs.org/sax
aws-sdk@1.5.2 node_modules/aws-sdk
├── xmlbuilder@0.4.2
└── xml2js@0.2.4 (sax@0.5.5)
Macintosh-27:d3 Examples patrickreynolds$ AWS.config.loadFromPath('./config.json');
-bash: syntax error near unexpected token `'./config.json''
Macintosh-27:d3 Examples patrickreynolds$ var AWS = require('aws-sdk');
-bash: syntax error near unexpected token `('
Macintosh-27:d3 Examples patrickreynolds$
我的config.json文件保存在本地控制器以及安装AWS SDK后创建的/node_modules/aws-sdk/config.json目录中。 config.json中的格式如下:
{ "accessKeyId": "akid", "secretAccessKey": "secret", "region": "us-west-2" }
我所遵循的安装过程直接来自他们提供的Amazon Web Services Javascript文档页面:http://aws.amazon.com/sdkfornodejs/
答案 0 :(得分:3)
看起来你试图直接在bash shell中运行它。您需要在节点repl中尝试此操作或编写一个小节点应用程序。
编写一个如下所示的快速test.js
文件并将其放在项目的根目录中:
var AWS = require('aws-sdk');
var util = require('util');
AWS.config.loadFromPath('./config.json');
console.log(util.inspect(AWS.config));
然后使用node:
运行它node test.js