Created
April 15, 2022 17:07
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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