Skip to content

Commit

Permalink
more placeholder stuff - add retries
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Oct 11, 2022
1 parent 1afcec1 commit 45e8f15
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 29 deletions.
15 changes: 0 additions & 15 deletions API.md

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

8 changes: 5 additions & 3 deletions src/Nextjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class Nextjs extends Construct {
});
this.bucket = this.assetsDeployment.bucket;

this.originAccessIdentity = new cloudfront.OriginAccessIdentity(this, 'OAI(', {
this.originAccessIdentity = new cloudfront.OriginAccessIdentity(this, 'OAI', {
comment: 'Allows CloudFront to access S3 bucket with assets',
});

Expand All @@ -239,7 +239,7 @@ export class Nextjs extends Construct {
new iam.PolicyStatement({
// only allow getting of files - not listing
actions: ['s3:GetObject'],
resources: [`${this.bucket.bucketArn}/*`],
resources: [this.bucket.arnForObjects('*')],
principals: [this.originAccessIdentity.grantPrincipal],
})
);
Expand All @@ -253,7 +253,9 @@ export class Nextjs extends Construct {
? this.createCloudFrontDistributionForStub()
: this.createCloudFrontDistribution();
// wait for asset deployments to finish
this.assetsDeployment.deployments.forEach((s3Deployment) => this.distribution.node.addDependency(s3Deployment));
this.assetsDeployment.deployments.forEach((s3Deployment) =>
this.distribution.node.addDependency(s3Deployment.deployedBucket)
);

// // Invalidate CloudFront (might already be handled by deployments?)
// const invalidationCR = this.createCloudFrontInvalidation();
Expand Down
10 changes: 2 additions & 8 deletions src/NextjsAssetsDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ import { Construct } from 'constructs';
import * as fs from 'fs-extra';
import * as micromatch from 'micromatch';
import { NextjsBaseProps } from './NextjsBase';
import {
createArchive,
makeTokenPlaceholder,
NextjsBuild,
replaceTokenGlobs,
TOKEN_PLACEHOLDER_BEGIN,
} from './NextjsBuild';
import { createArchive, makeTokenPlaceholder, NextjsBuild, replaceTokenGlobs } from './NextjsBuild';

export interface NextjsAssetsDeploymentProps extends NextjsBaseProps {
/**
Expand Down Expand Up @@ -330,7 +324,7 @@ exports.handler = async (event) => {

Object.entries(this.props.environment || {})
.filter(([, value]) => Token.isUnresolved(value))
.filter(([key]) => key.startsWith(TOKEN_PLACEHOLDER_BEGIN + 'NEXT_PUBLIC_')) // don't replace server-only env vars
.filter(([key]) => key.startsWith('NEXT_PUBLIC_')) // don't replace server-only env vars
.forEach(([key, value]) => {
const token = makeTokenPlaceholder(key);
replacements[token] = value.toString();
Expand Down
4 changes: 1 addition & 3 deletions src/NextjsBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ export function getBuildCmdEnvironment(siteEnvironment?: { [key: string]: string
//
const buildCmdEnvironment: Record<string, string> = {};
Object.entries(siteEnvironment || {}).forEach(([key, value]) => {
buildCmdEnvironment[key] = Token.isUnresolved(value)
? TOKEN_PLACEHOLDER_BEGIN + key.toString() + TOKEN_PLACEHOLDER_END
: value;
buildCmdEnvironment[key] = Token.isUnresolved(value) ? makeTokenPlaceholder(key) : value;
});

return buildCmdEnvironment;
Expand Down

0 comments on commit 45e8f15

Please sign in to comment.