{"id":18303734,"url":"https://github.com/marcodaniels/elm-aws-cloudfront","last_synced_at":"2025-04-09T10:19:08.555Z","repository":{"id":215903297,"uuid":"739710595","full_name":"MarcoDaniels/elm-aws-cloudfront","owner":"MarcoDaniels","description":"Create AWS CloudFront Lambda@Edge functions in Elm","archived":false,"fork":false,"pushed_at":"2024-01-14T13:11:43.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T04:27:16.331Z","etag":null,"topics":["aws-cloudfront","elm","lambda-edge"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/marcodaniels/elm-aws-cloudfront/latest/","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarcoDaniels.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-01-06T10:00:54.000Z","updated_at":"2024-01-23T20:22:02.000Z","dependencies_parsed_at":"2024-11-05T15:42:52.231Z","dependency_job_id":null,"html_url":"https://github.com/MarcoDaniels/elm-aws-cloudfront","commit_stats":null,"previous_names":["marcodaniels/elm-aws-cloudfront"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcoDaniels%2Felm-aws-cloudfront","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcoDaniels%2Felm-aws-cloudfront/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcoDaniels%2Felm-aws-cloudfront/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcoDaniels%2Felm-aws-cloudfront/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarcoDaniels","download_url":"https://codeload.github.com/MarcoDaniels/elm-aws-cloudfront/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018119,"owners_count":21034053,"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-cloudfront","elm","lambda-edge"],"created_at":"2024-11-05T15:26:36.466Z","updated_at":"2025-04-09T10:19:08.533Z","avatar_url":"https://github.com/MarcoDaniels.png","language":"Elm","readme":"# elm-aws-cloudfront\n\nCreate [AWS CloudFront Lambda@Edge](https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html) functions in Elm.\n\n---\n\nThis package uses an [Elm headless worker](https://package.elm-lang.org/packages/elm/core/latest/Platform#worker) under\nthe hood requiring [ports](https://guide.elm-lang.org/interop/ports) and a small JavaScript snippet to be bundled and\ndeployed into AWS CloudFront Lambda@Edge. Check the [examples folder](/examples).\n\nElm part:\n\n```elm\nport module MyModule exposing (main)\n\nimport CloudFront exposing (Model, Msg, cloudFront)\nimport CloudFront.Header exposing (withHeader)\nimport CloudFront.Lambda exposing (originResponse, toResponse)\nimport Json.Decode as Decode\nimport Json.Encode as Encode\n\nport inputEvent : (Decode.Value -\u003e msg) -\u003e Sub msg\n\nport outputEvent : Encode.Value -\u003e Cmd msg\n\n-- Optional flags can be used on init\n-- main : Program {token : String} (Model {token : String}) Msg\nmain : Program () (Model ()) Msg\nmain =\n    ( inputEvent, outputEvent )\n        |\u003e (originResponse\n                (\\{ response, request } _ -\u003e\n                    response\n                        |\u003e withHeader { key = \"cache-control\", value = \"public, max-age=1000\" }\n                        |\u003e toResponse\n                )\n                |\u003e cloudFront\n           )\n```\n\nJavaScript part:\n\n```javascript\nconst {Elm} = require('./elm');\n// optinal flags can be passed on init\n// const app = Elm.MyModule.init({flags: {token: 'my-token'}});\nconst app = Elm.MyModule.init();\nexports.handler = (event, context, callback) =\u003e {\n    const caller = (output) =\u003e {\n        callback(null, output);\n        app.ports.outputEvent.unsubscribe(caller);\n    }\n    app.ports.outputEvent.subscribe(caller);\n    app.ports.inputEvent.send(event);\n}\n```\n\nThis repository also provides a nix builder to build and bundle the application to be ready to deploy into AWS. This\nrequires to have the Elm ports named with:\n\n```elm\nport inputEvent : (Decode.Value -\u003e msg) -\u003e Sub msg\n\nport outputEvent : Encode.Value -\u003e Cmd msg\n```\n\nAs the bundled JavasScript will automatically add the input and output ports with the specific name.\n\nThe nix builder requires the `elm-srcs.nix` and `registry.dat` files, and for that\nthe [elm2nix package](https://github.com/cachix/elm2nix) is needed to generate them.\n\n```nix\nmakeLambda.buildElmAWSCloudFront {\n  src = ./src;\n  elmSrc = ./elm-srcs.nix;\n  elmRegistryDat = ./registry.dat;\n  lambdas = [\n    { module = ./src/MyModuleTwo.elm; }\n    {\n      module = ./src/MyModuleOne.elm;\n      flags = [ ''token:\"token-goes-here\"'' ''url:\"url-goes-here\"'' ];\n    }\n  ];\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcodaniels%2Felm-aws-cloudfront","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcodaniels%2Felm-aws-cloudfront","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcodaniels%2Felm-aws-cloudfront/lists"}