{"id":26330757,"url":"https://github.com/lchristmann/tracker-api-aws-lambda-function","last_synced_at":"2025-08-26T15:27:11.049Z","repository":{"id":279500937,"uuid":"938332826","full_name":"lchristmann/tracker-api-aws-lambda-function","owner":"lchristmann","description":"An API implementation on AWS Lambda for the Tracker Android application","archived":false,"fork":false,"pushed_at":"2025-02-25T22:37:26.000Z","size":5117,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-12T18:33:34.886Z","etag":null,"topics":["amazon-web-services","api","aws-lambda","aws-lambda-node","location-tracker","rest-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lchristmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-24T19:37:39.000Z","updated_at":"2025-02-25T22:37:29.000Z","dependencies_parsed_at":"2025-02-25T22:40:28.981Z","dependency_job_id":null,"html_url":"https://github.com/lchristmann/tracker-api-aws-lambda-function","commit_stats":null,"previous_names":["lchristmann/tracker-api-aws-lambda-function"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lchristmann/tracker-api-aws-lambda-function","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2Ftracker-api-aws-lambda-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2Ftracker-api-aws-lambda-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2Ftracker-api-aws-lambda-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2Ftracker-api-aws-lambda-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lchristmann","download_url":"https://codeload.github.com/lchristmann/tracker-api-aws-lambda-function/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lchristmann%2Ftracker-api-aws-lambda-function/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269366853,"owners_count":24405250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazon-web-services","api","aws-lambda","aws-lambda-node","location-tracker","rest-api"],"created_at":"2025-03-15T22:17:41.021Z","updated_at":"2025-08-08T05:06:44.197Z","avatar_url":"https://github.com/lchristmann.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tracker API AWS Lambda Function - Part of [Tracker project](https://github.com/lchristmann/Tracker)\n\nThis project contains the AWS Lambda function `tracker-api` that is part of the [\"Tracker\" Android app](https://github.com/lchristmann/Tracker)'s system architecture (see diagram in its repo's README.md).\n\nThe Lambda function is integrated with an Amazon API Gateway API via proxy-integration (forwarding the request as-is as structured event).\n\nIt reads and writes to the S3 bucket `tracker-website` (in region `eu-central-1`) and therefor as appropriate permissions:\n\n- via IAM role that allows access to the S3 bucket\n- the S3 bucket has a bucket policy allowing it to be accessed from this Lambda\n\nIt also invalidates the CloudFront CDN cache of the `locations.json` file after it has written that file to the AWS S3 bucket. This makes it that we see fresh content on reloading the page and not stale old content that the CDN has cached.\n\nIt lives in Australia's `ap-southeast-2` region (Sydney).\n\n## What this Lambda does\n\nIn detail: see well-commented code\n\nIn short:\n\n1. It makes required imports, sets constants and initializes the S3 client with eu-central-1 region\n2. It tries to read the `locations.json` file from the `tracker-website` bucket. If it doesn't exist it's no big deal - the function will go with an empty array for now and create that file later.\n3. If the file is present in the bucket though, the contained array will be used.\n4. The current request with the `timestamp`, `longitutde`, `latitude` payload is appended to the array.\n5. The array is saved to the `locations.json` file in the `tracker-website` bucket.\n\n## Development\n\nDevelopment on this Lambda function is recommended to be done with the Visual Studio Code Editor.\n\nRun `npm install` in this project directory to install the `@aws-sdk/client-s3` dependency.\n\nThe documentation of S3 Client part of the AWS SDK is linked in comments at the very top of the `index.mjs` file.\n\nThe code (`index.mjs`) uses the recommended ES6 module format.\n\n## Deployment\n\nTo deploy this AWS Lambda function, zip it while excluding the `README.md`, the `.gitignore` and the `.git` folder:\n\nRun `zip -r tracker-api-aws-lambda-function.zip . -x \"README.md\" -x \".git/*\" -x \".gitignore\"` (tested on Linux Ubuntu)\n\nThen go to the Lambda function in the AWS Management Console \u003e Upload from \u003e .zip file and choose the created file.\n\nFinally select \"Actions \u003e Publish new version \u003e Publish\" for the Lambda function.\n\n## Testing\n\nThe Lambda function can be tested **in the AWS Management Console** with the \"Test\" feature in the Lambda console:\n\n- creating a test event (e.g. \"LocationTestEvent\") with such a JSON body:\n\n```shell\n{\n  \"headers\": {\n    \"x-api-key\": \"\u003cSECRET_API_KEY\u003e\"\n  },\n  \"body\": \"{\\\"timestamp\\\": 1740499200000, \\\"latitude\\\": -26.679507, \\\"longitude\\\": 153.136417}\"\n}\n```\n\nThat should yield below result, but most importantly a `locations.json` file should have been created in the `tracker-website` S3 bucket or - if it already existed - above data should've been appended to it\n\n```shell\nStatus: Succeeded\nTest Event Name: TestLocationEvent\n\nResponse:\n{\n  \"statusCode\": 200,\n  \"body\": \"{\\\"message\\\":\\\"Record saved successfully\\\"}\"\n}\n```\n\n### Testing with [Postman](https://www.postman.com/)\n\nCreate a POST request to `https://x7b9yw5krd.execute-api.ap-southeast-2.amazonaws.com/prod/location` with\n\n- header `Content-Type`: `application/json`\n- header `x-api-key`: `\u003cSECRET_API_KEY\u003e` (ask the developer)\n- below raw body:\n\n```json\n{\n  \"timestamp\": \"1740499200000\",\n  \"latitude\": -26.679507,\n  \"longitude\": 153.136417\n}\n```\n\n### Testing with [curl](https://curl.se/)\n\n```shell\ncurl -X POST https://x7b9yw5krd.execute-api.ap-southeast-2.amazonaws.com/prod/location \\\n  -H \"Content-Type: application/json\" \\\n  -H \"x-api-key: \u003cSECRET_API_KEY\u003e\" \\\n  -d '{\n    \"timestamp\": \"1740499200000\",\n    \"latitude\": -26.679507,\n    \"longitude\": 153.136417\n  }'\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flchristmann%2Ftracker-api-aws-lambda-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flchristmann%2Ftracker-api-aws-lambda-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flchristmann%2Ftracker-api-aws-lambda-function/lists"}