我有一个JSON文件,我正在调用一个文件:
{
"SecurityGroups": [
{
"IpPermissionsEgress": [],
"Description": "My security group",
"IpPermissions": [
{
"PrefixListIds": [],
"FromPort": 22,
"IpRanges": [
{
"CidrIp": "203.0.113.0/24"
}
],
"ToPort": 22,
"IpProtocol": "tcp",
"UserIdGroupPairs": []
}
],
"GroupName": "MySecurityGroup",
"VPCId": "123456789012",
"GroupId": "sg-903004f8",
}
]
}
我的JSON文件如下所示:
SyntaxError: /Users/testuser/Documents/testsecuritygroups.json: Unexpected token } in JSON at position 696
at JSON.parse (<anonymous>)
at Object.Module._extensions..json (module.js:588:27)
错误组名称和描述显然在那里。不知道为什么我会收到这些错误。这就是我的代码:
'use strict';
process.env.AWS_PROFILE
var PropertiesReader = require('properties-reader');
var AWS = require('aws-sdk')
var properties = PropertiesReader('/Users/testuser/.aws/credentials');
AWS.config.update({
accessKeyId : properties.get('aws_access_key_id'),
secretAccessKey : properties.get('aws_secret_access_key'),
region : 'us-east-1'
})
var ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
// Load credentials and set region from JSON file
// Load in security group parameters
let securityParams = require('./securityParams.json');
let securityParamsJSON = JSON.stringify(securityParams);
module.exports = {
//Exports creation of Security Groups
createSecurityGroup: (req, res) => {
ec2.createSecurityGroup(securityParams[0].SecurityGroups[0], function(err, data) {
if (err) {
return (console.log("Error", err));
}
// Pass the Json as a parameter in this function
ec2.authorizeSecurityGroupIngress(securityParams.IpPermissions, function(err, data) {
if (err) {
res.serverError(err, err.stack);
} else {
res.ok(data);
console.log('Ingress Security Rules Created');
}
})
// Pass the Json as a parameter in this function
ec2.authorizeSecurityGroupEgress(securityParams.IpPermissionsEgress[0], function(err, data) {
if (err) {
res.serverError(err, err.stack);
} else {
res.ok(data);
console.log('Egress Security Rules Created');
}
})
})
}
}
module.exports.createSecurityGroup();
我只是想通过这个脚本在AWS中创建安全组。