Skip to content

Commit 517eff7

Browse files
authored
Fixed deployment of aws resources if a pipeline name is not specified (aws#117)
Fixed deployment of aws resources which would fail if option `--create-update-aws-pipeline-name` was not specified: * corrected mismatch of resolver schema file name when creating the lambda zip file by passing the generated schema file name to the function which is creating the zip file * changed the output file prefix to only have the `.output` suffix if there is no discovered graph name * changed App Sync Function and DataSource resource names to replace any dashes `-` with underscores as dashes are not allowed (but can be present in Neptune db/graph names) * added integration tests to validate that correct output files and zip file content are created if no pipeline name is provided Other minor changes: * changed file error logging to include the `error.message` as the error message was output to console but missing from the file * added validation of output folder files to CDK integration tests * modified affected test cases to have descriptive file names and output folders
1 parent a0a3b0b commit 517eff7

28 files changed

+284
-97
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,7 @@ permissions and limitations under the License.
108108
can be referenced further in the
109109
query ([#114](https://github.com/aws/amazon-neptune-for-graphql/pull/114))
110110
* Fixed Apollo template to reference `graphql` `parse` instead of `graphql-tag`
111-
`gql` ([#116](https://github.com/aws/amazon-neptune-for-graphql/pull/116))
111+
`gql` ([#116](https://github.com/aws/amazon-neptune-for-graphql/pull/116))
112+
* Fixed deployment of AWS resources if a pipeline name is not provided as an
113+
input
114+
option ([#117](https://github.com/aws/amazon-neptune-for-graphql/pull/117))

src/CDKPipelineApp.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ async function getSchemaFields(typeName) {
5454
return r;
5555
}
5656

57-
async function createDeploymentFile(templateFolderPath, resolverFilePath) {
57+
async function createDeploymentFile({templateFolderPath, resolverFilePath, resolverSchemaFilePath}) {
5858
try {
5959
const zipFilePath = path.join(RELATIVE_OUTPUT_PATH, `${NAME}.zip`);
60-
const resolverSchemaFilePath = path.join(RELATIVE_OUTPUT_PATH, `${NAME}.resolver.schema.json.gz`)
6160
await createLambdaDeploymentPackage({
6261
outputZipFilePath: zipFilePath,
6362
templateFolderPath: templateFolderPath,
@@ -85,6 +84,7 @@ async function createAWSpipelineCDK({
8584
neptunePort,
8685
outputFolderPath,
8786
resolverFilePath,
87+
resolverSchemaFilePath,
8888
neptuneType
8989
}) {
9090

@@ -153,7 +153,11 @@ async function createAWSpipelineCDK({
153153
}
154154

155155
if (!quiet) spinner = ora('Creating ZIP ...').start();
156-
await createDeploymentFile(lambdaFilesPath, resolverFilePath);
156+
await createDeploymentFile({
157+
templateFolderPath: lambdaFilesPath,
158+
resolverFilePath: resolverFilePath,
159+
resolverSchemaFilePath: resolverSchemaFilePath
160+
});
157161
if (!quiet) spinner.succeed('Created ZIP File: ' + yellow(LAMBDA_ZIP_FILE));
158162

159163
APPSYNC_ATTACH_QUERY = await getSchemaFields('Query');

src/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function loggerError(errorMessage, error) {
7272
let toLog = removeYellow(errorMessage);
7373
if (error) {
7474
toConsole = toConsole + ': ' + error.message + ' - Please see ' + logFileDestination + ' for more details';
75-
toLog = toLog + '\n' + JSON.stringify(error, null, 4);
75+
toLog = toLog + ': ' + error.message + '\n' + JSON.stringify(error, null, 4);
7676
}
7777
console.error(toConsole);
7878
fileLogger.error(toLog);

src/main.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ async function main() {
401401
createUpdatePipelineNeptuneDatabaseName ||
402402
inputCDKpipelineName ||
403403
inputCDKpipelineDatabaseName ||
404-
`${neptuneInfo?.graphName?.concat('.') || ''}output`;
404+
neptuneInfo?.graphName ||
405+
'output';
405406
// save the neptune schema early for troubleshooting purposes
406407
saveNeptuneSchema(outputFilePrefix);
407408

@@ -591,8 +592,8 @@ async function main() {
591592
}
592593

593594
// Output Lambda resolver
594-
if (outputLambdaResolverFile == '') {
595-
outputLambdaResolverFile = outputFolderPath + '/output.resolver.graphql.js';
595+
if (!outputLambdaResolverFile) {
596+
outputLambdaResolverFile = path.join(outputFolderPath, `${outputFilePrefix}.resolver.graphql.js`);
596597
}
597598

598599
try {
@@ -659,11 +660,10 @@ async function main() {
659660

660661
if ( !(createUpdatePipeline || inputCDKpipeline) && createLambdaZip) {
661662

662-
if (outputLambdaResolverZipFile == '' && outputLambdaResolverZipName == '')
663-
outputLambdaResolverZipFile = outputFolderPath + '/output.lambda.zip';
664-
665-
if (outputLambdaResolverZipFile == '' && outputLambdaResolverZipName != '')
666-
outputLambdaResolverZipFile = outputFolderPath + '/' + outputLambdaResolverZipName + '.zip';
663+
if (!outputLambdaResolverZipFile) {
664+
const zipName = outputLambdaResolverZipName || `${outputFilePrefix}.lambda`;
665+
outputLambdaResolverZipFile = path.join(outputFolderPath, `${zipName}.zip`);
666+
}
667667

668668
try {
669669
if (!quiet) spinner = ora('Creating Lambda ZIP ...').start();
@@ -693,21 +693,24 @@ async function main() {
693693
let neptuneHost = neptuneInfo.host;
694694
let neptunePort = neptuneInfo.port;
695695

696-
await createUpdateAWSpipeline( createUpdatePipelineName,
697-
createUpdatePipelineNeptuneDatabaseName,
698-
createUpdatePipelineRegion,
699-
outputSchema,
700-
schemaModel,
701-
__dirname + outputLambdaPackagePath,
702-
outputSchemaMutations,
703-
quiet,
704-
__dirname,
705-
isNeptuneIAMAuth,
706-
neptuneHost,
707-
neptunePort,
708-
outputFolderPath,
709-
outputLambdaResolverFile,
710-
neptuneType );
696+
await createUpdateAWSpipeline({
697+
pipelineName: createUpdatePipelineName,
698+
neptuneDBName: createUpdatePipelineNeptuneDatabaseName,
699+
neptuneDBregion: createUpdatePipelineRegion,
700+
appSyncSchema: outputSchema,
701+
schemaModel: schemaModel,
702+
lambdaFilesPath: __dirname + outputLambdaPackagePath,
703+
addMutations: outputSchemaMutations,
704+
quietI: quiet,
705+
__dirname: __dirname,
706+
isNeptuneIAMAuth: isNeptuneIAMAuth,
707+
neptuneHost: neptuneHost,
708+
neptunePort: neptunePort,
709+
outputFolderPath: outputFolderPath,
710+
resolverFilePath: outputLambdaResolverFile,
711+
resolverSchemaFilePath: resolverSchemaFile,
712+
neptuneType: neptuneType
713+
});
711714
} catch (err) {
712715
loggerError('Error creating AWS pipeline', err);
713716
}
@@ -743,6 +746,7 @@ async function main() {
743746
neptunePort: neptunePort,
744747
outputFolderPath: outputFolderPath,
745748
resolverFilePath: outputLambdaResolverFile,
749+
resolverSchemaFilePath: resolverSchemaFile,
746750
neptuneType: neptuneType
747751
});
748752
} catch (err) {

src/pipelineResources.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ async function createLambdaRole() {
392392
* Creates the lambda deployment ZIP package
393393
* @param templateFolderPath the path to the template folder that contains contents to add to the zip
394394
* @param resolverFilePath the path to the resolver file that should be added to the zip
395+
* @param resolverSchemaFilePath the path to the resolver schema file that should be added to the zip
395396
* @returns {Promise<Buffer<ArrayBufferLike>>}
396397
*/
397-
async function createDeploymentPackage(templateFolderPath, resolverFilePath) {
398+
async function createDeploymentPackage({templateFolderPath, resolverFilePath, resolverSchemaFilePath}) {
398399
const zipFilePath = path.join(thisOutputFolderPath, `${NAME}.zip`);
399-
const resolverSchemaFilePath = path.join(thisOutputFolderPath, `${NAME}.resolver.schema.json.gz`)
400400
await createLambdaDeploymentPackage({
401401
outputZipFilePath: zipFilePath,
402402
templateFolderPath: templateFolderPath,
@@ -535,11 +535,15 @@ async function createAppSyncAPI() {
535535
const apiKey = response.apiKey.id;
536536
succeedSpinner('Created API key', {logLevel: 'info'});
537537

538+
// some resource names cannot have dashes
539+
const sanitizedName = NAME.replaceAll('-', '_');
540+
538541
// create datasource
539542
startSpinner('Creating DataSource ...', true);
543+
const dataSourceName = `${sanitizedName}DataSource`;
540544
params = {
541545
apiId: apiId,
542-
name: NAME + 'DataSource',
546+
name: dataSourceName,
543547
type: "AWS_LAMBDA",
544548
serviceRoleArn: LAMBDA_INVOCATION_ROLE,
545549
lambdaConfig: {
@@ -548,15 +552,16 @@ async function createAppSyncAPI() {
548552
};
549553
command = new CreateDataSourceCommand(params);
550554
response = await appSyncClient.send(command);
551-
succeedSpinner('Created DataSource: ' + yellow(NAME+'DataSource'), {logLevel: 'debug'});
555+
succeedSpinner('Created DataSource: ' + yellow(dataSourceName), {logLevel: 'debug'});
552556
loggerInfo('Created datasource');
553557

554558
// create function
555559
startSpinner('Creating Function ...', true);
560+
const functionName = `${sanitizedName}Function`;
556561
params = {
557562
apiId: apiId,
558-
name: NAME+'Function',
559-
dataSourceName: NAME+'DataSource',
563+
name: functionName,
564+
dataSourceName: dataSourceName,
560565
runtime: {
561566
name: "APPSYNC_JS",
562567
runtimeVersion: "1.0.0",
@@ -591,7 +596,7 @@ export function response(ctx) {
591596
await sleep(5000);
592597
let functionId = response.functionConfiguration.functionId;
593598
storeResource({AppSyncAPIFunction: functionId});
594-
succeedSpinner('Created Function: ' + yellow(NAME+'Function'), {logLevel: 'debug'});
599+
succeedSpinner('Created Function: ' + yellow(functionName), {logLevel: 'debug'});
595600
loggerInfo('Created function');
596601

597602
// Upload schema
@@ -917,21 +922,24 @@ async function updateAppSyncAPI(resources) {
917922
}
918923

919924

920-
async function createUpdateAWSpipeline ( pipelineName,
921-
neptuneDBName,
922-
neptuneDBregion,
923-
appSyncSchema,
924-
schemaModel,
925-
lambdaFilesPath,
926-
addMutations,
927-
quietI,
928-
__dirname,
929-
isNeptuneIAMAuth,
930-
neptuneHost,
931-
neptunePort,
932-
outputFolderPath,
933-
resolverFilePath,
934-
neptuneType) {
925+
async function createUpdateAWSpipeline({
926+
pipelineName,
927+
neptuneDBName,
928+
neptuneDBregion,
929+
appSyncSchema,
930+
schemaModel,
931+
lambdaFilesPath,
932+
addMutations,
933+
quietI,
934+
__dirname,
935+
isNeptuneIAMAuth,
936+
neptuneHost,
937+
neptunePort,
938+
outputFolderPath,
939+
resolverFilePath,
940+
resolverSchemaFilePath,
941+
neptuneType
942+
}) {
935943

936944
NAME = pipelineName;
937945
REGION = neptuneDBregion;
@@ -1002,7 +1010,11 @@ async function createUpdateAWSpipeline ( pipelineName,
10021010
}
10031011

10041012
startSpinner('Creating ZIP ...', true);
1005-
ZIP = await createDeploymentPackage(LAMBDA_FILES_PATH, resolverFilePath);
1013+
ZIP = await createDeploymentPackage({
1014+
templateFolderPath: LAMBDA_FILES_PATH,
1015+
resolverFilePath: resolverFilePath,
1016+
resolverSchemaFilePath: resolverSchemaFilePath
1017+
});
10061018
succeedSpinner('Created ZIP File: ' + yellow(LAMBDA_FILES_PATH), {logLevel: 'info'});
10071019

10081020
await createLambdaRole();
@@ -1034,7 +1046,11 @@ async function createUpdateAWSpipeline ( pipelineName,
10341046
}
10351047

10361048
startSpinner('Creating ZIP ...', true);
1037-
ZIP = await createDeploymentPackage(LAMBDA_FILES_PATH, resolverFilePath);
1049+
ZIP = await createDeploymentPackage({
1050+
templateFolderPath: LAMBDA_FILES_PATH,
1051+
resolverFilePath: resolverFilePath,
1052+
resolverSchemaFilePath: resolverSchemaFilePath
1053+
});
10381054
succeedSpinner('Created ZIP File: ' + yellow(LAMBDA_FILES_PATH), {logLevel: 'info'});
10391055

10401056
loggerInfo('Updating Lambda function', {toConsole: true});

src/zipPackage.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,20 @@ async function createZip({targetZipFilePath, includePaths = [], includeContent =
8484
* @returns {Promise<Buffer<ArrayBufferLike>>}
8585
*/
8686
export async function createLambdaDeploymentPackage({outputZipFilePath, templateFolderPath, resolverFilePath, resolverSchemaFilePath}) {
87-
const filePaths = [{source: templateFolderPath}, {source: resolverFilePath, target: 'output.resolver.graphql.js'}];
8887
const modulePath = getModulePath();
88+
const filePaths = [
89+
{source: templateFolderPath},
90+
{source: resolverFilePath, target: 'output.resolver.graphql.js'},
91+
{source: resolverSchemaFilePath, target: 'output.resolver.schema.json.gz'},
92+
{source: path.join(modulePath, '/../templates/util.mjs')}
93+
];
94+
8995
if (templateFolderPath.includes('HTTP')) {
9096
filePaths.push({
9197
source: path.join(modulePath, '/../templates/queryHttpNeptune.mjs')
9298
})
9399
}
94100

95-
filePaths.push({
96-
source: resolverSchemaFilePath,
97-
target: 'output.resolver.schema.json.gz'
98-
}, {source: path.join(modulePath, '/../templates/util.mjs')});
99-
100101
await createZip({
101102
targetZipFilePath: outputZipFilePath,
102103
includePaths: filePaths

templates/CDKTemplate.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,15 @@ class AppSyncNeptuneStack extends Stack {
163163
]
164164
})
165165
);
166-
167-
// AppSync: DataSource
168-
const dataSource = new CfnDataSource(this, NAME + 'DataSource', {
166+
167+
// some resources names cannot have dashes
168+
const sanitizedName = NAME.replaceAll('-', '_');
169+
170+
// AppSync: DataSource
171+
const dataSourceName = `${sanitizedName}DataSource`;
172+
const dataSource = new CfnDataSource(this, dataSourceName, {
169173
apiId: itemsGraphQLApi.attrApiId,
170-
name: NAME + 'DataSource',
174+
name: dataSourceName,
171175
type: 'AWS_LAMBDA',
172176
lambdaConfig: {
173177
lambdaFunctionArn: LAMBDA_ARN,
@@ -181,10 +185,11 @@ class AppSyncNeptuneStack extends Stack {
181185

182186

183187
// AppSync: Function
184-
const functionappSync = new CfnFunctionConfiguration(this, NAME + 'Function', {
188+
const functionName = `${sanitizedName}Function`;
189+
const functionappSync = new CfnFunctionConfiguration(this, functionName, {
185190
apiId: itemsGraphQLApi.attrApiId,
186-
dataSourceName: NAME + 'DataSource',
187-
name: NAME + 'Function',
191+
dataSourceName: dataSourceName,
192+
name: functionName,
188193
runtime: {
189194
name: "APPSYNC_JS",
190195
runtimeVersion: "1.0.0",

test/TestCases/Case04/Case04.01.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { jest } from '@jest/globals';
33
import { readJSONFile } from '../../testLib';
44
import { main } from "../../../src/main";
55

6-
const casetest = readJSONFile('./test/TestCases/Case04/case.json');
6+
const casetest = readJSONFile('./test/TestCases/Case04/get-db-schema.json');
77

88
async function executeUtility() {
99
process.argv = casetest.argv;

test/TestCases/Case04/Case04.02.test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { readJSONFile, checkOutputFileContent, checkFolderContainsFiles } from '
22
import { sortNeptuneSchema } from './util';
33
import fs from "fs";
44
import { parseNeptuneEndpoint } from "../../../src/util.js";
5+
import path from "path";
56

6-
const casetest = readJSONFile('./test/TestCases/Case04/case.json');
7+
const casetest = readJSONFile('./test/TestCases/Case04/get-db-schema.json');
78
const testDbInfo = parseNeptuneEndpoint(casetest.host + ':' + casetest.port);
8-
const outputFolderPath = './test/TestCases/Case04/output';
9+
const outputFolderPath = './test/TestCases/Case04/get-db-schema-output';
910

10-
const schemaFile = `${testDbInfo.graphName}.output.neptune.schema.json`;
11-
const neptuneSchema = readJSONFile(`./test/TestCases/Case04/output/${schemaFile}`);
11+
const schemaFile = `${testDbInfo.graphName}.neptune.schema.json`;
12+
const neptuneSchema = readJSONFile(path.join(outputFolderPath, schemaFile));
1213
const refSchemaFile = `output.neptune.${testDbInfo.neptuneType.replace('neptune-', '')}.schema.json`;
1314
const refNeptuneSchema = readJSONFile(`./test/TestCases/Case04/outputReference/${refSchemaFile}`);
1415

@@ -18,10 +19,10 @@ describe('Validate output content', () => {
1819
});
1920

2021
checkFolderContainsFiles(outputFolderPath, [
21-
`${testDbInfo.graphName}.output.resolver.graphql.js`,
22-
`${testDbInfo.graphName}.output.resolver.schema.json.gz`,
23-
`${testDbInfo.graphName}.output.schema.graphql`,
24-
`${testDbInfo.graphName}.output.source.schema.graphql`
22+
`${testDbInfo.graphName}.resolver.graphql.js`,
23+
`${testDbInfo.graphName}.resolver.schema.json.gz`,
24+
`${testDbInfo.graphName}.schema.graphql`,
25+
`${testDbInfo.graphName}.source.schema.graphql`
2526
]);
2627

2728
// note that this test can be flaky depending on how the air routes sample data was loaded into neptune
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description":"",
44
"argv":["--quiet",
55
"--input-graphdb-schema-neptune-endpoint", "<AIR_ROUTES_DB_HOST>:<AIR_ROUTES_DB_PORT>",
6-
"--output-folder-path", "./test/TestCases/Case04/output",
6+
"--output-folder-path", "./test/TestCases/Case04/get-db-schema-output",
77
"--output-no-lambda-zip"],
88
"host": "<AIR_ROUTES_DB_HOST>",
99
"port": "<AIR_ROUTES_DB_PORT>",

0 commit comments

Comments
 (0)