This will return the IPv4 or IPv6 address of the client making the GET
request to the domain you specified when making
the CloudFront distribution. If you add an Accept
header with application/json
present, it will return an json-parseable
object like { "ip": "127.0.0.1" }
, but if not specified or text/plain
appears before application/json
, it will
default to text/plain
and just return the IP address like 127.0.0.1
(following standard handling of Accept
headers).
- Add the source of
index.js
to your AWS account- This file is written with speed in mind. Lambda@Edge tends to bounce execution around between different workers,
which means you'll encounter lots of cold-starts. Not being able to rely on V8's JIT to make your oh-so-pretty code
fast, some V8 optimization tricks are worth employing (
var
is still faster thanlet
andconst
, andfunction
s are faster than arrows() => {}
)
- This file is written with speed in mind. Lambda@Edge tends to bounce execution around between different workers,
which means you'll encounter lots of cold-starts. Not being able to rely on V8's JIT to make your oh-so-pretty code
fast, some V8 optimization tricks are worth employing (
- Configure it as you like (i.e. amount of memory (I use
1024mb
which is hella excessive) - Create a Cloudfront distribution, set it up as you'd like
- Have the default origin point to an empty, dummy S3 bucket (we won't be using this as this is purely ran by Lambda, but we need an origin to bind a behavior to)
- Viewer Protocol Policy:
Redirect HTTP to HTTPS
- Allowed HTTP Methods:
GET, HEAD
- Cache and origin request settings:
Use a cache policy and origin request policy
- Cache Policy: see Cache Policy below
- Origin Request Policy: see Origin Request Policy below
- Compress Objects Automatically:
Yes
- Lambda Function Associations:
Origin Request
and put the Lamba function you created's ARN in, hit the plus button
- Deploy and you're done!
- TTL Settings (set these to whatever you're comfortable with
- Headers:
Whitelist
Accept
X-Forwarded-For
you have to manually enter this one
- Cookies:
None
- Query strings:
None
- Compression Support:
Gzip
andBrotli
because why not?
- Headers:
Whitelist
Accept
X-Forwarded-For
you have to manually enter this one
- Cookies:
None
- Query strings:
None