INNER CODE UNIT · JavaScript

sendResponse

middyjs/middy · packages/cloudformation-response/index.js:127

const sendResponse = async (url, response, context) => {
	// The response goes to a presigned S3 URL, which is always https. Anything
	// else would send the body, and with it the stack's ids, elsewhere.
	const protocol = URL.parse(url)?.protocol;
	if (protocol !== "https:") {
		throw new Error(`${pkg}: ResponseURL must be an https URL`, {
			cause: { package: pkg, data: { protocol } },
		});
	}
	const body = serialize(response);
	// A PUT that hangs past the invocation would be cut off by Lambda without
	// a response; abort it 500 ms early instead so the failure is logged.
	// Outside Lambda (no remaining-time budget) allow 30 s.
	const budget = (context.getRemainingTimeInMillis?.() ?? 30_000) - 500;
	// The presigned URL was signed with an empty content type, so any other
	// value fails the bucket's signature check (same as the cfn-response module).
	// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-lambda-function-code-cfnresponsemodule.html
	const res = await fetch(url, {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…