Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ Detailed docs for RubyKaigi orgz: https://rubykaigi.esa.io/posts/1241

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

- 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)
- Lambda: [rko-router](https://us-west-2.console.aws.amazon.com/lambda/home?region=us-west-2#/functions/rko-router?tab=monitoring)
- 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)
- CloudFront: [arn:aws:cloudfront::005216166247:distribution/E2WEWQCYU12GVD](https://us-east-1.console.aws.amazon.com/cloudfront/v3/home?region=ap-northeast-1#/distributions/E2WEWQCYU12GVD)

All resources except App Runner deployment is managed under Terraform (`./tf`).
All resources except deployment is managed under Terraform [./tf](./tf).

### Domains

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.
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._

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

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).

### Cache invalidation

While rubykaigi.org deployment automatically invalidates CloudFront cache on each deployment, rko-router does not.

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

## Run locally

```
Expand Down
1 change: 1 addition & 0 deletions config/github_pages.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ proxy_hide_header x-served-by;
add_header via "1.1 rko-router.rubykaigi.org";
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\"";
add_header server-timing "rko-router;dur=$upstream_response_time,$fastly_timer_as_server_timing";
add_header x-server-timing "rko-router;dur=$upstream_response_time,$fastly_timer_as_server_timing";
6 changes: 6 additions & 0 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,15 @@ http {
set $x_rko_xfp "http";
}

set $x_request_id "$http_x_request_id";
if ( $http_x_request_id = "" ) {
set $x_request_id "$http_x_amz_cf_id";
}

proxy_set_header Host $http_x_rko_host;
proxy_set_header X-Forwarded-Proto $x_rko_xfp;
proxy_set_header x-rko-forwarded "yes";
proxy_set_header x-request-id "$x_request_id";
proxy_pass http://localhost:<%= ENV.fetch("PORT") %>;
}
}
Expand Down
2 changes: 0 additions & 2 deletions tf/cf_functions/src/viewreq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ function handler(
request.headers["x-rko-xfp"] = { value: "http" };
}

request.headers["x-request-id"] = { value: context.requestId };

return request;
}