LoginSignup
2
0

More than 1 year has passed since last update.

App Runner に VPN 経由でオンプレミスからアクセスしてみた

Posted at

はじめに

2022 年 11 月に、AWS App Runner が Amazon VPC 内に閉じたアクセスをサポートするようになりました。

このアップデート以前は、App Runner にアクセスするときはインターネットに公開されたエンドポイントにアクセスする必要がありました。このアップデートにより、インターネットは経由せず VPC に閉じた形でアクセスができるようになります。また、Site-to-Site VPN や DirectConnect をオンプレミスと接続することで、プライベートなネットワーク経由で App Runner にアクセスすることも出来ます。

今回の記事では、Site-to-Site VPN 経由で App Runner にアクセスする方法を紹介します。

構成図

この構成図を検証していきます。Site-to-Site VPN は既に接続している前提で記事を作っています。

  • App Runner を設定するときに、VPC Endpoint を設定可能
  • オンプレミスから App Runner にアクセスするときには、Private Subnet に作成された VPC Endpoint 経由でアクセスする

image-20230226162301118.png

App Runner Service 作成

それでは、簡単に App Runner を作成していきます。Create Service を押します。

image-20230226155417727.png

動かすアプリケーションはなんでもいいので、ECR Public にホストされている Nginx イメージを利用します。

public.ecr.aws/nginx/nginx:latest 

image-20230226155449334.png

適当に名前やリソースなどを指定します。

image-20230226155602635.png

このスクリーンショットはデフォルトのままです。余談ですが、App Runner で WAF が使えるようになっています。

image-20230226155629082.png

Incoming network traffic を Private endpoint にすることで、VPC 内に閉じたエンドポイントが作成できます。VPC に加えて、Site-to-Site VPN や DirectConnect 経由でオンプレミスからアクセスもできます。

image-20230226155749906.png

適当に Endpoint の名前や、Subnet を指定します。

image-20230226155938798.png

Confirm を押します。

image-20230226160000880.png

App Runner の画面で Endpoint を作成しました。その裏側では、VPC Endpoint が自動的に作成されています。

image-20230226160143305.png

App Runner の画面に戻り、Outgoing network traffic を指定します。

image-20230226160215925.png

Next

image-20230226160232328.png

Create を押して、デプロイをします。

image-20230226160256095.png

Deploy が開始されます。一定時間後に、Status が Running に変わります。

image-20230226160406036.png

オンプレミスから App Runner にアクセス確認

これで設定が完了です。オンプレミスから Site-to-Site VPN 経由で、App Runner にアクセスしてみましょう。

image-20230226163956816.png

App Runner で作成した Service のドメインを確認します。

image-20230226163920905.png

このドメインを名前解決してみましょう。AWS 側にある Private Subnet 上の IP アドレスが 3 つ返ってきます。

[ec2-user@ip-192-168-0-184 ~]$ dig 52unqahbq5.ap-northeast-1.awsapprunner.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.amzn2.4 <<>> 52unqahbq5.ap-northeast-1.awsapprunner.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56212
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;52unqahbq5.ap-northeast-1.awsapprunner.com. IN A

;; ANSWER SECTION:
52unqahbq5.ap-northeast-1.awsapprunner.com. 60 IN A 10.0.102.40
52unqahbq5.ap-northeast-1.awsapprunner.com. 60 IN A 10.0.100.160
52unqahbq5.ap-northeast-1.awsapprunner.com. 60 IN A 10.0.101.180

;; Query time: 2 msec
;; SERVER: 192.168.0.2#53(192.168.0.2)
;; WHEN: Sun Feb 26 07:39:25 UTC 2023
;; MSG SIZE  rcvd: 119

オンプレミスのマシンから、curl でアクセスしてみます。無事に Nginx の画面が返ってきています。

[ec2-user@ip-192-168-0-184 ~]$ curl https://52unqahbq5.ap-northeast-1.awsapprunner.com
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

関係ないマシンから、このドメインにアクセスしてみます。想定通り、App Runner の Endpoint に接続が出来ません。

> curl -v https://52unqahbq5.ap-northeast-1.awsapprunner.com
*   Trying 10.0.101.180:443...
* TCP_NODELAY set

オンプレミスから Site-to-Site VPN 経由でアクセスができました。今回は試していませんが、DirectConnect 経由でも正常にアクセスが出来ます。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0