{"id":25056975,"url":"https://github.com/finndersen/aws_sam_custom_build_method","last_synced_at":"2025-07-30T09:03:11.488Z","repository":{"id":274655731,"uuid":"923592077","full_name":"Finndersen/aws_sam_custom_build_method","owner":"Finndersen","description":"A basic project template for using a custom AWS SAM build method so that each Lambda only contains the source code it needs.","archived":false,"fork":false,"pushed_at":"2025-01-28T15:35:51.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-07T19:46:33.944Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","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/Finndersen.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}},"created_at":"2025-01-28T14:25:51.000Z","updated_at":"2025-01-28T15:35:55.000Z","dependencies_parsed_at":"2025-01-28T16:43:51.751Z","dependency_job_id":null,"html_url":"https://github.com/Finndersen/aws_sam_custom_build_method","commit_stats":null,"previous_names":["finndersen/aws_sam_custom_build_method"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Finndersen/aws_sam_custom_build_method","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finndersen%2Faws_sam_custom_build_method","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finndersen%2Faws_sam_custom_build_method/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finndersen%2Faws_sam_custom_build_method/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finndersen%2Faws_sam_custom_build_method/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Finndersen","download_url":"https://codeload.github.com/Finndersen/aws_sam_custom_build_method/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finndersen%2Faws_sam_custom_build_method/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267842968,"owners_count":24153132,"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-07-30T02:00:09.044Z","response_time":70,"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":[],"created_at":"2025-02-06T13:40:03.922Z","updated_at":"2025-07-30T09:03:10.385Z","avatar_url":"https://github.com/Finndersen.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom SAM Build Method for Multi-lambda Monorepo \n\nA basic project template to demonstrate using a custom AWS SAM build method so that each Lambda only contain the source code it needs.\n\n## Issue with Standard build method\n\nIn you have a project involving multiple Lambda functions with shared code, having a structure like:\n\n```\nmy-project/\n├── src/\n│   ├── function_a/\n│   ├── function_b/\n│   └── shared/\n├── tests/\n├── requirements.txt\n└── sam-template.yaml\n```\nAnd with a SAM resource configuration like:\n```yaml\nResources:\n  LambdaA:\n    Type: AWS::Serverless::Function\n    Properties:\n      Handler: function_a.app.lambda_handler\n      Runtime: python3.11\n      CodeUri: src/\n\n  ...\n```\nThe standard AWS SAM build method will package all the source code into each Lambda, meaning each Lambda will contain code it does not need, and will have a new version published even when its own relevant code has not changed.\nExample build output:\n```\nbuild/\n├── LambdaA/\n│   ├── function_a/\n│   ├── function_b/     # This is not needed\n│   ├── shared/\n│   └── \u003cdependencies\u003e\n├── LambdaB/\n│   ├── function_a/     # This is not needed\n│   ├── function_b/\n│   ├── shared/\n│   └── \u003cdependencies\u003e\n```\n\n## Solution\n\nAWS SAM supports defining [custom build logic](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-custom-runtimes.html) using Makefile commands. \nThis project includes an example custom build process which only includes the necessary source code in each Lambda, so the build output will look like:\n\n```\nbuild/\n├── LambdaA/\n│   ├── function_a/\n│   ├── shared/\n│   └── \u003cdependencies\u003e\n├── LambdaB/\n│   ├── function_b/\n│   ├── shared/\n│   └── \u003cdependencies\u003e\n```\n\n## Usage\n\nTo run default build method:\n```bash\nsam build --template sam-template-basic.yaml --manifest requirements.txt\n```\n\nTo run custom build method:\n```bash\nsam build --template sam-template-custom.yaml\n```\n\n## Limitations\nThis setup involves a single set of dependencies for all Lambdas, so this may result in a Lambda being built with dependencies it does not need.\nThe dependencies are downloaded only once for efficiency and copied for each Lambda so this may not be a big deal, but it should also be possible to extend this solution to support Lambda-specific dependencies if required. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinndersen%2Faws_sam_custom_build_method","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffinndersen%2Faws_sam_custom_build_method","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinndersen%2Faws_sam_custom_build_method/lists"}