{"id":17865255,"url":"https://github.com/oieduardorabelo/aws-sam-nested-applications-single-package-json","last_synced_at":"2025-09-21T12:33:21.903Z","repository":{"id":185455565,"uuid":"611106257","full_name":"oieduardorabelo/aws-sam-nested-applications-single-package-json","owner":"oieduardorabelo","description":"AWS SAM Nested Applications with single package.json to all lambda handlers","archived":false,"fork":false,"pushed_at":"2023-03-08T08:27:37.000Z","size":200,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-29T21:11:59.656Z","etag":null,"topics":["amazon-api-gateway","aws","aws-lambda","aws-sam","aws-sam-cli","aws-sam-example","aws-sam-nested-applications","serverless","typescript"],"latest_commit_sha":null,"homepage":"","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/oieduardorabelo.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-03-08T05:47:52.000Z","updated_at":"2024-11-15T08:38:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"6890a4ba-24fa-4afb-8b7b-18cd8a980eab","html_url":"https://github.com/oieduardorabelo/aws-sam-nested-applications-single-package-json","commit_stats":null,"previous_names":["oieduardorabelo/aws-sam-nested-applications-single-package-json"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Faws-sam-nested-applications-single-package-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Faws-sam-nested-applications-single-package-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Faws-sam-nested-applications-single-package-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oieduardorabelo%2Faws-sam-nested-applications-single-package-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oieduardorabelo","download_url":"https://codeload.github.com/oieduardorabelo/aws-sam-nested-applications-single-package-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233694823,"owners_count":18715508,"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":["amazon-api-gateway","aws","aws-lambda","aws-sam","aws-sam-cli","aws-sam-example","aws-sam-nested-applications","serverless","typescript"],"created_at":"2024-10-28T09:19:59.943Z","updated_at":"2025-09-21T12:33:16.488Z","avatar_url":"https://github.com/oieduardorabelo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS SAM Nested Applications with single package.json\n\nThis is an example of using AWS SAM with nested applications sharing a single `package.json`.\n\nWe have a Rest API TypeScript application (`apps/rest-api/handlers`) that uses `dependencies` from the root `package.json`.\n\nWe have a DynamoDB Stream with a TypeScript lambda consumer (`apps/dynamodb/handlers`) that uses `dependencies` from the root `package.json`.\n\nAny application can define its own TypeScript Lambda and use the root `package.json`.\n\nThe parent AWS SAM application is defined in `./template.yaml` and child applications are defined in `./apps/*/template.yaml`.\n\n## Benefits\n\nThis enables the developer to use a single `package.json` and share it across the entire application. `esbuild` will be packing each lambda handler bundling the correct dependencies imported by each handler.\n\n## Drawback\n\nYou need to define `--base-dir` for every AWS SAM CLI command that have it as an option.\n\nWhen using `sam sync` chaging the source code of one lambda with sync all lambdas of that stack. For example, `apps/rest-api` is a stack with 2 lambdas. If you change the source code of one lambda, all 2 lambdas will be synced.\n\n## Conventions on how to use\n\nWe have a few conventions:\n\n1. The `package.json` is located in the root of the project\n2. The `CodeUri` of any lambda is always `./`\n3. Definitions for lambda handlers entry points are defined using the full relative path of the project root\n4. When running `sam build` from the root of the project, we need to define `--base-dir .` to make sure that `esbuild` will be able to find the `package.json` in the root of the project and resolve all relative paths correctly\n\nFor example:\n\n```yaml\nResources:\n    GetBooksFunction:\n        Type: AWS::Serverless::Function\n        Properties:\n            CodeUri: ./\n            Handler: get-books.handler\n            # ...\n        Metadata:\n            # ...\n            BuildProperties:\n                # ...\n                EntryPoints:\n                    - apps/rest-api/handlers/get-books.ts\n```\n\n**Important:** The `--base-dir` must be defined for every AWS SAM CLI command that have it as an option.\n\n## Deploying to AWS\n\nYou can use any AWS SAM CLI command, make sure you include `--base-dir .` when running from the root of the project.\n\nWith `sync`:\n\n```bash\nsam sync --base-dir .\n```\n\nWith `deploy`:\n\n```\nsam build --base-dir .\nsam deploy\n```\n\n## Running locally\n\nYou can run it locally as you would normally do with AWS SAM CLI.\n\nWith `local start-api`:\n\n```bash\nsam build --base-dir .\nsam local start-api\n```\n\nWith `local invoke`:\n\n```bash\nsam build --base-dir .\nsam local invoke StackRestApi/GetCategoriesFunction\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foieduardorabelo%2Faws-sam-nested-applications-single-package-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foieduardorabelo%2Faws-sam-nested-applications-single-package-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foieduardorabelo%2Faws-sam-nested-applications-single-package-json/lists"}