Skip to content

Instantly share code, notes, and snippets.

@jorovipe97
Created April 15, 2022 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorovipe97/a1d57e9a0e150001989317f509a09ae5 to your computer and use it in GitHub Desktop.
Save jorovipe97/a1d57e9a0e150001989317f509a09ae5 to your computer and use it in GitHub Desktop.
A simple lambda function to test if we can invoke a lambda URL that takes more than 30 seconds
// This dummy function is just to answer the following simple question:
// Do these new AWS Lambda Function URLs still suffer the same timeout issues that the API Gateway does? Namely 30s?
// Answer: According to my local testing I found they dont suffer the 30s limitation, which is pretty amazing.
exports.handler = async (event) => {
console.log(event)
let timeoutSeconds = +event.queryStringParameters.timeout
if (typeof timeoutSeconds !== 'number') {
timeoutSeconds = 40
} else {
// If value is a number...
// Clamp the timeout to lambda max timeout (max 15 minutes)
timeoutSeconds = clamp(timeoutSeconds, 0, 900)
}
console.log('Before timeout!')
await timeout(timeoutSeconds)
console.log('After timeout!')
const response = {
statusCode: 200,
body: JSON.stringify(`Hello from Lambda, after a timeout of ${timeoutSeconds} seconds.`),
};
return response;
};
const timeout = async (seconds) => {
return new Promise((done, reject) => {
setTimeout(function() {
done()
}, seconds * 1000);
})
}
const clamp = (value, min, max) => {
return Math.min(Math.max(value, min), max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment