Serverless Next.js Constructの戻り値から上書きする
● LambdaやCloudFrontの設定は
上書き可能
● TypeScriptなどの型付き言語は、
定義を追いかけて調査しやすい
● 「一部だけ変更」は難しそう
● cdk synthでCFNスタックを
出力し、初期値を調査する方式
● Amplifyより手間だけど、
触れる範囲と柔軟性は上
30
AWS CDK Conference Japan 2022
https://github.com/serverless-nextjs/serverless-next.js
import { Stack, StackProps, CfnOutput, Duration } from 'aws-cdk-lib';
import { NextJSLambdaEdge } from "@sls-next/cdk-construct";
import { CachePolicy, CacheQueryStringBehavior, CacheHeaderBehavior } from
'aws-cdk-lib/aws-cloudfront';
// 中略
const app = new NextJSLambdaEdge(this, "App", { serverlessBuildOutDir: "./build"});
app.nextLambdaCachePolicy = new CachePolicy(this, "NextLambdaCache", {
queryStringBehavior: CacheQueryStringBehavior.all(),
headerBehavior: CacheHeaderBehavior.allowList("Authorization", "Origin"),
cookieBehavior: {
behavior: 'all'
},
defaultTtl: Duration.seconds(0),
maxTtl: Duration.days(365),
minTtl: Duration.seconds(0),