export class AstroStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const curiostaCert = Certificate.fromCertificateArn(
this,
"curiostaCert",
"arn:aws:acm:us-east-1:615256776167:certificate/47567bde-9915-4b69-9274-8b0f271def89"
);
const cachePolicy = new CachePolicy(this, "curiostaCachePolicy", {
maxTtl: Duration.days(365),
minTtl: Duration.seconds(5),
defaultTtl: Duration.minutes(15),
// queryStringBehavior: CacheQueryStringBehavior.allowList(),
});
const astroAws = new AstroAWS(this, "curiosta-website", {
websiteDir: "../",
output: "server",
cdk: {
cloudfrontDistribution: {
domainNames: ["curiosta.com"],
certificate: curiostaCert,
defaultBehavior: {
cachePolicy: cachePolicy,
},
},
lambdaFunction: {
environment: {
PUBLIC_BASE_URL: "https://store.curiosta.com",
},
},
},
});
const curiostaHostedZone = HostedZone.fromLookup(
this,
"curiostaHostedZone",
{
domainName: "curiosta.com",
}
);
new ARecord(this, "domain-alias", {
zone: curiostaHostedZone,
recordName: "curiosta.com",
target: RecordTarget.fromAlias(
new CloudFrontTarget(astroAws.cdk.cloudfrontDistribution)
),
});
if (!astroAws.cdk.lambdaFunction) {
throw Error("Unable to get lambda ref");
}
new CfnOutput(this, "WebsiteDomain", {
value: astroAws.cdk.cloudfrontDistribution.distributionDomainName,
});
}
}