{"id":27933478,"url":"https://github.com/timescale/aws-lambda-example","last_synced_at":"2025-07-07T05:06:30.120Z","repository":{"id":83098354,"uuid":"602819652","full_name":"timescale/aws-lambda-example","owner":"timescale","description":"A sample serverless AWS Lambda time-series application.","archived":false,"fork":false,"pushed_at":"2023-04-05T17:20:17.000Z","size":702,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-06-16T07:57:31.859Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/timescale.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":"2023-02-17T02:11:14.000Z","updated_at":"2025-04-22T15:52:25.000Z","dependencies_parsed_at":"2025-05-07T04:59:01.504Z","dependency_job_id":"b2dcb226-ff98-42df-9915-a8329157b448","html_url":"https://github.com/timescale/aws-lambda-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/timescale/aws-lambda-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timescale%2Faws-lambda-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timescale%2Faws-lambda-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timescale%2Faws-lambda-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timescale%2Faws-lambda-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timescale","download_url":"https://codeload.github.com/timescale/aws-lambda-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timescale%2Faws-lambda-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264016735,"owners_count":23544626,"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","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":[],"created_at":"2025-05-07T04:58:59.893Z","updated_at":"2025-07-07T05:06:30.111Z","avatar_url":"https://github.com/timescale.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# timescale/aws-lambda-example\n\nThis repository serves as an example of an AWS Lambda time-series application that uses TimescaleDB on Timescale Cloud as a database!\n\n### Watch our video about this repository on YouTube!\n[![YouTube Thumbnail](https://raw.githubusercontent.com/timescale/aws-lambda-example/main/imgs/aws-timescale-cloud-lambda.png)](https://tsdb.co/aws-lambda-yt)\n\nThe application consists of two Lambda functions behind an API Gateway and a TimescaleDB instance on Timescale Cloud.\n\n![diagram of the architecture](https://raw.githubusercontent.com/timescale/aws-lambda-example/main/imgs/aws-diagram.png)\n\n### PostSensorData\nThis function takes in an API Gateway event with a body containing the location and temperature of the sensor reading. The function parses those parameters from the body and inserts them into a TimescaleDB database.\n\nEvent body:\n```json\n{\n    \"location\": \"bedroom\",\n    \"temperature\": 74\n}\n```\n\nResponse:\n```json\n[\n    {\n        \"time\": 1675997918,\n        \"location\": \"bedroom\",\n        \"temperature\": 65.0\n    },\n    ...\n    {\n        \"time\": 1675997910,\n        \"location\": \"bedroom\",\n        \"temperature\": 67.0\n    }\n]\n```\n\n### GetSensorData\nThis function takes no inputs but returns the latest 5 sensor readings ordered by time in an array.\n\n## Template\nIn order to use this AWS SAM project, you need to modify the following records in the `template.yaml` file:\n- `Globals.Function.Environment.Variables.CONN_STRING`\n- `Globals.Function.Environment.VpcConfig.SecurityGroupIds`\n- `Globals.Function.Environment.VpcConfig.SubnetIds`\n\n## Test and Deploy\nTo test the functions locally we need to build the Docker container for each function. You can do this by executing the following command in the root of this project:\n ```bash\n sam build\n ```\n\n Afterwards we can test each function individually using the provided events in `./events`.\n ```bash\n# test the PostSensorData function\nsam local invoke \"PostSensorDataFunction\" -e events/post.json\n\n# test the GetSensorData function\nsam local invoke \"GetSensorDataFunction\" -e events/get.json\n```\n\nTo deploy the function and it's required resources for the first time, execute:\n```\nsam deploy --guided\n```\n\nIf you've made changes to the code and want to deploy them to the cloud, execute:\n```\nsam build\nsam deploy\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimescale%2Faws-lambda-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimescale%2Faws-lambda-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimescale%2Faws-lambda-example/lists"}