Skip to content

Commit e0656ae

Browse files
authored
Integration with Neptune Analytics (#31)
Added support for integration with Neptune Analytics via SDK or http: added new dependency on client-neptune-graph added logic to fall back to neptune graph SDK if Axios request fails during pipeline creation (previous logic threw Error as the analytics SDK was not yet available) created new lambda template which is used if the user specifies --output-resolver-query-sdk option set additional lambda environment variable for neptune db name which is required to execute queries using the neptune graph SDK fixed function which retrieves graph summary to use neptune graph SDK if the neptune-type is neptune-graph (the summary endpoint path for neptune-db is not the same for neptune-graph) fixed CDK pipeline to only fetch cluster info if the type is neptune-db as it is not required for neptune-graph (analytics) set isNeptuneIAMAuth to true if the neptune type is detected as neptune-graph introduced util.js for parsing functions that are used across multiple modules refactored function which had many params to use an object param instead for better readability introduced new test case 7 which sets --output-resolver-query-sdk option
1 parent 5380603 commit e0656ae

24 files changed

+5698
-278
lines changed

.gitignore

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
output/**
21
package-lock.json
32
.vscode/launch.json
4-
node_modules/**
5-
templates/Lambda4AppSyncHTTP/node_modules/**
6-
templates/Lambda4AppSyncSDK/node_modules/**
3+
**/node_modules/
74
coverage/**
8-
test/node_modules/**
9-
test/TestCases/Case01/output/**
10-
test/TestCases/Case01/output/**
11-
test/TestCases/Case02/output/**
12-
test/TestCases/Case03/output/**
13-
test/TestCases/Case04/output/**
14-
test/TestCases/Case05/output/**
15-
test/TestCases/Case06/output/**
5+
**/output/
166
*.iml

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aws/neptune-for-graphql",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "CLI utility to create and maintain a GraphQL API for Amazon Neptune",
55
"keywords": [
66
"Amazon Neptune",
@@ -19,9 +19,10 @@
1919
"test": "test"
2020
},
2121
"scripts": {
22-
"postinstall": "cd templates/Lambda4AppSyncHTTP && npm install && cd ../Lambda4AppSyncSDK && npm install",
22+
"postinstall": "cd templates/Lambda4AppSyncHTTP && npm install && cd ../Lambda4AppSyncSDK && npm install && cd ../Lambda4AppSyncGraphSDK && npm install",
2323
"lint": "eslint neptune-for-graphql.mjs ./src",
2424
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js",
25+
"test:sdk": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js --testPathPattern=test/TestCases/Case07",
2526
"test:resolver": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js --testPathPattern=test/TestCases/Case01"
2627
},
2728
"jest": {
@@ -42,6 +43,8 @@
4243
"./templates/Lambda4AppSyncHTTP/package.json",
4344
"./templates/Lambda4AppSyncSDK/index.mjs",
4445
"./templates/Lambda4AppSyncSDK/package.json",
46+
"./templates/Lambda4AppSyncGraphSDK/index.mjs",
47+
"./templates/Lambda4AppSyncGraphSDK/package.json",
4548
"./src/**"
4649
],
4750
"author": "AWS",
@@ -53,6 +56,7 @@
5356
"@aws-sdk/client-lambda": "3.387.0",
5457
"@aws-sdk/client-neptune": "3.387.0",
5558
"@aws-sdk/client-neptunedata": "3.403.0",
59+
"@aws-sdk/client-neptune-graph": "3.662.0",
5660
"@aws-sdk/credential-providers": "3.414.0",
5761
"archiver": "5.3.1",
5862
"aws4-axios": "3.3.0",

src/CDKPipelineApp.js

+63-42
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ express or implied. See the License for the specific language governing
1010
permissions and limitations under the License.
1111
*/
1212

13-
import { getNeptuneClusterinfoBy } from './pipelineResources.js'
13+
import { getNeptuneClusterDbInfoBy } from './pipelineResources.js'
1414
import { readFile, writeFile } from 'fs/promises';
1515
//import semver from 'semver';
1616
import fs from 'fs';
@@ -23,6 +23,7 @@ let REGION = '';
2323
let NEPTUNE_DB_NAME = '';
2424
let NEPTUNE_HOST = null;
2525
let NEPTUNE_PORT = null;
26+
let NEPTUNE_TYPE = null;
2627
let NEPTUNE_DBSubnetGroup = null;
2728
let NEPTUNE_IAM_POLICY_RESOURCE = '*';
2829
let LAMBDA_ZIP_FILE = '';
@@ -73,11 +74,27 @@ async function createDeploymentFile(folderPath, zipFilePath) {
7374
}
7475

7576

76-
async function createAWSpipelineCDK (pipelineName, neptuneDBName, neptuneDBregion, appSyncSchema, schemaModel, lambdaFilesPath, outputFile, __dirname, quiet, isNeptuneIAMAuth, neptuneHost, neptunePort, outputFolderPath ) {
77+
async function createAWSpipelineCDK({
78+
pipelineName,
79+
neptuneDBName,
80+
neptuneDBregion,
81+
appSyncSchema,
82+
schemaModel,
83+
lambdaFilesPath,
84+
outputFile,
85+
__dirname,
86+
quiet,
87+
isNeptuneIAMAuth,
88+
neptuneHost,
89+
neptunePort,
90+
outputFolderPath,
91+
neptuneType
92+
}) {
7793

7894
NAME = pipelineName;
7995
REGION = neptuneDBregion;
8096
NEPTUNE_DB_NAME = neptuneDBName;
97+
NEPTUNE_TYPE = neptuneType;
8198
APPSYNC_SCHEMA = appSyncSchema;
8299
SCHEMA_MODEL = schemaModel;
83100
NEPTUNE_HOST = neptuneHost;
@@ -88,50 +105,52 @@ async function createAWSpipelineCDK (pipelineName, neptuneDBName, neptuneDBregio
88105
let spinner = null;
89106
let neptuneClusterInfo = null;
90107

91-
try {
92-
if (!quiet) console.log('Get Neptune Cluster Info');
93-
if (!quiet) spinner = ora('Getting ...').start();
94-
neptuneClusterInfo = await getNeptuneClusterinfoBy(NEPTUNE_DB_NAME, REGION);
95-
if (!quiet) spinner.succeed('Got Neptune Cluster Info');
96-
if (isNeptuneIAMAuth) {
97-
if (!neptuneClusterInfo.isIAMauth) {
98-
console.error("The Neptune database authentication is set to VPC.");
99-
console.error("Remove the --output-aws-pipeline-cdk-neptune-IAM option.");
100-
process.exit(1);
101-
}
102-
} else {
103-
if (neptuneClusterInfo.isIAMauth) {
104-
console.error("The Neptune database authentication is set to IAM.");
105-
console.error("Add the --output-aws-pipeline-cdk-neptune-IAM option.");
106-
process.exit(1);
108+
if (neptuneType === 'neptune-db') {
109+
try {
110+
if (!quiet) console.log('Get Neptune Cluster Info');
111+
if (!quiet) spinner = ora('Getting ...').start();
112+
neptuneClusterInfo = await getNeptuneClusterDbInfoBy(NEPTUNE_DB_NAME, REGION);
113+
if (!quiet) spinner.succeed('Got Neptune Cluster Info');
114+
if (isNeptuneIAMAuth) {
115+
if (!neptuneClusterInfo.isIAMauth) {
116+
console.error("The Neptune database authentication is set to VPC.");
117+
console.error("Remove the --output-aws-pipeline-cdk-neptune-IAM option.");
118+
process.exit(1);
119+
}
107120
} else {
108-
if (!quiet) console.log(`Subnet Group: ` + yellow(neptuneClusterInfo.dbSubnetGroup));
121+
if (neptuneClusterInfo.isIAMauth) {
122+
console.error("The Neptune database authentication is set to IAM.");
123+
console.error("Add the --output-aws-pipeline-cdk-neptune-IAM option.");
124+
process.exit(1);
125+
} else {
126+
if (!quiet) console.log(`Subnet Group: ` + yellow(neptuneClusterInfo.dbSubnetGroup));
127+
}
109128
}
110-
}
111129

112-
if (neptuneClusterInfo.version != '') {
113-
const v = neptuneClusterInfo.version;
114-
if (lambdaFilesPath.includes('SDK') == true && //semver.satisfies(v, '>=1.2.1.0') ) {
115-
(v == '1.2.1.0' || v == '1.2.0.2' || v == '1.2.0.1' || v == '1.2.0.0' || v == '1.1.1.0' || v == '1.1.0.0')) {
116-
console.error("Neptune SDK query is supported starting with Neptune versions 1.2.1.0.R5");
117-
console.error("Switch to Neptune HTTPS query with option --output-resolver-query-https");
118-
process.exit(1);
130+
if (neptuneClusterInfo.version != '') {
131+
const v = neptuneClusterInfo.version;
132+
if (lambdaFilesPath.includes('SDK') == true && //semver.satisfies(v, '>=1.2.1.0') ) {
133+
(v == '1.2.1.0' || v == '1.2.0.2' || v == '1.2.0.1' || v == '1.2.0.0' || v == '1.1.1.0' || v == '1.1.0.0')) {
134+
console.error("Neptune SDK query is supported starting with Neptune versions 1.2.1.0.R5");
135+
console.error("Switch to Neptune HTTPS query with option --output-resolver-query-https");
136+
process.exit(1);
137+
}
119138
}
120-
}
121139

122-
NEPTUNE_HOST = neptuneClusterInfo.host;
123-
NEPTUNE_PORT = neptuneClusterInfo.port;
124-
NEPTUNE_DBSubnetGroup = neptuneClusterInfo.dbSubnetGroup.replace('default-', '');
125-
NEPTUNE_IAM_POLICY_RESOURCE = neptuneClusterInfo.iamPolicyResource;
126-
127-
} catch (error) {
128-
if (!quiet) spinner.fail("Error getting Neptune Cluster Info.");
129-
if (!isNeptuneIAMAuth) {
130-
spinner.clear();
131-
console.error("VPC data is not available to proceed.");
132-
process.exit(1);
133-
} else {
134-
if (!quiet) console.log("Proceeding without getting Neptune Cluster info.");
140+
NEPTUNE_HOST = neptuneClusterInfo.host;
141+
NEPTUNE_PORT = neptuneClusterInfo.port;
142+
NEPTUNE_DBSubnetGroup = neptuneClusterInfo.dbSubnetGroup.replace('default-', '');
143+
NEPTUNE_IAM_POLICY_RESOURCE = neptuneClusterInfo.iamPolicyResource;
144+
145+
} catch (error) {
146+
if (!quiet) spinner.fail("Error getting Neptune Cluster Info.");
147+
if (!isNeptuneIAMAuth) {
148+
spinner.clear();
149+
console.error("VPC data is not available to proceed.");
150+
process.exit(1);
151+
} else {
152+
if (!quiet) console.log("Proceeding without getting Neptune Cluster info.");
153+
}
135154
}
136155
}
137156

@@ -147,7 +166,9 @@ async function createAWSpipelineCDK (pipelineName, neptuneDBName, neptuneDBregio
147166
CDKFile = CDKFile.replace( "const NAME = '';", `const NAME = '${NAME}';` );
148167
CDKFile = CDKFile.replace( "const REGION = '';", `const REGION = '${REGION}';` );
149168
CDKFile = CDKFile.replace( "const NEPTUNE_HOST = '';", `const NEPTUNE_HOST = '${NEPTUNE_HOST}';` );
150-
CDKFile = CDKFile.replace( "const NEPTUNE_PORT = '';", `const NEPTUNE_PORT = '${NEPTUNE_PORT}';` );
169+
CDKFile = CDKFile.replace( "const NEPTUNE_PORT = '';", `const NEPTUNE_PORT = '${NEPTUNE_PORT}';` );
170+
CDKFile = CDKFile.replace( "const NEPTUNE_DB_NAME = '';", `const NEPTUNE_DB_NAME = '${NEPTUNE_DB_NAME}';` );
171+
CDKFile = CDKFile.replace( "const NEPTUNE_TYPE = '';", `const NEPTUNE_TYPE = '${NEPTUNE_TYPE}';` );
151172
CDKFile = CDKFile.replace( "const NEPTUNE_DBSubnetGroup = null;", `const NEPTUNE_DBSubnetGroup = '${NEPTUNE_DBSubnetGroup}';` );
152173
CDKFile = CDKFile.replace( "const NEPTUNE_IAM_AUTH = false;", `const NEPTUNE_IAM_AUTH = ${isNeptuneIAMAuth};` );
153174
CDKFile = CDKFile.replace( "const NEPTUNE_IAM_POLICY_RESOURCE = '*';", `const NEPTUNE_IAM_POLICY_RESOURCE = '${NEPTUNE_IAM_POLICY_RESOURCE}';` );

0 commit comments

Comments
 (0)