Skip to content

Commit c2e85ae

Browse files
authored
Merge pull request #140 from ruby-no-kai/lambda2
lambda: follow up changes
2 parents e6e3369 + 345b044 commit c2e85ae

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@ Detailed docs for RubyKaigi orgz: https://rubykaigi.esa.io/posts/1241
88

99
Deployments are automatically performed on GitHub Actions on `master` branch after CI.
1010

11-
- App Runner: [arn:aws:apprunner:us-west-2:005216166247:service/rko-router/2c9219ae5e14411baaf46fa932f33025](https://us-west-2.console.aws.amazon.com/apprunner/home?region=us-west-2#/services/dashboard?service_arn=arn%3Aaws%3Aapprunner%3Aus-west-2%3A005216166247%3Aservice%2Frko-router%2F2c9219ae5e14411baaf46fa932f33025&active_tab=logs)
11+
- Lambda: [rko-router](https://us-west-2.console.aws.amazon.com/lambda/home?region=us-west-2#/functions/rko-router?tab=monitoring)
12+
- App Runner (deprecated): [arn:aws:apprunner:us-west-2:005216166247:service/rko-router/2c9219ae5e14411baaf46fa932f33025](https://us-west-2.console.aws.amazon.com/apprunner/home?region=us-west-2#/services/dashboard?service_arn=arn%3Aaws%3Aapprunner%3Aus-west-2%3A005216166247%3Aservice%2Frko-router%2F2c9219ae5e14411baaf46fa932f33025&active_tab=logs)
1213
- CloudFront: [arn:aws:cloudfront::005216166247:distribution/E2WEWQCYU12GVD](https://us-east-1.console.aws.amazon.com/cloudfront/v3/home?region=ap-northeast-1#/distributions/E2WEWQCYU12GVD)
1314

14-
All resources except App Runner deployment is managed under Terraform (`./tf`).
15+
All resources except deployment is managed under Terraform [./tf](./tf).
1516

1617
### Domains
1718

18-
Due to the quota of custom domains per App Runner service, the first hop on rko-router proxies a request to itself with correct `Host` header.
19+
Due to the quota of custom domains per App Runner service and the lambda function URL, the first hop on rko-router proxies a request to itself with correct `Host` header. We call this virtual host a _jump host._
1920

2021
`x-rko-host` and `x-rko-xfp` headers are referenced as a `Host` and `X-Forwarded-Proto` header for the second hop.
2122

2223
These custom headers are assigned at CloudFront function (viewer-request) and implementation is at [./tf/cf_functions/src/viewreq.ts](./tf/cf_functions/src/viewreq.ts).
2324

25+
### Cache invalidation
26+
27+
While rubykaigi.org deployment automatically invalidates CloudFront cache on each deployment, rko-router does not.
28+
29+
You need to manually invalidate the cache: https://rubykaigi.esa.io/posts/1241#%E3%82%AD%E3%83%A3%E3%83%83%E3%82%B7%E3%83%A5
30+
2431
## Run locally
2532

2633
```

config/github_pages.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ proxy_hide_header x-served-by;
1111
add_header via "1.1 rko-router.rubykaigi.org";
1212
add_header x-rk-ghp "fi=\"$upstream_http_x_fastly_request_id\",fs=\"$upstream_http_x_served_by\",ghi=\"$upstream_http_x_github_request_id\",cache=\"$upstream_http_x_cache\",cache-hits=\"$upstream_http_x_cache_hits\"";
1313
add_header server-timing "rko-router;dur=$upstream_response_time,$fastly_timer_as_server_timing";
14+
add_header x-server-timing "rko-router;dur=$upstream_response_time,$fastly_timer_as_server_timing";

config/nginx.conf.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,15 @@ http {
192192
set $x_rko_xfp "http";
193193
}
194194

195+
set $x_request_id "$http_x_request_id";
196+
if ( $http_x_request_id = "" ) {
197+
set $x_request_id "$http_x_amz_cf_id";
198+
}
199+
195200
proxy_set_header Host $http_x_rko_host;
196201
proxy_set_header X-Forwarded-Proto $x_rko_xfp;
197202
proxy_set_header x-rko-forwarded "yes";
203+
proxy_set_header x-request-id "$x_request_id";
198204
proxy_pass http://localhost:<%= ENV.fetch("PORT") %>;
199205
}
200206
}

tf/cf_functions/src/viewreq.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ function handler(
1212
request.headers["x-rko-xfp"] = { value: "http" };
1313
}
1414

15-
request.headers["x-request-id"] = { value: context.requestId };
16-
1715
return request;
1816
}

0 commit comments

Comments
 (0)