danieltorrecillas / anonymize-tiktok-link-lambda

AWS Lambda Function to anonymize a TikTok tracking link

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TikTok Link Anonymizer

This is an AWS Lambda function that converts a TikTok link embedded with user tracking into one without tracking. This function is written in Javascript targeting the Node.js runtime.

Function Input

This function was developed with an architecture of client HTTP requests being accepted from AWS API Gateway and passed to the function. More precisely, input to the function is an event from API Gateway to a Lambda proxy integration where event format is specified here.

Among all that data, this function only expects and uses a query string parameter url which is the tracking URL to be converted.

For example,

GET https://3rce4mrp80.execute-api.us-east-1.amazonaws.com/dev/convert?url=https://www.tiktok.com/t/ZTdtTNRjr --> event.queryStringParameters.url === 'https://www.tiktok.com/t/ZTdtTNRjr'

Function Output

A "good" response is an HTTP 200 OK with sample JSON:

{
  "url": "https://www.tiktok.com/@thetalkingbook/video/7053083465318878511"
}

where the value for url is the converted link.

There are two kinds of "bad" responses:

1.) A video could not be found for the URL submitted. This is an HTTP 404 Not Found with JSON:

{
  "errorMessage": "Could not find a video for that link. Please double check and try again."
}

2.) Any other kind of error that may have occurred. The HTTP status codes will vary. JSON will have an errorMessage property with a value that varies:

{
  "errorMessage": "An unknown error occurred."
}

Project Installation

This project uses npm for dependency management. An install at the root of the project gets you installed:

$ npm install

Project Testing

This project uses jest for testing. There are two test suites:

1.) Unit tests:

$ npm run test-unit

2.) Integration tests:

$ npm run test-integration

To run both unit and integration test suites:

$ npm test

Project Deployment

Create and upload a .zip of /src and required /node_modules to your Lambda function. Done.

Optional Deployment Script to AWS

There is a script to generate a .zip of only required files and update the Lambda function with that .zip.

AWS Prerequisites

  1. You have a Lambda function with a Node.js runtime out in AWS.
  2. You have access set up so that the AWS CLI can update the function.

Deployment Script Prerequisites

  1. You have bash or a bash compatible shell installed on your local machine.
  2. You have the AWS CLI installed on your local machine.
  3. You have the AWS CLI configured for your AWS account.

Deployment Script First Time Setup

update-lambda.sample is the above-mentioned script. There is some one-time setup:

  1. Copy update-lambda.sample and name it update-lambda:
$ cp update-lambda.sample update-lambda
  1. In update-lambda, edit 'YOUR_FUNCTION_NAME' to be the name of your Lambda function.

Run Deployment Script

In the root of the project:

$ ./update-lambda

About

AWS Lambda Function to anonymize a TikTok tracking link

License:MIT License


Languages

Language:JavaScript 96.1%Language:Shell 3.9%