Created
October 16, 2018 22:27
-
-
Save prenagha/886c44526c7e9b1bc9e904900687f6b0 to your computer and use it in GitHub Desktop.
Lambda@Edge CloudFront Debugging Sample Records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"callbackWaitsForEmptyEventLoop":true, | |
"logGroupName":"/aws/lambda/us-east-1.DebugEvent", | |
"logStreamName":"2018/10/16/zzz", | |
"functionName":"us-east-1.DebugEvent", | |
"memoryLimitInMB":"128", | |
"functionVersion":"2", | |
"invokeid":"ad19fdb1-zzz-zzz-zzz-zzz", | |
"awsRequestId":"ad19fdb1-zzz-zzz-zzz-zzz", | |
"invokedFunctionArn":"arn:aws:lambda:us-east-1:zzz:function:us-east-1.DebugEvent:2" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Lambda@Edge to log CloudFront event and context. | |
* Note: this runs in Lambda@Edge which means it runs in a variety | |
* of regions, the region closest to the browser making the request. | |
* So be sure and check other regions if you don't see the logs in | |
* CloudWatch in the region you normally use. | |
* | |
* https://medium.com/@jbesw/postcards-from-lambda-the-edge-11a43f215dc1 | |
* | |
*/ | |
exports.handler = (event, context, callback) => { | |
const eventType = event.Records[0].cf.config.eventType; | |
// Log JSON of the event and context if available to console which | |
// will end up in CloudWatch | |
console.log('DebugEvent ' + eventType | |
+ ' -- ' + JSON.stringify(event) | |
+ ' -- context -- ' + JSON.stringify(context) | |
); | |
const responseEvent = eventType.indexOf('-response') > 0; | |
// Response back to CloudFront and let the HTTP request continue | |
callback(null, | |
(responseEvent ? | |
event.Records[0].cf.response : event.Records[0].cf.request)); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Records":[ | |
{ | |
"cf":{ | |
"config":{ | |
"distributionDomainName":"d1zzzlmt.cloudfront.net", | |
"distributionId":"E1zzzGZ", | |
"eventType":"origin-request" | |
}, | |
"request":{ | |
"clientIp":"2607:zzz:1812:zzz:c06e:zzz:99e7:da29", | |
"headers":{ | |
"user-agent":[ | |
{ | |
"key":"User-Agent", | |
"value":"Amazon CloudFront" | |
} | |
], | |
"via":[ | |
{ | |
"key":"Via", | |
"value":"1.1 7fa8abd93azzzbdcbc31.cloudfront.net (CloudFront)" | |
} | |
], | |
"accept-encoding":[ | |
{ | |
"key":"Accept-Encoding", | |
"value":"gzip" | |
} | |
], | |
"x-forwarded-for":[ | |
{ | |
"key":"X-Forwarded-For", | |
"value":"2607:zzz:zzz:zzz:c06e:38cc:99e7:da29" | |
} | |
], | |
"host":[ | |
{ | |
"key":"Host", | |
"value":"pzzze.s3.amazonaws.com" | |
} | |
] | |
}, | |
"method":"GET", | |
"origin":{ | |
"s3":{ | |
"authMethod":"origin-access-identity", | |
"customHeaders":{ | |
}, | |
"domainName":"pzzze.s3.amazonaws.com", | |
"path":"", | |
"region":"us-east-1" | |
} | |
}, | |
"querystring":"", | |
"uri":"/mycalendar.ics" | |
} | |
} | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Records":[ | |
{ | |
"cf":{ | |
"config":{ | |
"distributionDomainName":"d1zzzlmt.cloudfront.net", | |
"distributionId":"E1zzz8GZ", | |
"eventType":"origin-response" | |
}, | |
"request":{ | |
"clientIp":"6.2.1.7", | |
"headers":{ | |
"user-agent":[ | |
{ | |
"key":"User-Agent", | |
"value":"Amazon CloudFront" | |
} | |
], | |
"via":[ | |
{ | |
"key":"Via", | |
"value":"1.1 caf2zzzb43da60.cloudfront.net (CloudFront)" | |
} | |
], | |
"accept-encoding":[ | |
{ | |
"key":"Accept-Encoding", | |
"value":"gzip" | |
} | |
], | |
"host":[ | |
{ | |
"key":"Host", | |
"value":"pzzze.s3.amazonaws.com" | |
} | |
], | |
"x-forwarded-for":[ | |
{ | |
"key":"X-Forwarded-For", | |
"value":"6.2.1.7" | |
} | |
] | |
}, | |
"method":"GET", | |
"origin":{ | |
"s3":{ | |
"authMethod":"origin-access-identity", | |
"customHeaders":{ | |
}, | |
"domainName":"pzzze.s3.amazonaws.com", | |
"path":"", | |
"region":"us-east-1" | |
} | |
}, | |
"querystring":"", | |
"uri":"/mycalendar.ics" | |
}, | |
"response":{ | |
"headers":{ | |
"x-amz-request-id":[ | |
{ | |
"key":"x-amz-request-id", | |
"value":"B6DzzzD48" | |
} | |
], | |
"x-amz-id-2":[ | |
{ | |
"key":"x-amz-id-2", | |
"value":"KzMQLDzzzj93XRhGYMchr5shuiYsM9EJu1wLS0+IM=" | |
} | |
], | |
"date":[ | |
{ | |
"key":"Date", | |
"value":"Tue, 16 Oct 2018 22:05:05 GMT" | |
} | |
], | |
"server":[ | |
{ | |
"key":"Server", | |
"value":"AmazonS3" | |
} | |
], | |
"content-type":[ | |
{ | |
"key":"Content-Type", | |
"value":"application/xml" | |
} | |
], | |
"transfer-encoding":[ | |
{ | |
"key":"Transfer-Encoding", | |
"value":"chunked" | |
} | |
] | |
}, | |
"status":"403", | |
"statusDescription":"Forbidden" | |
} | |
} | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Records":[ | |
{ | |
"cf":{ | |
"config":{ | |
"distributionDomainName":"d1lzzzlmt.cloudfront.net", | |
"distributionId":"zzz", | |
"eventType":"viewer-request", | |
"requestId":"zsDwxGzzz-DG-zzz-s0uwyQ==" | |
}, | |
"request":{ | |
"clientIp":"6.2.1.7", | |
"headers":{ | |
"host":[ | |
{ | |
"key":"Host", | |
"value":"example.com" | |
} | |
], | |
"user-agent":[ | |
{ | |
"key":"User-Agent", | |
"value":"iOS/12.0.1 (16A404) dataaccessd/1.0" | |
} | |
], | |
"accept":[ | |
{ | |
"key":"accept", | |
"value":"text/calendar" | |
} | |
], | |
"accept-language":[ | |
{ | |
"key":"accept-language", | |
"value":"en-us" | |
} | |
], | |
"accept-encoding":[ | |
{ | |
"key":"accept-encoding", | |
"value":"br, gzip, deflate" | |
} | |
] | |
}, | |
"method":"GET", | |
"querystring":"", | |
"uri":"/mycalendar.ics" | |
} | |
} | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Records":[ | |
{ | |
"cf":{ | |
"config":{ | |
"distributionDomainName":"d1lzzzlmt.cloudfront.net", | |
"distributionId":"zzz", | |
"eventType":"viewer-response", | |
"requestId":"ohSdzzzmp5a-zzz-zzz==" | |
}, | |
"request":{ | |
"clientIp":"6.2.1.7", | |
"headers":{ | |
"host":[ | |
{ | |
"key":"Host", | |
"value":"example.com" | |
} | |
], | |
"user-agent":[ | |
{ | |
"key":"User-Agent", | |
"value":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" | |
} | |
], | |
"accept":[ | |
{ | |
"key":"accept", | |
"value":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" | |
} | |
], | |
"accept-language":[ | |
{ | |
"key":"accept-language", | |
"value":"en-us" | |
} | |
], | |
"accept-encoding":[ | |
{ | |
"key":"accept-encoding", | |
"value":"br, gzip, deflate" | |
} | |
], | |
"dnt":[ | |
{ | |
"key":"dnt", | |
"value":"1" | |
} | |
] | |
}, | |
"method":"GET", | |
"querystring":"", | |
"uri":"/" | |
}, | |
"response":{ | |
"headers":{ | |
"x-amz-id-2":[ | |
{ | |
"key":"x-amz-id-2", | |
"value":"Lzhzzzzz6Y7oo=" | |
} | |
], | |
"x-amz-request-id":[ | |
{ | |
"key":"x-amz-request-id", | |
"value":"8zzzzz742" | |
} | |
], | |
"date":[ | |
{ | |
"key":"Date", | |
"value":"Tue, 16 Oct 2018 18:13:35 GMT" | |
} | |
], | |
"last-modified":[ | |
{ | |
"key":"Last-Modified", | |
"value":"Mon, 15 Oct 2018 23:54:20 GMT" | |
} | |
], | |
"etag":[ | |
{ | |
"key":"ETag", | |
"value":"\"e7zzzzzz8702e33\"" | |
} | |
], | |
"x-amz-server-side-encryption":[ | |
{ | |
"key":"x-amz-server-side-encryption", | |
"value":"AES256" | |
} | |
], | |
"cache-control":[ | |
{ | |
"key":"Cache-Control", | |
"value":"max-age=86400,public" | |
} | |
], | |
"server":[ | |
{ | |
"key":"Server", | |
"value":"AmazonS3" | |
} | |
], | |
"strict-transport-security":[ | |
{ | |
"key":"Strict-Transport-Security", | |
"value":"max-age=50000;" | |
} | |
], | |
"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; report=https://example.report-uri.com/r/d/csp/enforce" | |
} | |
], | |
"content-security-policy":[ | |
{ | |
"key":"Content-Security-Policy", | |
"value":"upgrade-insecure-requests; default-src 'none'; font-src fonts.gstatic.com use.fontawesome.com; style-src 'self' cdnjs.cloudflare.com fonts.googleapis.com use.fontawesome.com; img-src 'self' example.com; script-src 'self' cdnjs.cloudflare.com; connect-src app.com example.com; report-uri https://example.report-uri.com/r/d/csp/enforce" | |
} | |
], | |
"referrer-policy":[ | |
{ | |
"key":"Referrer-Policy", | |
"value":"same-origin" | |
} | |
], | |
"content-encoding":[ | |
{ | |
"key":"Content-Encoding", | |
"value":"gzip" | |
} | |
], | |
"vary":[ | |
{ | |
"key":"Vary", | |
"value":"Accept-Encoding" | |
} | |
], | |
"age":[ | |
{ | |
"key":"Age", | |
"value":"9251" | |
} | |
], | |
"content-type":[ | |
{ | |
"key":"Content-Type", | |
"value":"text/html" | |
} | |
], | |
"transfer-encoding":[ | |
{ | |
"key":"Transfer-Encoding", | |
"value":"chunked" | |
} | |
] | |
}, | |
"status":"200", | |
"statusDescription":"OK" | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample context (which is basically the same for all event types), and event object for each event type. Note these examples are NOT all from the same single HTTP request. But regardless they give you an idea of what data to expect in the event object passed to your Lambda method.
As mentioned here