From d7b45e5545025ce53a807fbf74d4eb958725a925 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Tue, 8 Nov 2022 14:14:59 -0800 Subject: [PATCH] Serializing JSON for env vars --- .projen/deps.json | 4 ++-- .projenrc.js | 2 +- package.json | 4 ++-- src/NextjsLambda.ts | 13 +++++++------ yarn.lock | 10 +++++----- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.projen/deps.json b/.projen/deps.json index b9e3039c..ede0b9a1 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -22,7 +22,7 @@ }, { "name": "aws-cdk-lib", - "version": "2.39.0", + "version": "2.50.0", "type": "build" }, { @@ -171,7 +171,7 @@ }, { "name": "aws-cdk-lib", - "version": "^2.39.0", + "version": "^2.50.0", "type": "peer" }, { diff --git a/.projenrc.js b/.projenrc.js index 21e6decb..b120dbdc 100644 --- a/.projenrc.js +++ b/.projenrc.js @@ -2,7 +2,7 @@ const { awscdk } = require('projen'); const project = new awscdk.AwsCdkConstructLibrary({ author: 'JetBridge', authorAddress: 'mischa@jetbridge.com', - cdkVersion: '2.39.0', + cdkVersion: '2.50.0', defaultReleaseBranch: 'main', name: 'cdk-nextjs-standalone', repositoryUrl: 'https://github.com/jetbridge/cdk-nextjs.git', diff --git a/package.json b/package.json index 34b1dd1a..d2d876aa 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@types/node": "^14", "@typescript-eslint/eslint-plugin": "^5", "@typescript-eslint/parser": "^5", - "aws-cdk-lib": "2.39.0", + "aws-cdk-lib": "2.50.0", "aws-sdk": "^2.1240.0", "constructs": "10.0.5", "eslint": "^8", @@ -63,7 +63,7 @@ "typescript": "^4.8.4" }, "peerDependencies": { - "aws-cdk-lib": "^2.39.0", + "aws-cdk-lib": "^2.50.0", "constructs": "^10.0.5" }, "dependencies": { diff --git a/src/NextjsLambda.ts b/src/NextjsLambda.ts index f8fd688f..c222a620 100644 --- a/src/NextjsLambda.ts +++ b/src/NextjsLambda.ts @@ -118,8 +118,9 @@ export class NextJsLambda extends Construct { }); this.lambdaFunction = fn; - // put JSON file with env var replacements in S3e - this.configBucket = this.createConfigBucket(props); + // put JSON file with env var replacements in S3 + const [configBucket, configDeployment] = this.createConfigBucket(props); + this.configBucket = configBucket; // replace env var placeholders in the lambda package with resolved values const rewriter = new NextjsS3EnvRewriter(this, 'LambdaCodeRewriter', { @@ -129,7 +130,7 @@ export class NextJsLambda extends Construct { replacementConfig: { // use json file in S3 for replacement values // this can contain backend secrets so better to not have them in custom resource logs - jsonS3Bucket: this.configBucket, + jsonS3Bucket: configDeployment.deployedBucket, jsonS3Key: CONFIG_ENV_JSON_PATH, }, debug: true, // enable for more verbose output from the rewriter function @@ -172,13 +173,13 @@ export class NextJsLambda extends Construct { }); // upload environment config to s3 - new BucketDeployment(this, 'EnvJsonDeployment', { + const deployment = new BucketDeployment(this, 'EnvJsonDeployment', { sources: [ - // warning: this doesn't escape quotes in unresolved tokens + // serialize as JSON to S3 object Source.jsonData(CONFIG_ENV_JSON_PATH, replacementParams), ], destinationBucket: bucket, }); - return bucket; + return [bucket, deployment] as const; } } diff --git a/yarn.lock b/yarn.lock index 651a9a22..c03607fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1288,10 +1288,10 @@ available-typed-arrays@^1.0.5: resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7" integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== -aws-cdk-lib@2.39.0: - version "2.39.0" - resolved "https://registry.yarnpkg.com/aws-cdk-lib/-/aws-cdk-lib-2.39.0.tgz#4461deb7f3daac603dc2684d6be4280c38f00489" - integrity sha512-YhXSE6bGS8hQxYygftp3VbaFEz19wl4B1tUAjKjW1rNs3ZpNGnW6o1AVA3Yuc5DlaELrIjXxF0/f+5SvSpYkTA== +aws-cdk-lib@2.50.0: + version "2.50.0" + resolved "https://registry.yarnpkg.com/aws-cdk-lib/-/aws-cdk-lib-2.50.0.tgz#2b3a9ba4c1c4c56fd32e3e4f57eea8bf9fa3dbba" + integrity sha512-deDbZTI7oyu3rqUyqjwhP6tnUO8MD70lE98yR65xiYty4yXBpsWKbeH3s1wNLpLAWS3hWJYyMtjZ4ZfC35NtVg== dependencies: "@balena/dockerignore" "^1.0.2" case "1.6.3" @@ -1300,7 +1300,7 @@ aws-cdk-lib@2.39.0: jsonschema "^1.4.1" minimatch "^3.1.2" punycode "^2.1.1" - semver "^7.3.7" + semver "^7.3.8" yaml "1.10.2" aws-lambda@^1.0.7: