If a requestに「matches the statement」を選択 ※上記以外にAND, OR, NOT の条件が作成可。例えば、IP set とヘッダ,クエリやURI Pathの指定がAND条件で一致するなど。
Statement を設定する。
Inspectに「Original from an IP address in」、IP setに先ほど作成したIP setを選択
IP address to use as the originating addressに「Source IP address」を選択 ※アクセスの経路にプロキシがある場合は、「IP address in header」の「X-Forwarded-For」を指定する。
ActionのActionに「Allow」を選択
「Add Rule」を選択
Set rule priority にて、priority を設定。「Save」を選択します。
CloudFront に対する疎通テスト
許可されているIPアドレスからテストします。
niikawa@niikawa1:~$ curl https://d1vmj58jrb59di.cloudfront.net/dev
"Hello from Lambda!"
許可されていないIPアドレスからテストします。
niikawa@niikawa1:~$ curl https://d1vmj58jrb59di.cloudfront.net/dev
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Request blocked.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: __4vWtfwz9QJ9FNbORhVE9mF44fHcNKG06W3wTjIHctCVAXRedUAjQ==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>