🤖 Merge PR #43696 Added requestId member on all CloudFrontEvent types by @nhodin

* 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
This commit is contained in:
Nicolas Hodin
2020-04-08 11:00:36 -07:00
committed by GitHub
parent cc2ea21db0
commit c72d502e2e
2 changed files with 201 additions and 3 deletions
+3 -3
View File
@@ -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;
};
}
/**
+198
View File
@@ -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"
}
}
}
]
};