UNPKG

2.24 kBTypeScriptView Raw
1/**
2 * CloudFront events
3 * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html
4 * Bear in mind that the "example" event structure in the page above includes
5 * both an S3 and a Custom origin, which is not strictly allowed. Only one
6 * of these per event may be present.
7 */
8export interface CloudFrontHeaders {
9 [name: string]: Array<{
10 key?: string;
11 value: string;
12 }>;
13}
14
15export type CloudFrontOrigin =
16 | { s3: CloudFrontS3Origin; custom?: never }
17 | { custom: CloudFrontCustomOrigin; s3?: never };
18
19export interface CloudFrontCustomOrigin {
20 customHeaders: CloudFrontHeaders;
21 domainName: string;
22 keepaliveTimeout: number;
23 path: string;
24 port: number;
25 protocol: 'http' | 'https';
26 readTimeout: number;
27 sslProtocols: string[];
28}
29
30export interface CloudFrontS3Origin {
31 authMethod: 'origin-access-identity' | 'none';
32 customHeaders: CloudFrontHeaders;
33 domainName: string;
34 path: string;
35 region: string;
36}
37
38export interface CloudFrontResponse {
39 status: string;
40 statusDescription: string;
41 headers: CloudFrontHeaders;
42}
43
44export interface CloudFrontRequest {
45 body?: {
46 action: 'read-only' | 'replace';
47 data: string;
48 encoding: 'base64' | 'text';
49 readonly inputTruncated: boolean;
50 };
51 readonly clientIp: string;
52 readonly method: string;
53 uri: string;
54 querystring: string;
55 headers: CloudFrontHeaders;
56 origin?: CloudFrontOrigin;
57}
58
59export interface CloudFrontEvent {
60 config: {
61 readonly distributionDomainName: string;
62 readonly distributionId: string;
63 readonly eventType: 'origin-request' | 'origin-response' | 'viewer-request' | 'viewer-response';
64 readonly requestId: string;
65 };
66}
67
68/**
69 * Generated HTTP response in viewer request event or origin request event
70 *
71 * https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-generating-http-responses-in-requests.html#lambda-generating-http-responses-object
72 */
73export interface CloudFrontResultResponse {
74 status: string;
75 statusDescription?: string;
76 headers?: CloudFrontHeaders;
77 bodyEncoding?: 'text' | 'base64';
78 body?: string;
79}