{"id":22693624,"url":"https://github.com/mooyoul/serverless-cloudfront-lambdaedge-plugin","last_synced_at":"2025-04-13T00:15:58.022Z","repository":{"id":40555334,"uuid":"227927912","full_name":"mooyoul/serverless-cloudfront-lambdaedge-plugin","owner":"mooyoul","description":"A serverless plugin that injects actual Lambda Version ARN to LambdaAssociations in CloudFront CFN resource","archived":false,"fork":false,"pushed_at":"2025-04-11T08:13:47.000Z","size":1468,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T00:15:52.724Z","etag":null,"topics":["lambda","lambda-edge","serverless","serverless-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mooyoul.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2019-12-13T21:51:21.000Z","updated_at":"2025-04-11T08:13:16.000Z","dependencies_parsed_at":"2024-02-13T06:27:28.444Z","dependency_job_id":"19024139-e8de-460d-8aba-e862f3d4589a","html_url":"https://github.com/mooyoul/serverless-cloudfront-lambdaedge-plugin","commit_stats":{"total_commits":141,"total_committers":4,"mean_commits":35.25,"dds":0.375886524822695,"last_synced_commit":"76bb66a1881ba6c93df9e0242dfd387c20a8f5f8"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooyoul%2Fserverless-cloudfront-lambdaedge-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooyoul%2Fserverless-cloudfront-lambdaedge-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooyoul%2Fserverless-cloudfront-lambdaedge-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooyoul%2Fserverless-cloudfront-lambdaedge-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mooyoul","download_url":"https://codeload.github.com/mooyoul/serverless-cloudfront-lambdaedge-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647273,"owners_count":21139086,"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":["lambda","lambda-edge","serverless","serverless-plugin"],"created_at":"2024-12-10T02:12:02.356Z","updated_at":"2025-04-13T00:15:57.971Z","avatar_url":"https://github.com/mooyoul.png","language":"JavaScript","readme":"# serverless-cloudfront-lambdaedge-plugin\n\nA serverless plugin that injects actual Lambda Version ARN to LambdaAssociations in CloudFront CFN resource\n\n![plugin demo](./assets/plugin.png)\n\n## Why?\n\n![CFN requirements](./assets/cfn.png)\n\n![Unpredictable Versions](./assets/versions.png)\n\n\n[Lambda@Edge replicates function to all CloudFront Edges.](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-how-it-works.html)\n\nDue to this behavior, Lambda@Edge configuration requires Full Lambda Function ARN.\nYou cannot reference alias or `$LATEST` tag when configuring Lambda@Edge.\n\n[You **MUST** reference fully-qualified Lambda Function version ARN.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-lambdafunctionassociation.html)\n\nCurrently there's no easy/reliable way to setup Lambda@Edge using Serverless Framework.\n\nRecently released Serverless framework added support of Lambda@Edge triggers, [but it looks not easily customizable](https://github.com/serverless/serverless/issues/6785).\nso you will have to use CloudFormation Template to configure Lambda@Edge.\n\n[Unfortunately, Serverless framework creates a new Lambda Version in every deployment with unpredictable hash suffix](https://github.com/serverless/serverless/blob/5fa10f59279d0b8c2e31c9ab5c3121fc06b32813/lib/plugins/aws/package/compile/functions/index.js#L478-L551), and it's by default.\nYou cannot reference Lambda Function version resource directly in your CloudFormation template.\n\nThis plugin replaces all `LambdaFunctionAssociations` in your `serverless.yml` CloudFormation template to automatically created Lambda Version references.   \n\n\n## Install\n\nFirst, install package as development dependency.\n\n```bash\n$ npm i serverless-cloudfront-lambdaedge-plugin --save-dev\n```\n\nThen, add the plugin to `serverless.yml`\n\n```yaml\n# serverless.yml\n\nplugins:\n  - serverless-cloudfront-lambdaedge-version\n```\n\n## Setup\n\nJust specify `LambdaFunctionARN` of LambdaFunctionAssociations to matching function name.\n\nLet's suppose that you've defined functions in `serverless.yml` like below:\n\n```yaml\nfunctions:\n  APIOriginRequest:\n    name: ${self:service}-${self:provider.stage}-api-origin-request\n    handler: handlers/api/origin-request.handler\n    memorySize: 128\n    timeout: 5\n    role: LambdaEdgeExecutionRole\n  WebOriginRequest:\n    name: ${self:service}-${self:provider.stage}-web-origin-request\n    handler: handlers/api/origin-request.handler\n    memorySize: 128\n    timeout: 5\n    role: LambdaEdgeExecutionRole\n```\n\nJust Specify `LambdaFunctionARN` block like below:\n\n```yaml\nresources:\n  Resources:\n    CloudFrontDistribution:\n      Type: AWS::CloudFront::Distribution\n      Properties:\n        DistributionConfig:\n          # ... TRUNCATED ...\n          DefaultCacheBehavior:\n            LambdaFunctionAssociations:\n              - EventType: origin-request\n                LambdaFunctionARN: WebOriginRequest # Specify matching function name\n            # ... TRUNCATED ...\n          CacheBehaviors:\n            - PathPattern: \"/api/*\"\n              LambdaFunctionAssociations:\n                - EventType: origin-request\n                  LambdaFunctionARN: APIOriginRequest # Specify matching function name\n              # ... TRUNCATED ...\n          # ... TRUNCATED ...\n```\n \nand then, deploy your stack. \nThis plugin will automatically replace `LambdaFunctionARN` block to `{ Ref: \"MatchingLambdaVersionLogicalId\" }`.\n\n## Changelog\n\nSee [CHANGELOG](CHANGELOG.md).\n\n\n## License\n[MIT](LICENSE)\n\nSee full license on [mooyoul.mit-license.org](http://mooyoul.mit-license.org/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmooyoul%2Fserverless-cloudfront-lambdaedge-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmooyoul%2Fserverless-cloudfront-lambdaedge-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmooyoul%2Fserverless-cloudfront-lambdaedge-plugin/lists"}