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" + } + } + } + ] +};