{"id":19853852,"url":"https://github.com/magnetikonline/edgy","last_synced_at":"2025-05-02T01:30:24.362Z","repository":{"id":143759173,"uuid":"449135218","full_name":"magnetikonline/edgy","owner":"magnetikonline","description":"Harness to assist in authoring tests for Node.js based AWS CloudFront Lambda@Edge functions.","archived":false,"fork":false,"pushed_at":"2024-11-21T01:44:15.000Z","size":100,"stargazers_count":10,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T20:25:07.864Z","etag":null,"topics":["cloudfront","lambda","lambda-edge","npm","testing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@magnetikonline/edgy","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magnetikonline.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-18T04:07:12.000Z","updated_at":"2024-11-21T01:44:18.000Z","dependencies_parsed_at":"2023-09-27T08:54:51.726Z","dependency_job_id":"e9880c55-36f2-40a2-b22b-3cbd9ba418d0","html_url":"https://github.com/magnetikonline/edgy","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fedgy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fedgy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fedgy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fedgy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magnetikonline","download_url":"https://codeload.github.com/magnetikonline/edgy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251782784,"owners_count":21642988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudfront","lambda","lambda-edge","npm","testing"],"created_at":"2024-11-12T14:07:49.235Z","updated_at":"2025-05-02T01:30:23.998Z","avatar_url":"https://github.com/magnetikonline.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Edgy\n\n[![Test](https://github.com/magnetikonline/edgy/actions/workflows/test.yaml/badge.svg)](https://github.com/magnetikonline/edgy/actions/workflows/test.yaml)\n\nA harness to assist in the authoring of tests for Node.js based AWS CloudFront [Lambda@Edge](https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html) functions.\n\n- [Installation](#installation)\n- [What can this do?](#what-can-this-do)\n- [Usage](#usage)\n\t- [ViewerRequest()](#viewerrequest)\n\t- [OriginRequest()](#originrequest)\n\t- [OriginResponse()](#originresponse)\n\t- [ViewerResponse()](#viewerresponse)\n- [Methods](#methods)\n\t- [setDistributionDomainName(name)](#setdistributiondomainnamename)\n\t- [setDistributionId(id)](#setdistributionidid)\n\t- [setRequestId(id)](#setrequestidid)\n\t- [setClientIp(ipAddr)](#setclientipipaddr)\n\t- [setHttpMethod(method)](#sethttpmethodmethod)\n\t- [setQuerystring(qs)](#setquerystringqs)\n\t- [setUri(uri)](#seturiuri)\n\t- [setBody(data[,isTruncated])](#setbodydataistruncated)\n\t- [setRequestHttpHeader(key[,value])](#setrequesthttpheaderkeyvalue)\n\t- [addRequestHttpHeader(key,value)](#addrequesthttpheaderkeyvalue)\n\t- [setOriginCustom(domainName[,path])](#setorigincustomdomainnamepath)\n\t- [setOriginKeepaliveTimeout(timeout)](#setoriginkeepalivetimeouttimeout)\n\t- [setOriginPort(port)](#setoriginportport)\n\t- [setOriginHttps(isHttps)](#setoriginhttpsishttps)\n\t- [setOriginReadTimeout(timeout)](#setoriginreadtimeouttimeout)\n\t- [setOriginSslProtocolList(protocolList)](#setoriginsslprotocollistprotocollist)\n\t- [setOriginS3(domainName[,region][,path])](#setorigins3domainnameregionpath)\n\t- [setOriginOAI(isOAI)](#setoriginoaiisoai)\n\t- [setOriginHttpHeader(key[,value])](#setoriginhttpheaderkeyvalue)\n\t- [addOriginHttpHeader(key,value)](#addoriginhttpheaderkeyvalue)\n\t- [setResponseHttpStatusCode(code)](#setresponsehttpstatuscodecode)\n\t- [setResponseHttpHeader(key[,value])](#setresponsehttpheaderkeyvalue)\n\t- [addResponseHttpHeader(key,value)](#addresponsehttpheaderkeyvalue)\n\t- [execute(handler)](#executehandler)\n- [Reference](#reference)\n\n## Installation\n\n```sh\n$ npm install @magnetikonline/edgy\n```\n\n## What can this do?\n\nEdgy provides the following:\n\n- Generation of Lambda@Edge [event structures](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html) for the four available request life cycle points (viewer request, origin request, origin response, viewer response).\n- Execution of Lambda@Edge functions in a manner _somewhat similar_ to the CloudFront runtime. Both [`async` and older callback style](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html) handlers are supported.\n- Implements various checks and bounds (duck typing) of payloads returned from edge functions, with the [`execute(handler)`](#executehandler) harness function throwing errors for anything deemed to be malformed.\n- Captures the executed Lambda@Edge function payload, allowing for further testing and assertions.\n\n## Usage\n\nEdgy provides four core constructors, which directly relate to each of the [four life cycle points](https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html) available in a CloudFront request. With an instance created, the desired event structure is then crafted and a supplied Lambda@Edge function executed against it.\n\n### `ViewerRequest()`\n\nAn example of crafting a [viewer request](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#example-viewer-request) event payload and executing a dummy function against it:\n\n```js\nconst edgy = require('@magnetikonline/edgy');\n\nasync function myTest() {\n  const vReq = new edgy.ViewerRequest();\n  vReq\n    .setClientIp('1.2.3.4')\n    .setHttpMethod('PUT')\n    .setUri('/path/to/api/route')\n    .addRequestHttpHeader('X-Fancy-Header','apples');\n\n  const resp = await vReq.execute(\n    // example Lambda@Edge function\n    async function(event) {\n      return event.Records[0].cf.request;\n    }\n  );\n\n  console.dir(resp,{ depth: null });\n\n  /*\n  {\n    clientIp: '1.2.3.4',\n    headers: { 'x-fancy-header': [ { key: 'X-Fancy-Header', value: 'apples' } ] },\n    method: 'PUT',\n    querystring: '',\n    uri: '/path/to/api/route'\n  }\n  */\n}\n```\n\nAvailable methods:\n\n- [setDistributionDomainName(name)](#setdistributiondomainnamename)\n- [setDistributionId(id)](#setdistributionidid)\n- [setRequestId(id)](#setrequestidid)\n- [setClientIp(ipAddr)](#setclientipipaddr)\n- [setHttpMethod(method)](#sethttpmethodmethod)\n- [setQuerystring(qs)](#setquerystringqs)\n- [setUri(uri)](#seturiuri)\n- [setBody(data[,isTruncated])](#setbodydataistruncated)\n- [setRequestHttpHeader(key[,value])](#setrequesthttpheaderkeyvalue)\n- [addRequestHttpHeader(key,value)](#addrequesthttpheaderkeyvalue)\n- [execute(handler)](#executehandler)\n\n### `OriginRequest()`\n\nAn example of crafting a [origin request](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#example-origin-request) event payload and executing a dummy function against it:\n\n```js\nconst edgy = require('@magnetikonline/edgy');\n\nasync function myTest() {\n  const oReq = new edgy.OriginRequest();\n  oReq\n    .setClientIp('1.2.3.4')\n    .setHttpMethod('POST')\n    .setUri('/path/to/api/route')\n    .addRequestHttpHeader('X-Fancy-Header','apples')\n    .setOriginS3('mybucket.s3.ap-southeast-2.amazonaws.com','ap-southeast-2');\n\n  const resp = await oReq.execute(\n    // example Lambda@Edge function\n    async function(event) {\n      return event.Records[0].cf.request;\n    }\n  );\n\n  console.dir(resp,{ depth: null });\n\n  /*\n  {\n    clientIp: '1.2.3.4',\n    headers: { 'x-fancy-header': [ { key: 'X-Fancy-Header', value: 'apples' } ] },\n    method: 'POST',\n    querystring: '',\n    uri: '/path/to/api/route',\n    origin: {\n      s3: {\n        authMethod: 'none',\n        customHeaders: {},\n        domainName: 'mybucket.s3.ap-southeast-2.amazonaws.com',\n        path: '',\n        region: 'ap-southeast-2'\n      }\n    }\n  }\n  */\n}\n```\n\nAvailable methods:\n\n- [setDistributionDomainName(name)](#setdistributiondomainnamename)\n- [setDistributionId(id)](#setdistributionidid)\n- [setRequestId(id)](#setrequestidid)\n- [setClientIp(ipAddr)](#setclientipipaddr)\n- [setHttpMethod(method)](#sethttpmethodmethod)\n- [setQuerystring(qs)](#setquerystringqs)\n- [setUri(uri)](#seturiuri)\n- [setBody(data[,isTruncated])](#setbodydataistruncated)\n- [setRequestHttpHeader(key[,value])](#setrequesthttpheaderkeyvalue)\n- [addRequestHttpHeader(key,value)](#addrequesthttpheaderkeyvalue)\n- [setOriginCustom(domainName[,path])](#setorigincustomdomainnamepath)\n- [setOriginKeepaliveTimeout(timeout)](#setoriginkeepalivetimeouttimeout)\n- [setOriginPort(port)](#setoriginportport)\n- [setOriginHttps(isHttps)](#setoriginhttpsishttps)\n- [setOriginReadTimeout(timeout)](#setoriginreadtimeouttimeout)\n- [setOriginSslProtocolList(protocolList)](#setoriginsslprotocollistprotocollist)\n- [setOriginS3(domainName[,region][,path])](#setorigins3domainnameregionpath)\n- [setOriginOAI(isOAI)](#setoriginoaiisoai)\n- [setOriginHttpHeader(key[,value])](#setoriginhttpheaderkeyvalue)\n- [addOriginHttpHeader(key,value)](#addoriginhttpheaderkeyvalue)\n- [execute(handler)](#executehandler)\n\n### `OriginResponse()`\n\nAn example of crafting a [origin response](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-response-origin) event payload and executing a dummy function against it:\n\n```js\nconst edgy = require('@magnetikonline/edgy');\n\nasync function myTest() {\n  const oRsp = new edgy.OriginResponse();\n  oRsp\n    .setResponseHttpStatusCode(202)\n    .addResponseHttpHeader('X-Fancy-Header','oranges');\n\n  const resp = await oRsp.execute(\n    // example Lambda@Edge function\n    async function(event) {\n      return event.Records[0].cf.response;\n    }\n  );\n\n  console.dir(resp,{ depth: null });\n\n  /*\n  {\n    headers: { 'x-fancy-header': [ { key: 'X-Fancy-Header', value: 'oranges' } ] },\n    status: '202',\n    statusDescription: 'Accepted'\n  }\n  */\n}\n```\n\nAvailable methods:\n\n- [setDistributionDomainName(name)](#setdistributiondomainnamename)\n- [setDistributionId(id)](#setdistributionidid)\n- [setRequestId(id)](#setrequestidid)\n- [setClientIp(ipAddr)](#setclientipipaddr)\n- [setHttpMethod(method)](#sethttpmethodmethod)\n- [setQuerystring(qs)](#setquerystringqs)\n- [setUri(uri)](#seturiuri)\n- [setRequestHttpHeader(key[,value])](#setrequesthttpheaderkeyvalue)\n- [addRequestHttpHeader(key,value)](#addrequesthttpheaderkeyvalue)\n- [setOriginCustom(domainName[,path])](#setorigincustomdomainnamepath)\n- [setOriginKeepaliveTimeout(timeout)](#setoriginkeepalivetimeouttimeout)\n- [setOriginPort(port)](#setoriginportport)\n- [setOriginHttps(isHttps)](#setoriginhttpsishttps)\n- [setOriginReadTimeout(timeout)](#setoriginreadtimeouttimeout)\n- [setOriginSslProtocolList(protocolList)](#setoriginsslprotocollistprotocollist)\n- [setOriginS3(domainName[,region][,path])](#setorigins3domainnameregionpath)\n- [setOriginOAI(isOAI)](#setoriginoaiisoai)\n- [setOriginHttpHeader(key[,value])](#setoriginhttpheaderkeyvalue)\n- [addOriginHttpHeader(key,value)](#addoriginhttpheaderkeyvalue)\n- [setResponseHttpStatusCode(code)](#setresponsehttpstatuscodecode)\n- [setResponseHttpHeader(key[,value])](#setresponsehttpheaderkeyvalue)\n- [addResponseHttpHeader(key,value)](#addresponsehttpheaderkeyvalue)\n- [execute(handler)](#executehandler)\n\n### `ViewerResponse()`\n\nAn example of crafting a [viewer response](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-response-viewer) event payload and executing a dummy function against it:\n\n```js\nconst edgy = require('@magnetikonline/edgy');\n\nasync function myTest() {\n  const vRsp = new edgy.ViewerResponse();\n  vRsp\n    .setResponseHttpStatusCode(304)\n    .addResponseHttpHeader('X-Fancy-Header','oranges');\n\n  const resp = await vRsp.execute(\n    // example Lambda@Edge function\n    async function(event) {\n      return event.Records[0].cf.response;\n    }\n  );\n\n  console.dir(resp,{ depth: null });\n\n  /*\n  {\n    headers: { 'x-fancy-header': [ { key: 'X-Fancy-Header', value: 'oranges' } ] },\n    status: '304',\n    statusDescription: 'Not Modified'\n  }\n  */\n}\n```\n\nAvailable methods:\n\n- [setDistributionDomainName(name)](#setdistributiondomainnamename)\n- [setDistributionId(id)](#setdistributionidid)\n- [setRequestId(id)](#setrequestidid)\n- [setClientIp(ipAddr)](#setclientipipaddr)\n- [setHttpMethod(method)](#sethttpmethodmethod)\n- [setQuerystring(qs)](#setquerystringqs)\n- [setUri(uri)](#seturiuri)\n- [setRequestHttpHeader(key[,value])](#setrequesthttpheaderkeyvalue)\n- [addRequestHttpHeader(key,value)](#addrequesthttpheaderkeyvalue)\n- [setResponseHttpStatusCode(code)](#setresponsehttpstatuscodecode)\n- [setResponseHttpHeader(key[,value])](#setresponsehttpheaderkeyvalue)\n- [addResponseHttpHeader(key,value)](#addresponsehttpheaderkeyvalue)\n- [execute(handler)](#executehandler)\n\n## Methods\n\n### `setDistributionDomainName(name)`\n\n### `setDistributionId(id)`\n\n### `setRequestId(id)`\n\nMethods to set properties related to the CloudFront distribution:\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\nharness\n  .setDistributionDomainName('d111111abcdef8.cloudfront.net')\n  .setDistributionId('EDFDVBD6EXAMPLE')\n  .setRequestId('4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==');\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        config: {\n          distributionDomainName: 'd111111abcdef8.cloudfront.net',\n          distributionId: 'EDFDVBD6EXAMPLE',\n          requestId: '4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ=='\n        }\n      }\n    }\n  ]\n}\n*/\n```\n\n### `setClientIp(ipAddr)`\n\n### `setHttpMethod(method)`\n\n### `setQuerystring(qs)`\n\n### `setUri(uri)`\n\nMethods to set general properties related to the request sent from the client:\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\nharness\n  .setClientIp('203.0.113.178')\n  .setHttpMethod('GET')\n  .setQuerystring('?key=value')\n  .setUri('/path/to/route');\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        request: {\n          clientIp: '203.0.113.178',\n          method: 'GET',\n          querystring: 'key=value',\n          uri: '/path/to/route'\n        }\n      }\n    }\n  ]\n}\n*/\n```\n\n### `setBody(data[,isTruncated])`\n\nAdds a collection of request `body` properties. The given `data` will be automatically `base64` encoded:\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\nharness.setBody('data payload',false);\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        request: {\n          body: {\n            action: 'read-only',\n            data: 'ZGF0YSBwYXlsb2Fk',\n            encoding: 'base64',\n            inputTruncated: false\n          }\n        }\n      }\n    }\n  ]\n}\n*/\n```\n\n### `setRequestHttpHeader(key[,value])`\n### `addRequestHttpHeader(key,value)`\n\nSets/adds HTTP headers to the request payload:\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\nharness\n  .addRequestHttpHeader('User-Agent','curl/8.4.0')\n  .addRequestHttpHeader('X-Custom-Header','apples')\n  .addRequestHttpHeader('X-Custom-Header','oranges');\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        request: {\n          headers: {\n            'user-agent': [ { key: 'User-Agent', value: 'curl/8.4.0' } ],\n            'x-custom-header': [\n              { key: 'X-Custom-Header', value: 'apples' },\n              { key: 'X-Custom-Header', value: 'oranges' }\n            ]\n          }\n        }\n      }\n    }\n  ]\n}\n*/\n\nharness\n  .setRequestHttpHeader('User-Agent','xyz')\n  .setRequestHttpHeader('X-Custom-Header'); // remove HTTP header\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        request: {\n          headers: {\n            'user-agent': [ { key: 'User-Agent', value: 'xyz' } ]\n          }\n        }\n      }\n    }\n  ]\n}\n*/\n```\n\n### `setOriginCustom(domainName[,path])`\n\n### `setOriginKeepaliveTimeout(timeout)`\n\n### `setOriginPort(port)`\n\n### `setOriginHttps(isHttps)`\n\n### `setOriginReadTimeout(timeout)`\n\n### `setOriginSslProtocolList(protocolList)`\n\nMethods to define a custom origin property set for the request event payload:\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\nharness\n  .setOriginCustom('example.org','/custom/origin/path')\n  .setOriginKeepaliveTimeout(35)\n  .setOriginPort(1234)\n  .setOriginHttps(true)\n  .setOriginReadTimeout(25)\n  .setOriginSslProtocolList(['TLSv1.1','TLSv1.2']);\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        request: {\n          origin: {\n            custom: {\n              customHeaders: {},\n              domainName: 'example.org',\n              keepaliveTimeout: 35,\n              path: '/custom/origin/path',\n              port: 1234,\n              protocol: 'https',\n              readTimeout: 25,\n              sslProtocols: [ 'TLSv1.1', 'TLSv1.2' ]\n            }\n          }\n        }\n      }\n    }\n  ]\n}\n*/\n```\n\n### `setOriginS3(domainName[,region][,path])`\n\n### `setOriginOAI(isOAI)`\n\nMethods to define an S3 origin property set for the request event payload:\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\nharness\n  .setOriginS3(\n    'mybucket.s3.ap-southeast-2.amazonaws.com',\n    'ap-southeast-2',\n    '/s3/bucket/path')\n  .setOriginOAI(true);\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        request: {\n          origin: {\n            s3: {\n              authMethod: 'origin-access-identity',\n              customHeaders: {},\n              domainName: 'mybucket.s3.ap-southeast-2.amazonaws.com',\n              path: '/s3/bucket/path',\n              region: 'ap-southeast-2'\n            }\n          }\n        }\n      }\n    }\n  ]\n}\n*/\n```\n\n### `setOriginHttpHeader(key[,value])`\n### `addOriginHttpHeader(key,value)`\n\nSets/adds HTTP headers to the origin request payload for [custom](#setorigincustomdomainnamepath) and [S3](#setorigins3domainnameregionpath) targets:\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\nharness\n  .setOriginS3(\n    'mybucket.s3.ap-southeast-2.amazonaws.com',\n    'ap-southeast-2',\n    '/s3/bucket/path')\n  .addOriginHttpHeader('X-Custom-Header','apples')\n  .addOriginHttpHeader('X-Custom-Header','oranges');\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        request: {\n          origin: {\n            s3: {\n              customHeaders: {\n                'x-custom-header': [\n                  { key: 'X-Custom-Header', value: 'apples' },\n                  { key: 'X-Custom-Header', value: 'oranges' }\n                ]\n              }\n            }\n          }\n        }\n      }\n    }\n  ]\n}\n*/\n\nharness.setOriginHttpHeader('X-Custom-Header'); // remove HTTP header\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        request: {\n          origin: {\n            s3: {\n              customHeaders: {}\n            }\n          }\n        }\n      }\n    }\n  ]\n}\n*/\n```\n\n### `setResponseHttpStatusCode(code)`\n### `setResponseHttpHeader(key[,value])`\n### `addResponseHttpHeader(key,value)`\n\nMethods to set properties related to the response received from the upstream CloudFront target:\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\nharness\n  .setResponseHttpStatusCode(304)\n  .addResponseHttpHeader('X-Fancy-Header','oranges');\n\n/*\n{\n  Records: [\n    {\n      cf: {\n        response: {\n          headers: {\n            'x-fancy-header': [ { key: 'X-Fancy-Header', value: 'oranges' } ]\n          },\n          status: '304',\n          statusDescription: 'Not Modified'\n        }\n      }\n    }\n  ]\n}\n*/\n```\n\n### `execute(handler)`\n\nExecutes a Lambda@Edge function, passing a constructed event payload. Supports both [`async` and older callback style](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html) function handlers.\n\nAfter successful execution:\n\n- A series of validations are performed against the returned payload, verifying _it should_ be a usable response for CloudFront to accept. In _no way_ consider this to be comprehensive or complete - but should catch many obvious malformed payloads.\n- Return the transformed payload from the executed Lambda@Edge function, where additional assertions can then be performed.\n\n```js\nconst harness = new edgy.EVENT_TYPE_CONSTRUCTOR();\n\n// -- construct event payload using instance methods --\n// .setHttpMethod()\n// .setUri()\n// .setQuerystring()\n// etc.\n\n// execute function against payload\nconst resp = await harness.execute(\n  // example Lambda@Edge function\n  async function(event) {\n    return event.Records[0].cf.response;\n  }\n);\n```\n\n## Reference\n\n- [Using AWS Lambda with CloudFront Lambda@Edge](https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html)\n- [Lambda@Edge event structure](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html)\n- [Restrictions on edge functions](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-restrictions.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagnetikonline%2Fedgy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagnetikonline%2Fedgy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagnetikonline%2Fedgy/lists"}