Skip to content

Commit

Permalink
Merge pull request #55 from Opetushallitus/OK-672
Browse files Browse the repository at this point in the history
OK-672
  • Loading branch information
pretseli authored Dec 2, 2024
2 parents 88127de + 2fa7e15 commit 6edf66f
Show file tree
Hide file tree
Showing 71 changed files with 2,733 additions and 1,032 deletions.
119 changes: 102 additions & 17 deletions cdk/lib/sovellus-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,106 @@ import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as route53 from 'aws-cdk-lib/aws-route53';
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
import { Nextjs } from 'cdk-nextjs-standalone';
import * as logs from 'aws-cdk-lib/aws-logs';
import { Nextjs, NextjsOverrides } from 'cdk-nextjs-standalone';
import { PriceClass } from 'aws-cdk-lib/aws-cloudfront';

type EnvironmentName = 'untuva' | 'hahtuva' | 'pallero';

const publicHostedZones: Record<EnvironmentName, string> = {
untuva: 'untuvaopintopolku.fi',
hahtuva: 'hahtuvaopintopolku.fi',
pallero: 'testiopintopolku.fi',
};

const publicHostedZoneIds: Record<EnvironmentName, string> = {
untuva: 'Z1399RU36FG2N9',
hahtuva: 'Z20VS6J64SGAG9',
pallero: 'Z175BBXSKVCV3B',
};

interface ValintojenToteuttaminenStackProps extends cdk.StackProps {
environmentName: string;
environmentName: EnvironmentName;
skipBuild: boolean;
}

const nextJsLogGroupOverrides = (
scope: Construct,
environmentName: EnvironmentName,
appName: string,
): NextjsOverrides => {
return {
nextjsServer: {
functionProps: {
logGroup: new logs.LogGroup(
scope,
'Valintojen Toteuttaminen NextJs Server lambda',
{
logGroupName: `/aws/lambda/${environmentName}-${appName}-nextjs-server`,
},
),
},
},
nextjsStaticAssets: {
nextjsBucketDeploymentProps: {
overrides: {
functionProps: {
logGroup: new logs.LogGroup(
scope,
'Valintojen Toteuttaminen NextJs Static Assets Bucket Deployment lambda',
{
logGroupName: `/aws/lambda/${environmentName}-${appName}-nextjs-static-assets-bucket-deployment`,
},
),
},
},
},
},
nextjsBucketDeployment: {
functionProps: {
logGroup: new logs.LogGroup(
scope,
'Valintojen Toteuttaminen NextJs Bucket Deployment lambda',
{
logGroupName: `/aws/lambda/${environmentName}-${appName}-nextjs-bucket-deployment`,
},
),
},
},
nextjsImage: {
functionProps: {
logGroup: new logs.LogGroup(
scope,
'Valintojen Toteuttaminen NextJs Image lambda',
{
logGroupName: `/aws/lambda/${environmentName}-${appName}-nextjs-image`,
},
),
},
},
nextjsRevalidation: {
insertFunctionProps: {
logGroup: new logs.LogGroup(
scope,
'Valintojen Toteuttaminen NextJs Revalidation Insert lambda',
{
logGroupName: `/aws/lambda/${environmentName}-${appName}-nextjs-revalidation-insert`,
},
),
},
queueFunctionProps: {
logGroup: new logs.LogGroup(
scope,
'Valintojen Toteuttaminen NextJs Revalidation Queue lambda',
{
logGroupName: `/aws/lambda/${environmentName}-${appName}-nextjs-revalidation-queue`,
},
),
},
},
};
};

export class SovellusStack extends cdk.Stack {
constructor(
scope: Construct,
Expand All @@ -18,19 +110,7 @@ export class SovellusStack extends cdk.Stack {
) {
super(scope, id, props);

const publicHostedZones: { [p: string]: string } = {
hahtuva: 'hahtuvaopintopolku.fi',
pallero: 'testiopintopolku.fi',
untuva: 'untuvaopintopolku.fi',
};

const publicHostedZoneIds: { [p: string]: string } = {
hahtuva: 'Z20VS6J64SGAG9',
pallero: 'Z175BBXSKVCV3B',
untuva: 'Z1399RU36FG2N9',
};

const zone = route53.HostedZone.fromHostedZoneAttributes(
const hostedZone = route53.HostedZone.fromHostedZoneAttributes(
this,
'PublicHostedZone',
{
Expand All @@ -46,7 +126,7 @@ export class SovellusStack extends cdk.Stack {
'SiteCertificate',
{
domainName,
hostedZone: zone,
hostedZone,
region: 'us-east-1', // Cloudfront only checks this region for certificates.
},
);
Expand All @@ -67,14 +147,19 @@ export class SovellusStack extends cdk.Stack {
domainProps: {
domainName,
certificate,
hostedZone: zone,
hostedZone,
},
overrides: {
nextjsDistribution: {
distributionProps: {
priceClass: PriceClass.PRICE_CLASS_100,
},
},
...nextJsLogGroupOverrides(
this,
props.environmentName,
'valintojen-toteuttaminen',
),
},
});
new cdk.CfnOutput(this, 'CloudFrontDistributionDomain', {
Expand Down
Loading

0 comments on commit 6edf66f

Please sign in to comment.