{"id":28344323,"url":"https://github.com/rehanvdm/pets-backend-v2","last_synced_at":"2026-04-30T07:37:51.191Z","repository":{"id":190962703,"uuid":"677239888","full_name":"rehanvdm/pets-backend-v2","owner":"rehanvdm","description":" How to create a tRPC server on AWS Lambda exporting an OpenAPI SDK to be used by the frontend","archived":false,"fork":false,"pushed_at":"2023-08-27T09:50:03.000Z","size":89,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-27T10:01:20.344Z","etag":null,"topics":["aws","cdk","lambda","trpc"],"latest_commit_sha":null,"homepage":"https://blog.cloudglance.dev/trpc-separate-backend-frontend-with-openapi-aws-lambda-cdk/index.html","language":"TypeScript","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/rehanvdm.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}},"created_at":"2023-08-11T04:40:58.000Z","updated_at":"2025-02-26T17:28:09.000Z","dependencies_parsed_at":"2023-08-27T11:57:24.538Z","dependency_job_id":"31a76900-c7ee-42e0-af02-c4123653c8d3","html_url":"https://github.com/rehanvdm/pets-backend-v2","commit_stats":null,"previous_names":["rehanvdm/pets-backend-v2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rehanvdm/pets-backend-v2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehanvdm%2Fpets-backend-v2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehanvdm%2Fpets-backend-v2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehanvdm%2Fpets-backend-v2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehanvdm%2Fpets-backend-v2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rehanvdm","download_url":"https://codeload.github.com/rehanvdm/pets-backend-v2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehanvdm%2Fpets-backend-v2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260953464,"owners_count":23088042,"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":["aws","cdk","lambda","trpc"],"created_at":"2025-05-27T09:56:46.603Z","updated_at":"2026-04-30T07:37:51.186Z","avatar_url":"https://github.com/rehanvdm.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backend\n\n\u003e This repo is part of this blog: [https://blog.cloudglance.dev/trpc-separate-backend-frontend-with-openapi-aws-lambda-cdk/index.html](https://blog.cloudglance.dev/trpc-separate-backend-frontend-with-openapi-aws-lambda-cdk/index.html)\n\nThis project consists of a single API Lambda function deployed to AWS that can be accessed using the Function URL(FURL).\nThe AWS CDK has been used to define the IaC and the Lambda is written in TS.\n\nIt features the following:\n- Showcases [tRPC](https://trpc.io/) + [trpc-openapi](https://github.com/jlalmes/trpc-openapi)\n- Generates an OpenAPI spec file from the tRPC code and then from that a JS API SDK, TS types and sourcemaps\n- The API SDK is pushed to GitHub and also published to GitHub Packages (similar to NPM)\n- A build system that consists of npm scripts, [wireit](https://github.com/google/wireit) and a custom TS file used to execute commands\n- Tests setup for both unit and e2e\n- Local development by creating an express server from the tRPC lambda code\n- Other:\n  - Uses esbuild and the `esbuild-runner` package instead of `tsc` or `ts-node`\n  - Vitest is being used for tests\n  - Has ESLint + Prettier setup\n  - It has API endpoints to get all pets, a single pet and to create a pet. It also has an endpoint to show the OpenAPI\n    spec nicely formatted in HTML.\n\n## Configuration\n\nThe configuration is done in the `config/index.ts` file. The file has been committed with actual values for the purpose\nof this blog. Replace the values with your own, see description of the types in the file.\n\n**OPTIONALLY**, if you intend to publish the package to GH Packages, you will need to:\n1. Create a [Personal Access Token(PAT) on GitHub](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-token)\n   so that we can write the SDK API NPM package. You need to assign the flowing permissions:\n  - `write:packages` Upload packages to the GitHub Package Registry\n2. Make a copy of the `.npmrc.example` file and replace:\n   -`\u003cYOUR PERSONAL ACCESS TOKEN HERE\u003e` with your GitHub Personal Access Token (PAT) that you obtained above\n   -`\u003cYOUR GITHUB PROFILE OR ORGANIZATION NAME\u003e` with your GutHub username of where the package is installed\n\n## Scripts\n\nUseful commands:\n\n- `npm run build-src` - Builds this project source, transpiling the TS to JS for the Lambda function and storing\nthe JS in the `dist` folder which is then used by the Lambda.\n- `npm run cdk-diff` - Runs `build-src` and then the `cdk diff` command.\n- `npm run cdk-deploy` - Runs `build-src` and then the `cdk deploy` command. This deploys the Lambda + Function URL(FURL)\nand will produce a URL in the CloudFormation (CFN) output section that you must copy to the frontend production\nenvironment file.\n- `npm run cdk-hotswap` - Runs `build-src` and then the `cdk deploy --hotswap` command. The hotswap command is used for\nquick iteration of the deployed Lambda code.\n---\n- `npm run start-local-api-watch` - Starts an express server that serves the Lambda function for local development.\n- `npm run build-api-package` - Generates the OpenAPI Spec and the API SDK to the `api-packages` folder.\n- `npm run publish-api-package` - Runs the `build-api-package` again and publishes the API SDK to GitHub Packages.\n---\n- `npm run lint-fix` - Runs eslint and prettier on the project and fixes all linting and formatting issues (also runs\nin the hsuky git pre commit hook).\n- `npm run test-unit` - Runs the tests defined in the `/tests` folder.\n- `npm run test-e2e` - Runs the tests defined in the `/tests` folder, make sure the `TEST_VARIABLES` in the `config/index.ts`\nfile are set correctly. The only important property for e2e tests is the `api_url` which is the Function URL of the\ndeployed Lambda.\n\n\n## Using the API SDK NPM package\n\nSee the frontend docs here: [https://github.com/rehanvdm/pets-frontend-v2](https://github.com/rehanvdm/pets-frontend-v2)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehanvdm%2Fpets-backend-v2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frehanvdm%2Fpets-backend-v2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehanvdm%2Fpets-backend-v2/lists"}