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.
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'
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."
}
This project uses npm for dependency management. An
install
at the root of the project gets you installed:
$ npm install
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
Create and upload a .zip
of /src
and required /node_modules
to your Lambda
function. Done.
There is a script to generate a .zip
of only required files and update the
Lambda function with that .zip
.
- You have a Lambda function with a Node.js runtime out in AWS.
- You have access set up so that the AWS CLI can update the function.
- You have bash or a
bash
compatible shell installed on your local machine. - You have the AWS CLI installed on your local machine.
- You have the AWS CLI configured for your AWS account.
update-lambda.sample
is the above-mentioned script.
There is some one-time setup:
- Copy
update-lambda.sample
and name itupdate-lambda
:
$ cp update-lambda.sample update-lambda
- In
update-lambda
, edit'YOUR_FUNCTION_NAME'
to be the name of your Lambda function.
In the root of the project:
$ ./update-lambda