Skip to content

Commit

Permalink
Merge pull request #12 from jetbridge/config-json-escape
Browse files Browse the repository at this point in the history
Depend on deployment of config before rewriting
  • Loading branch information
revmischa authored Nov 8, 2022
2 parents 4ef408c + d7b45e5 commit 958241d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { awscdk } = require('projen');
const project = new awscdk.AwsCdkConstructLibrary({
author: 'JetBridge',
authorAddress: '[email protected]',
cdkVersion: '2.39.0',
cdkVersion: '2.50.0',
defaultReleaseBranch: 'main',
name: 'cdk-nextjs-standalone',
repositoryUrl: 'https://github.com/jetbridge/cdk-nextjs.git',
Expand Down
4 changes: 2 additions & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/NextjsLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
10 changes: 5 additions & 5 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 958241d

Please sign in to comment.