AWS Lambda Function to extract meta data (IP version, HTTP version, and Edge location) from customer visits to CloudFront
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

CloudFrontMetaData Build Status

A simple AWS Lambda ( function that in combination with Amazon API Gateway ( can extract meta data (IP Version, HTTP Version, and AWS CloudFront Edge Location) from visitor requests, when placed behind CloudFront.


To run this skill you need to do two things. The first is to deploy the code in lambda, and the second is to configure API Gateway.

AWS Lambda Setup

  1. Go to the AWS Console and click on the Lambda link. Note: ensure you are in us-east or you won't be able to use Alexa with Lambda.
  2. Click on the Create a Lambda Function or Get Started Now button.
  3. Name the Lambda Function “CloudFrontMetaData”.
  4. Go to the the src directory, select all files and then create a zip file, make sure the zip file does not contain the src directory itself, otherwise Lambda function will not work.
  5. Upload the .zip file to the Lambda
  6. Keep the Handler as index.handler (this refers to the main js file in the zip).
  7. Create a basic execution role and click create.

API Gateway Setup


When visiting the API Gateway URL via CloudFront you will see the following output:


You can now use the following Javascript code for Google Analytics to push the information into Google Analytics as custom dimension for each visit:

ga('create', 'UA-12345678-1', 'auto');
	function processData(x) {
		var y = {};
		for (var i = 0; i < x.length-1; i++) {
			var split = x[i].split('=');
			y[split[0].trim()] = split[1].trim();
		return y;

	function objData(x) { 
		return obj[x]; 

	var data;
	var obj;
	var client = new XMLHttpRequest();"GET", "/ipver.php", false);
	client.onreadystatechange =
		function () {
			if(client.readyState === 4){
				if(client.status === 200 || client.status == 0){
					data = client.responseText.split("\n");
	obj= processData(data);

  	ga('send', 'pageview');