From c72d502e2e339e17f374842977c78a8b18bc4e0c Mon Sep 17 00:00:00 2001 From: Nicolas Hodin Date: Wed, 8 Apr 2020 20:00:36 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#43696=20Added=20re?= =?UTF-8?q?questId=20member=20on=20all=20CloudFrontEvent=20types=20by=20@n?= =?UTF-8?q?hodin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added requestId member on all CloudFrontEvent types The requestId member is defined on all origin/viewer requests/responses, it is described here : https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html There is one example for each request/response and they all have a cf.config.requestId. Added new requests examples in tests in order to have all 4 types available * Fix lint issue with consecutive empty lines * Fix missing spaces --- types/aws-lambda/common/cloudfront.d.ts | 6 +- types/aws-lambda/test/cloudfront-tests.ts | 198 ++++++++++++++++++++++ 2 files changed, 201 insertions(+), 3 deletions(-) diff --git a/types/aws-lambda/common/cloudfront.d.ts b/types/aws-lambda/common/cloudfront.d.ts index f0ebbae8f5..1270347899 100644 --- a/types/aws-lambda/common/cloudfront.d.ts +++ b/types/aws-lambda/common/cloudfront.d.ts @@ -60,9 +60,9 @@ export interface CloudFrontEvent { config: { readonly distributionDomainName: string; readonly distributionId: string; - } & ( - | { readonly eventType: 'origin-request' | 'origin-response' } - | { readonly eventType: 'viewer-request' | 'viewer-response'; readonly requestId: string }); + readonly eventType: 'origin-request' | 'origin-response' | 'viewer-request' | 'viewer-response'; + readonly requestId: string; + }; } /** diff --git a/types/aws-lambda/test/cloudfront-tests.ts b/types/aws-lambda/test/cloudfront-tests.ts index 5b141ae205..269102881b 100644 --- a/types/aws-lambda/test/cloudfront-tests.ts +++ b/types/aws-lambda/test/cloudfront-tests.ts @@ -277,3 +277,201 @@ const responseEvent: CloudFrontResponseEvent = { }, ], }; + +const originRequestEvent: CloudFrontRequestEvent = { + Records: [ + { + cf: { + config: { + distributionDomainName: "d111111abcdef8.cloudfront.net", + distributionId: "EDFDVBD6EXAMPLE", + eventType: "origin-request", + requestId: "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + request: { + clientIp: "203.0.113.178", + headers: { + "x-forwarded-for": [ + { + key: "X-Forwarded-For", + value: "203.0.113.178" + } + ], + "user-agent": [ + { + key: "User-Agent", + value: "Amazon CloudFront" + } + ], + via: [ + { + key: "Via", + value: + "2.0 2afae0d44e2540f472c0635ab62c232b.cloudfront.net (CloudFront)" + } + ], + host: [ + { + key: "Host", + value: "example.org" + } + ], + "cache-control": [ + { + key: "Cache-Control", + value: "no-cache, cf-no-cache" + } + ] + }, + method: "GET", + origin: { + custom: { + customHeaders: {}, + domainName: "example.org", + keepaliveTimeout: 5, + path: "", + port: 443, + protocol: "https", + readTimeout: 30, + sslProtocols: ["TLSv1", "TLSv1.1", "TLSv1.2"] + } + }, + querystring: "", + uri: "/" + } + } + } + ] +}; + +const originResponseEvent: CloudFrontResponseEvent = { + Records: [ + { + cf: { + config: { + distributionDomainName: "d111111abcdef8.cloudfront.net", + distributionId: "EDFDVBD6EXAMPLE", + eventType: "origin-response", + requestId: "4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==" + }, + request: { + clientIp: "203.0.113.178", + headers: { + "x-forwarded-for": [ + { + key: "X-Forwarded-For", + value: "203.0.113.178" + } + ], + "user-agent": [ + { + key: "User-Agent", + value: "Amazon CloudFront" + } + ], + via: [ + { + key: "Via", + value: + "2.0 8f22423015641505b8c857a37450d6c0.cloudfront.net (CloudFront)" + } + ], + host: [ + { + key: "Host", + value: "example.org" + } + ], + "cache-control": [ + { + key: "Cache-Control", + value: "no-cache, cf-no-cache" + } + ] + }, + method: "GET", + origin: { + custom: { + customHeaders: {}, + domainName: "example.org", + keepaliveTimeout: 5, + path: "", + port: 443, + protocol: "https", + readTimeout: 30, + sslProtocols: ["TLSv1", "TLSv1.1", "TLSv1.2"] + } + }, + querystring: "", + uri: "/" + }, + response: { + headers: { + "access-control-allow-credentials": [ + { + key: "Access-Control-Allow-Credentials", + value: "true" + } + ], + "access-control-allow-origin": [ + { + key: "Access-Control-Allow-Origin", + value: "*" + } + ], + date: [ + { + key: "Date", + value: "Mon, 13 Jan 2020 20:12:38 GMT" + } + ], + "referrer-policy": [ + { + key: "Referrer-Policy", + value: "no-referrer-when-downgrade" + } + ], + server: [ + { + key: "Server", + value: "ExampleCustomOriginServer" + } + ], + "x-content-type-options": [ + { + key: "X-Content-Type-Options", + value: "nosniff" + } + ], + "x-frame-options": [ + { + key: "X-Frame-Options", + value: "DENY" + } + ], + "x-xss-protection": [ + { + key: "X-XSS-Protection", + value: "1; mode=block" + } + ], + "content-type": [ + { + key: "Content-Type", + value: "text/html; charset=utf-8" + } + ], + "content-length": [ + { + key: "Content-Length", + value: "9593" + } + ] + }, + status: "200", + statusDescription: "OK" + } + } + } + ] +};