Skip to content

Commit 534439a

Browse files
authored
feat: reducing TTL for api requests (#16)
* feat: reducing ttl for api requests * fix: switching from millis to seconds
1 parent 40779a2 commit 534439a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can get a new Serverless UI site deployed to you AWS account in just a few s
4242

4343
1. **AWS Prerequisites**
4444

45-
In order to deploy to AWS, you'll have to setup your machine with locally configured credentials. You'll find the best instructions [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).
45+
In order to deploy to AWS, you'll have to configure your machine with local credentials. You'll find the best instructions [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).
4646

4747
1. **Install the AWS CDK.**
4848

@@ -66,7 +66,7 @@ You can get a new Serverless UI site deployed to you AWS account in just a few s
6666

6767
1. **Deploy your static website**
6868

69-
Next, tell the Serverless UI where to find your website's static files
69+
Finally, tell the Serverless UI where to find your website's static files
7070

7171
```shell
7272
sui deploy --dir="./dist"

packages/construct/src/serverless-ui.construct.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import {
1717
import { IFunction, Runtime } from "@aws-cdk/aws-lambda";
1818
import { NodejsFunction } from "@aws-cdk/aws-lambda-nodejs";
1919
import { BucketDeployment, ISource } from "@aws-cdk/aws-s3-deployment";
20-
import { CfnOutput, Construct, RemovalPolicy } from "@aws-cdk/core";
20+
import {
21+
CfnOutput,
22+
Construct,
23+
Duration,
24+
RemovalPolicy,
25+
Stack,
26+
} from "@aws-cdk/core";
2127
import { Bucket, IBucket } from "@aws-cdk/aws-s3";
2228
import * as path from "path";
2329

@@ -126,14 +132,17 @@ export class ServerlessUI extends Construct {
126132

127133
const originConfigs: SourceConfiguration[] = restApis.map((restApi, i) => ({
128134
customOriginSource: {
129-
//TODO: remove region reference?
130-
domainName: `${restApi.restApiId}.execute-api.us-east-1.amazonaws.com`,
135+
domainName: `${restApi.restApiId}.execute-api.${
136+
Stack.of(this).region
137+
}.amazonaws.com`,
131138
originPath: "/prod",
132139
},
133140
behaviors: [
134141
{
135142
pathPattern: `/api/${functionFiles[i].name}`,
136143
allowedMethods: CloudFrontAllowedMethods.ALL,
144+
maxTtl: Duration.seconds(1),
145+
defaultTtl: Duration.seconds(0),
137146
},
138147
],
139148
}));

0 commit comments

Comments
 (0)