Skip to content

Instantly share code, notes, and snippets.

@mikeal
Created July 25, 2020 03:34
Show Gist options
  • Save mikeal/3e7916662c0389ca8f3fc37925bcf11b to your computer and use it in GitHub Desktop.
Save mikeal/3e7916662c0389ca8f3fc37925bcf11b to your computer and use it in GitHub Desktop.
const publicIp = require('public-ip')
const bent = require('bent')
const get = bent('json', 'https://my-lambda-url')
exports.handler = async function http (req) {
let { retries, ips } = req.queryStringParameters
const ip = await publicIp.v4()
if (ips) ips = ips.split(',')
else ips = []
ips.push(ip)
retries = parseInt(retries)
if (retries) {
ips = await get(`?retries=${retries-1}&ips=${ips.join(',')}`)
}
return {
headers: {
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0',
'content-type': 'application/json'
},
body: JSON.stringify(ips, null, 2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment