Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with Neptune Analytics #31

Merged
merged 12 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
output/**
package-lock.json
.vscode/launch.json
node_modules/**
templates/Lambda4AppSyncHTTP/node_modules/**
templates/Lambda4AppSyncSDK/node_modules/**
**/node_modules/
coverage/**
test/node_modules/**
test/TestCases/Case01/output/**
test/TestCases/Case01/output/**
test/TestCases/Case02/output/**
test/TestCases/Case03/output/**
test/TestCases/Case04/output/**
test/TestCases/Case05/output/**
test/TestCases/Case06/output/**
**/output/
*.iml
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws/neptune-for-graphql",
"version": "1.0.0",
"version": "1.1.0",
"description": "CLI utility to create and maintain a GraphQL API for Amazon Neptune",
"keywords": [
"Amazon Neptune",
Expand All @@ -19,9 +19,10 @@
"test": "test"
},
"scripts": {
"postinstall": "cd templates/Lambda4AppSyncHTTP && npm install && cd ../Lambda4AppSyncSDK && npm install",
"postinstall": "cd templates/Lambda4AppSyncHTTP && npm install && cd ../Lambda4AppSyncSDK && npm install && cd ../Lambda4AppSyncGraphSDK && npm install",
"lint": "eslint neptune-for-graphql.mjs ./src",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js",
"test:sdk": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js --testPathPattern=test/TestCases/Case07",
"test:resolver": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js --testPathPattern=test/TestCases/Case01"
},
"jest": {
Expand All @@ -42,6 +43,8 @@
"./templates/Lambda4AppSyncHTTP/package.json",
"./templates/Lambda4AppSyncSDK/index.mjs",
"./templates/Lambda4AppSyncSDK/package.json",
"./templates/Lambda4AppSyncGraphSDK/index.mjs",
"./templates/Lambda4AppSyncGraphSDK/package.json",
"./src/**"
],
"author": "AWS",
Expand All @@ -53,6 +56,7 @@
"@aws-sdk/client-lambda": "3.387.0",
"@aws-sdk/client-neptune": "3.387.0",
"@aws-sdk/client-neptunedata": "3.403.0",
"@aws-sdk/client-neptune-graph": "3.662.0",
"@aws-sdk/credential-providers": "3.414.0",
"archiver": "5.3.1",
"aws4-axios": "3.3.0",
Expand Down
105 changes: 63 additions & 42 deletions src/CDKPipelineApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/

import { getNeptuneClusterinfoBy } from './pipelineResources.js'
import { getNeptuneClusterDbInfoBy } from './pipelineResources.js'
import { readFile, writeFile } from 'fs/promises';
//import semver from 'semver';
import fs from 'fs';
Expand All @@ -23,6 +23,7 @@ let REGION = '';
let NEPTUNE_DB_NAME = '';
let NEPTUNE_HOST = null;
let NEPTUNE_PORT = null;
let NEPTUNE_TYPE = null;
let NEPTUNE_DBSubnetGroup = null;
let NEPTUNE_IAM_POLICY_RESOURCE = '*';
let LAMBDA_ZIP_FILE = '';
Expand Down Expand Up @@ -73,11 +74,27 @@ async function createDeploymentFile(folderPath, zipFilePath) {
}


async function createAWSpipelineCDK (pipelineName, neptuneDBName, neptuneDBregion, appSyncSchema, schemaModel, lambdaFilesPath, outputFile, __dirname, quiet, isNeptuneIAMAuth, neptuneHost, neptunePort, outputFolderPath ) {
async function createAWSpipelineCDK({
pipelineName,
neptuneDBName,
neptuneDBregion,
appSyncSchema,
schemaModel,
lambdaFilesPath,
outputFile,
__dirname,
quiet,
isNeptuneIAMAuth,
neptuneHost,
neptunePort,
outputFolderPath,
neptuneType
}) {

NAME = pipelineName;
REGION = neptuneDBregion;
NEPTUNE_DB_NAME = neptuneDBName;
NEPTUNE_TYPE = neptuneType;
APPSYNC_SCHEMA = appSyncSchema;
SCHEMA_MODEL = schemaModel;
NEPTUNE_HOST = neptuneHost;
Expand All @@ -88,50 +105,52 @@ async function createAWSpipelineCDK (pipelineName, neptuneDBName, neptuneDBregio
let spinner = null;
let neptuneClusterInfo = null;

try {
if (!quiet) console.log('Get Neptune Cluster Info');
if (!quiet) spinner = ora('Getting ...').start();
neptuneClusterInfo = await getNeptuneClusterinfoBy(NEPTUNE_DB_NAME, REGION);
if (!quiet) spinner.succeed('Got Neptune Cluster Info');
if (isNeptuneIAMAuth) {
if (!neptuneClusterInfo.isIAMauth) {
console.error("The Neptune database authentication is set to VPC.");
console.error("Remove the --output-aws-pipeline-cdk-neptune-IAM option.");
process.exit(1);
}
} else {
if (neptuneClusterInfo.isIAMauth) {
console.error("The Neptune database authentication is set to IAM.");
console.error("Add the --output-aws-pipeline-cdk-neptune-IAM option.");
process.exit(1);
if (neptuneType === 'neptune-db') {
try {
if (!quiet) console.log('Get Neptune Cluster Info');
if (!quiet) spinner = ora('Getting ...').start();
neptuneClusterInfo = await getNeptuneClusterDbInfoBy(NEPTUNE_DB_NAME, REGION);
if (!quiet) spinner.succeed('Got Neptune Cluster Info');
if (isNeptuneIAMAuth) {
if (!neptuneClusterInfo.isIAMauth) {
console.error("The Neptune database authentication is set to VPC.");
console.error("Remove the --output-aws-pipeline-cdk-neptune-IAM option.");
process.exit(1);
}
} else {
if (!quiet) console.log(`Subnet Group: ` + yellow(neptuneClusterInfo.dbSubnetGroup));
if (neptuneClusterInfo.isIAMauth) {
console.error("The Neptune database authentication is set to IAM.");
console.error("Add the --output-aws-pipeline-cdk-neptune-IAM option.");
process.exit(1);
} else {
if (!quiet) console.log(`Subnet Group: ` + yellow(neptuneClusterInfo.dbSubnetGroup));
}
}
}

if (neptuneClusterInfo.version != '') {
const v = neptuneClusterInfo.version;
if (lambdaFilesPath.includes('SDK') == true && //semver.satisfies(v, '>=1.2.1.0') ) {
(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')) {
console.error("Neptune SDK query is supported starting with Neptune versions 1.2.1.0.R5");
console.error("Switch to Neptune HTTPS query with option --output-resolver-query-https");
process.exit(1);
if (neptuneClusterInfo.version != '') {
const v = neptuneClusterInfo.version;
if (lambdaFilesPath.includes('SDK') == true && //semver.satisfies(v, '>=1.2.1.0') ) {
(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')) {
console.error("Neptune SDK query is supported starting with Neptune versions 1.2.1.0.R5");
console.error("Switch to Neptune HTTPS query with option --output-resolver-query-https");
process.exit(1);
}
}
}

NEPTUNE_HOST = neptuneClusterInfo.host;
NEPTUNE_PORT = neptuneClusterInfo.port;
NEPTUNE_DBSubnetGroup = neptuneClusterInfo.dbSubnetGroup.replace('default-', '');
NEPTUNE_IAM_POLICY_RESOURCE = neptuneClusterInfo.iamPolicyResource;

} catch (error) {
if (!quiet) spinner.fail("Error getting Neptune Cluster Info.");
if (!isNeptuneIAMAuth) {
spinner.clear();
console.error("VPC data is not available to proceed.");
process.exit(1);
} else {
if (!quiet) console.log("Proceeding without getting Neptune Cluster info.");
NEPTUNE_HOST = neptuneClusterInfo.host;
NEPTUNE_PORT = neptuneClusterInfo.port;
NEPTUNE_DBSubnetGroup = neptuneClusterInfo.dbSubnetGroup.replace('default-', '');
NEPTUNE_IAM_POLICY_RESOURCE = neptuneClusterInfo.iamPolicyResource;

} catch (error) {
if (!quiet) spinner.fail("Error getting Neptune Cluster Info.");
if (!isNeptuneIAMAuth) {
spinner.clear();
console.error("VPC data is not available to proceed.");
process.exit(1);
} else {
if (!quiet) console.log("Proceeding without getting Neptune Cluster info.");
}
}
}

Expand All @@ -147,7 +166,9 @@ async function createAWSpipelineCDK (pipelineName, neptuneDBName, neptuneDBregio
CDKFile = CDKFile.replace( "const NAME = '';", `const NAME = '${NAME}';` );
CDKFile = CDKFile.replace( "const REGION = '';", `const REGION = '${REGION}';` );
CDKFile = CDKFile.replace( "const NEPTUNE_HOST = '';", `const NEPTUNE_HOST = '${NEPTUNE_HOST}';` );
CDKFile = CDKFile.replace( "const NEPTUNE_PORT = '';", `const NEPTUNE_PORT = '${NEPTUNE_PORT}';` );
CDKFile = CDKFile.replace( "const NEPTUNE_PORT = '';", `const NEPTUNE_PORT = '${NEPTUNE_PORT}';` );
CDKFile = CDKFile.replace( "const NEPTUNE_DB_NAME = '';", `const NEPTUNE_DB_NAME = '${NEPTUNE_DB_NAME}';` );
CDKFile = CDKFile.replace( "const NEPTUNE_TYPE = '';", `const NEPTUNE_TYPE = '${NEPTUNE_TYPE}';` );
CDKFile = CDKFile.replace( "const NEPTUNE_DBSubnetGroup = null;", `const NEPTUNE_DBSubnetGroup = '${NEPTUNE_DBSubnetGroup}';` );
CDKFile = CDKFile.replace( "const NEPTUNE_IAM_AUTH = false;", `const NEPTUNE_IAM_AUTH = ${isNeptuneIAMAuth};` );
CDKFile = CDKFile.replace( "const NEPTUNE_IAM_POLICY_RESOURCE = '*';", `const NEPTUNE_IAM_POLICY_RESOURCE = '${NEPTUNE_IAM_POLICY_RESOURCE}';` );
Expand Down
Loading