简体   繁体   中英

Initializing and configuring AWS with Node.js

I have downloaded and installed node.js, and now setting up my development environment with my AWS account. Downloading the AWS Javascript SDK looks fine, but I am having a problem initializing my account with it's credentials. After using numerous approaches, it might have to do something with a command line (terminal) configuration? Any suggestions would be appreciated!!

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$ 



My config.json file is saved in both the local director as well as the /node_modules/aws-sdk/config.json directory that is made after installing the AWS SDK. The format in the config.json is as follows:

{ "accessKeyId": "akid", "secretAccessKey": "secret", "region": "us-west-2" }


The installation process I am following is straight from the Amazon Web Services Javascript documentation page they provide: http://aws.amazon.com/sdkfornodejs/

Looks like you are attempting to run this directly in a bash shell. You need to either try this in the node repl or write a small node app.

Write a quick test.js file that looks like this and place it in the root of your project:

var AWS = require('aws-sdk');
var util = require('util');

AWS.config.loadFromPath('./config.json');
console.log(util.inspect(AWS.config));

Then run it with node:

node test.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM