This is what my code looks like:
'use strict'; process.env.AWS_PROFILE // Load the AWS SDK for Node.js const AWS = require('aws-sdk'); // Create EC2 service object var ec2 = new AWS.EC2({apiVersion: '2016-11-15'}); // Load credentials and set region from JSON file AWS.config.loadFromPath('/Users/testuser/.aws/credentials'); // Load in security group parameters const securityParams = require('./securityParams.json'); module.exports = { //Exports creation of Security Groups CreateSecurityGroup: (req, res) => { ec2.createSecurityGroup(securityParams, function(err, data) { if (err) { return (console.log("Error", err)); } // Pass the Json as a parameter in this function ec2.authorizeSecurityGroupIngress(securityParams, 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, function(err, data) { if (err) { res.serverError(err, err.stack); } else { res.ok(data); console.log('Egress Security Rules Created'); } }) }) } } I'm trying to have the script load configurations from two files; one aws credentials file, and one json. However its throwing errors on the credentials file which looks like this:
[default] aws_access_key_id=************** aws_secret_access_key************** I'm not sure what I'm missing to get it to read the properties in correctly.
Here is the error I'm seeing:
undefined:1 [default] ^ SyntaxError: Unexpected token d in JSON at position 1 at JSON.parse (<anonymous>)
securityParams.jsoncontains JSON -- which you're treating as though it were JavaScript code viarequire-- but not the credentials).