当我运行我的节点应用程序时,我遇到了配置错误。错误信息如下:
这是在使用ejs和node的express服务器上运行。我正在使用Amazon JavaScript SDK。
我尝试了这里的解决方案:
编辑1:
如下所请求,我附上了完整的代码:
{ ConfigError: Missing region in config
at Request.VALIDATE_REGION (C:\Users\chris\Documents\AWS API
TEST\myapp\node_modules\aws-sdk\dist\aws-sdk-react-native.js:12027:47)
at Request.callListeners (C:\Users\chris\Documents\AWS API
TEST\myapp\node_modules\aws-sdk\dist\aws-sdk-react-native.js:11804:22)
at callNextListener (C:\Users\chris\Documents\AWS API
TEST\myapp\node_modules\aws-sdk\dist\aws-sdk-react-native.js:11794:14)
at C:\Users\chris\Documents\AWS API TEST\myapp\node_modules\aws-
sdk\dist\aws-sdk-react-native.js:12021:11
at finish (C:\Users\chris\Documents\AWS API TEST\myapp\node_modules\aws-
sdk\dist\aws-sdk-react-native.js:10842:9)
at Config.getCredentials (C:\Users\chris\Documents\AWS API
TEST\myapp\node_modules\aws-sdk\dist\aws-sdk-react-native.js:10887:9)
at Request.VALIDATE_CREDENTIALS (C:\Users\chris\Documents\AWS API
TEST\myapp\node_modules\aws-sdk\dist\aws-sdk-react-native.js:12016:28)
at Request.callListeners (C:\Users\chris\Documents\AWS API
TEST\myapp\node_modules\aws-sdk\dist\aws-sdk-react-native.js:11800:20)
at Request.emit (C:\Users\chris\Documents\AWS API
TEST\myapp\node_modules\aws-sdk\dist\aws-sdk-react-native.js:11776:12)
at Request.emit (C:\Users\chris\Documents\AWS API
TEST\myapp\node_modules\aws-sdk\dist\aws-sdk-react-native.js:13792:16)
message: 'Missing region in config',
code: 'ConfigError',
我拥有的代码是:
//Authenticate AWS:
var myCredentials = new AWS.CognitoIdentityCredentials({IdentityPoolId:'us-west-2a:"Identity Pool ID"'});
var myConfig = new AWS.Config({
credentials: myCredentials, region: 'us-west-2a'
});
这是在使用ejs和node的express服务器上运行。我正在使用Amazon JavaScript SDK。
我尝试了这里的解决方案:
但这并没有帮助。
编辑1:
如下所请求,我附上了完整的代码:
var express = require('express');
var AWS = require('aws-sdk');
var EC2 = require('aws-ec2')('access key', 'secret');
var scale = require('aws-scale');
var router = express.Router();
//Authenticate AWS:
var myCredentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId:'us-west-2:b0efe3c7-e4c9-420f-836b-6d776e2a9271'
});
var myConfig = new AWS.Config({
credentials: myCredentials, region: 'us-west-2'
});
AWS.config = myConfig
var minInst = 1;
var maxInst = 3;
var ec2 = new AWS.EC2();
//Set up parameters for EC2 Instances:
var params = {
ImageId: 'ami-6e1a0117',
MaxCount: minInst,
MinCount: maxInst,
InstanceInitiatedShutdownBehavior: 'terminate',
InstanceType: 't2.micro',
Monitoring: {
Enabled: true
},
NetworkInterfaces: [{
AssociatePublicIpAddress: true,
DeleteOnTermination: true,
}],
Placement: {
AvailabilityZone: 'us-west-2',
},
SecurityGroupIds: [
'sg-b0307ccd',
],
SecurityGroups: [
'CAB432Assignment2SG',
],
};
ec2.runInstances(params, function(err, data) {
if (err){
console.log(err, err.stack); //An error occurred
}
else{
console.log(data); //Successful Response
}
});