{"id":17305221,"url":"https://github.com/dv8fromtheworld/lambdaedge-variable-injector","last_synced_at":"2025-03-26T23:23:09.831Z","repository":{"id":146754175,"uuid":"365548955","full_name":"DV8FromTheWorld/LambdaEdge-Variable-Injector","owner":"DV8FromTheWorld","description":"A simple custom resource for adding environment variable support to Lambda@Edge.","archived":false,"fork":false,"pushed_at":"2021-05-11T22:20:42.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T05:15:51.034Z","etag":null,"topics":["aws","aws-cloudformation-custom-resource","aws-custom-resource","cloudformation","custom-resource","lambda","lambda-at-edge"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/DV8FromTheWorld.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":"2021-05-08T15:30:30.000Z","updated_at":"2021-05-11T22:23:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"623802ab-9fea-433f-953e-cf5596ac1566","html_url":"https://github.com/DV8FromTheWorld/LambdaEdge-Variable-Injector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DV8FromTheWorld%2FLambdaEdge-Variable-Injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DV8FromTheWorld%2FLambdaEdge-Variable-Injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DV8FromTheWorld%2FLambdaEdge-Variable-Injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DV8FromTheWorld%2FLambdaEdge-Variable-Injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DV8FromTheWorld","download_url":"https://codeload.github.com/DV8FromTheWorld/LambdaEdge-Variable-Injector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245750768,"owners_count":20666232,"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","aws-cloudformation-custom-resource","aws-custom-resource","cloudformation","custom-resource","lambda","lambda-at-edge"],"created_at":"2024-10-15T11:55:02.313Z","updated_at":"2025-03-26T23:23:09.811Z","avatar_url":"https://github.com/DV8FromTheWorld.png","language":"JavaScript","readme":"# Lambda@Edge Environment Variable Injector\nA simple custom resource for adding environment variable support to Lambda@Edge.\n\n## Why\nPer the [official documentation](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-requirements-limits.html)\nenvironment variables are not supported in AWS Lambda@Edge. There are [some](https://stackoverflow.com/a/58101487) \n[possible](https://stackoverflow.com/a/54829145) [workarounds](https://aws.amazon.com/blogs/networking-and-content-delivery/leveraging-external-data-in-lambdaedge/),\nhowever each requires leveraging of external AWS constructs to enable environment-variable-like data passing or requires\nmaintaining or building multiple versions of your code to simulate what environment varaibles are _meant_ to do.\n\nThis solution aims to allow the developer to use environments variables as expected in normal lambdas:\n - Defined in Cloudformation\n - Retrieved from the language standardized environment constructs\n   - Node: `process.env[KEY]`\n   - Python: `os.environ[KEY]`\n\n## How\nThis custom resource retrieves your Node or Python lambda's payload zip from S3, injects a file into the payload\nthat contains your defined Environment Variables, re-zips the contents and uploads to S3. It then exposes the \nS3 bucket and S3 key of the uploaded modified payload in cloudformation (via `Fn::GetAtt`) for use in lambda definitions.\n\n## Example\n\n```yaml\nResources:\n  InjectEnvVariables:\n    Type: Custom::InjectEnvironmentVariables\n    Properties:\n      ServiceToken: !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:your-global-lambda-edge-variable-injector'\n      LambdaBucket: 'your-asset-bucket'\n      LambdaKey: 'path/to/your/lambda/payload.zip'\n      PayloadLanguage: 'node'\n      EnvironmentVariables:\n        IsSomeone: \"Getting\"\n        TheBest: \"TheBest, TheBest, TheBest\"\n        Of: \"You\"\n  \n  LambdaAtEdge:\n    Type: AWS::Serverless::Function\n    Properties:\n      Handler: index.handler\n      CodeUri:\n        Bucket: !GetAtt InjectEnvVariables.LambdaBucket\n        Key: !GetAtt InjectEnvVariables.LambdaKey\n      Runtime: 'nodejs14.x'\n```\nThus, when `LambdaAtEdge` does `require('./env.js`), the provided environment variables will be loaded into `process.env`\n\n|                          |                                |\n| ------------------------ | ------------------------------ |\n| `process.env.IsSomeone`  | `\"Getting\"`                    |\n| `process.env.TheBest`    | `\"TheBest, TheBest, TheBest\"`  |\n| `process.env.Of`         | `\"You\"`                        |\n\n## API\n\n### `OutputBucket`\nDefines the S3 bucket which the modified payload zip will be uploaded to. This value will override the `OUTPUT_BUCKET`\nenvironment variable set on the Custom Resource lambda itself if one was set on the global declaration of the resource.\nIf there was no `OUTPUT_BUCKET` environment variable set on the global declaration then this parameter **is required**.\n- Type: `string`\n- Required: `conditionally`\n\n### `LambdaBucket`\nDefines the source S3 bucket where the payload zip resides. This value should correspond to what you would have put\nfor [Lambda.Code.S3Bucket](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-s3bucket).\n- Type: `string`\n- Required: `yes`\n\n### `LambdaKey`\nDefines the source S3 key of the zip file. This value should correspond to what you would have put\nfor [Lambda.Code.S3Key](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-s3key).\n- Type: `string`\n- Required: `yes`\n\n### `PayloadLanguage`\nDefines what language is being used in provided lambda payload.\n- Type: `string`\n- Required: `yes`\n- Allowed Values:\n    - `\"node\"`\n    - `\"python\"`\n\n### `EnvironmentVariables`\nAn object defining the environment variables that should be made available to the lambda. This value should \ncorrespond to what you would have put for [Lambda.Environment.Variables](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html#cfn-lambda-function-environment-variables).\n- Type: `object\u003cstring, string\u003e`\n- Required: `yes`\n\n### `EnvironmentFile`\n_Optional_ \n\u003cbr /\u003eDefines the name of the environment variable file that is injected into the lambda payload. This value **should include** \nthe language-specific file extension (`.js` / `.py`).\n- Type: `string`\n- Required: `no`\n- Default:\n  - Node: `env.js`\n  - Python: `env.py`  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdv8fromtheworld%2Flambdaedge-variable-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdv8fromtheworld%2Flambdaedge-variable-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdv8fromtheworld%2Flambdaedge-variable-injector/lists"}