{"id":13576544,"url":"https://github.com/serverless-components/aws-cloudfront","last_synced_at":"2025-04-04T15:32:09.782Z","repository":{"id":45560250,"uuid":"203358787","full_name":"serverless-components/aws-cloudfront","owner":"serverless-components","description":"Deploy an AWS CloudFront distribution for the provided origins using Serverless Components","archived":false,"fork":false,"pushed_at":"2021-12-08T18:08:23.000Z","size":90,"stargazers_count":27,"open_issues_count":20,"forks_count":12,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T11:05:59.775Z","etag":null,"topics":["aws","aws-cloudfront","cdn","serverless","serverless-components","serverless-framework"],"latest_commit_sha":null,"homepage":"https://serverless.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serverless-components.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-20T11:04:12.000Z","updated_at":"2023-02-24T15:53:28.000Z","dependencies_parsed_at":"2022-09-23T05:10:57.999Z","dependency_job_id":null,"html_url":"https://github.com/serverless-components/aws-cloudfront","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/serverless-components%2Faws-cloudfront","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-components%2Faws-cloudfront/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-components%2Faws-cloudfront/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-components%2Faws-cloudfront/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serverless-components","download_url":"https://codeload.github.com/serverless-components/aws-cloudfront/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247203020,"owners_count":20900895,"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-cloudfront","cdn","serverless","serverless-components","serverless-framework"],"created_at":"2024-08-01T15:01:11.260Z","updated_at":"2025-04-04T15:32:04.776Z","avatar_url":"https://github.com/serverless-components.png","language":"JavaScript","readme":"# aws-cloudfront\n\n\u0026nbsp;\n\nDeploy an AWS CloudFront distribution for the provided origins using [Serverless Components](https://github.com/serverless/components).\n\n\u0026nbsp;\n\n1. [Install](#1-install)\n2. [Create](#2-create)\n3. [Configure](#3-configure)\n4. [Deploy](#4-deploy)\n\n\u0026nbsp;\n\n### 1. Install\n\n```console\n$ npm install -g serverless\n```\n\n### 2. Create\n\n```console\n$ mkdir cdn\n$ cd cdn\n```\n\nthe directory should look something like this:\n\n```\n|- serverless.yml\n|- .env      # your AWS api keys\n\n```\n\n```\n# .env\nAWS_ACCESS_KEY_ID=XXX\nAWS_SECRET_ACCESS_KEY=XXX\n```\n\n### 3. Configure\n\n```yml\n# serverless.yml\n\ndistribution:\n  component: '@serverless/aws-cloudfront'\n  inputs:\n    region: us-east-1\n    enabled: true # optional\n    comment: 'My distribution' # optional\n    defaults: # optional\n      ttl: 15\n      allowedHttpMethods: ['HEAD', 'GET']\n      forward: # optional\n        # array of header names, 'none' or 'all'\n        headers: ['Accept', 'Accept-Language']\n        # array of cookie names, 'none' or 'all'\n        cookies: ['my-cookie]\n        queryString: true\n        queryStringCacheKeys: ['queryKey']\n      viewerProtocolPolicy: 'https-only' # optional\n      smoothStreaming: true # optional\n      compress: true # optional\n      fieldLevelEncryptionId: '123' # optional\n      lambda@edge: # added to cloudfront default cache behavior\n        viewer-request: arn:aws:lambda:us-east-1:123:function:myFunc:version\n    origins:\n      - https://my-bucket.s3.amazonaws.com\n```\n\n#### Custom cache behavior\nCustom cache behaviors support the same config parameters as the default cache behavior (see the example above). \n```yml\n# serverless.yml\n\ndistribution:\n  component: '@serverless/aws-cloudfront'\n  inputs:\n    origins:\n      - url: https://my-assets.com\n        pathPatterns:\n          /static/images: # route any /static/images requests to https://my-assets.com\n            ttl: 10\n            allowedHttpMethods: ['GET', 'HEAD'] # optional\n            forward: # optional\n              headers: 'all' \n              cookies: ['auth-token']\n              queryString: true\n            compress: false # optional\n            # ...\n```\n\n#### Lambda@Edge\n\n```yml\n# serverless.yml\n\ndistribution:\n  component: '@serverless/aws-cloudfront'\n  inputs:\n    origins:\n      - url: https://sampleorigin.com\n        pathPatterns:\n          /sample/path:\n            ttl: 10\n            lambda@edge:\n              viewer-request: arn:aws:lambda:us-east-1:123:function:myFunc:version # lambda ARN including version\n```\n\n#### Private S3 Content\n\nTo restrict access to content that you serve from S3 you can mark as `private` your S3 origins:\n\n```yml\n# serverless.yml\n\ndistribution:\n  component: '@serverless/aws-cloudfront'\n  inputs:\n    origins:\n      - url: https://my-private-bucket.s3.amazonaws.com\n        private: true\n```\n\nA bucket policy will be added that grants CloudFront with access to the bucket objects. Note that it doesn't remove any existing permissions on the bucket. If users currently have permission to access the files in your bucket using Amazon S3 URLs you will need to manually remove those.\n\nThis is documented in more detail here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html\n\n### 4. Deploy\n\n```console\n$ serverless\n```\n\n\u0026nbsp;\n\n### New to Components?\n\nCheckout the [Serverless Components](https://github.com/serverless/components) repo for more information.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverless-components%2Faws-cloudfront","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserverless-components%2Faws-cloudfront","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverless-components%2Faws-cloudfront/lists"}