# Host a static site in S3 with Cloudfront and Https

**URL:** <https://forum.serverless.com/t/host-a-static-site-in-s3-with-cloudfront-and-https/4370>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [April 27, 2018, 3:12pm UTC](https://forum.serverless.com/t/host-a-static-site-in-s3-with-cloudfront-and-https/4370 "2018-04-27T15:12:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cardreader](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cardreader](https://forum.serverless.com/u/cardreader)\
**Post date:** [April 27, 2018, 3:12pm UTC](https://forum.serverless.com/t/host-a-static-site-in-s3-with-cloudfront-and-https/4370/1 "2018-04-27T15:12:23Z")

</div>

Hi,

I am trying to understand if the following is possible…

- Upload a static site to S3.
- Create a cloud formation distribution.
- Link to a custom domain name from route 53
- Attach a custom https certificate from Amazon’s certificate manager.

I’ve had a look at both the serverless-finch and serverless-single-page-app-plugin plugins. The former works quite nicely to upload my static site to s3 and I believe the latter will set up a cloud front distribution.

I’m struggling to understand how to connect the dots.

Firstly - is this what the serverless framework is designed to do? Or should I look at a different tool (e.g. Terraform).

If I’m in the right place I think I need to understand how to link up both my Route 53 domain and my HTTPS certificate to my cloudfront distribution.

Or is it the case that I would set these up once manually and then use serverless to manage the deploy my static site in the s3 bucket and the lambda APIs I will have for the actual site functionality?

Would be grateful for some pointers.

Thanks.

---

<div class="post-metadata">

**Author:** ![bill](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bill/32/1072_2.png) [@bill](https://forum.serverless.com/u/bill)\
**Post date:** [April 29, 2018, 11:47am UTC](https://forum.serverless.com/t/host-a-static-site-in-s3-with-cloudfront-and-https/4370/2 "2018-04-29T11:47:35Z")

</div>

Go through [https://serverless-stack.com/](https://serverless-stack.com/), it gives you the instruction on how to do that.

You can jump to part of [Create a New React.js App](https://serverless-stack.com/chapters/create-a-new-reactjs-app.html) if you know serverless already.

---

<div class="post-metadata">

**Author:** ![fahadjabbar8](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/fahadjabbar8/32/2243_2.png) [@fahadjabbar8](https://forum.serverless.com/u/fahadjabbar8)\
**Post date:** [July 12, 2018, 2:20pm UTC](https://forum.serverless.com/t/host-a-static-site-in-s3-with-cloudfront-and-https/4370/3 "2018-07-12T14:20:53Z")

</div>

Have you found a way out to do it in through serverless rather using netily as mentioned in the serverless stack ?

---

<div class="post-metadata">

**Author:** ![fahadjabbar8](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/fahadjabbar8/32/2243_2.png) [@fahadjabbar8](https://forum.serverless.com/u/fahadjabbar8)\
**Post date:** [July 12, 2018, 2:22pm UTC](https://forum.serverless.com/t/host-a-static-site-in-s3-with-cloudfront-and-https/4370/4 "2018-07-12T14:22:27Z")

</div>

It uses netily do complete the process that is deploying to s3 -\> cloudfront and then a custom domain at route 53 . Can we do it using serverless only ?

---

<div class="post-metadata">

**Author:** ![3boysdad](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/3boysdad/32/2071_2.png) [@3boysdad](https://forum.serverless.com/u/3boysdad)\
**Post date:** [July 15, 2018, 5:31am UTC](https://forum.serverless.com/t/host-a-static-site-in-s3-with-cloudfront-and-https/4370/5 "2018-07-15T05:31:48Z")

</div>

in my experience…there are better ways to transfer your web site to S3 buckets. while i imagine there’s a way that serverless can do this…gulp is probably an easier tool - along with this add-on:

[https://www.npmjs.com/package/gulp-awspublish](https://www.npmjs.com/package/gulp-awspublish)

then in your gulp file:

gulp.task(‘aws-publish-dev’, function() {

```
var publisher = awspublish.create({
    region: 'us-west-2',
    params: {
        Bucket: '===your bucket name==='
    }
}, {
    cacheFileName: './cache/'
});

return gulp.src('./dist/**')
    .pipe(publisher.publish())
    .pipe(publisher.sync())
    .pipe(awspublish.reporter());

```

});

---

<div class="post-metadata">

**Author:** ![3boysdad](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/3boysdad/32/2071_2.png) [@3boysdad](https://forum.serverless.com/u/3boysdad)\
**Post date:** [July 15, 2018, 5:34am UTC](https://forum.serverless.com/t/host-a-static-site-in-s3-with-cloudfront-and-https/4370/6 "2018-07-15T05:34:52Z")

</div>

probably should also mention there’s a cloudfront add-on which will invalidate the cache for you (a)synchronously…

[https://www.npmjs.com/package/gulp-cloudfront-invalidate](https://www.npmjs.com/package/gulp-cloudfront-invalidate)

gulp.task(‘invalidate-cloudfront’, function() {  
var cfSettings = {  
distribution: ‘===your name====’, // Cloudfront distribution ID  
wait: false, // Whether to wait until invalidation is completed (default: false)  
paths: [’/\*’], // Configure OriginPath to be removed of file path to invalidation  
indexRootPath: true // Invalidate index.html root paths (`foo/index.html` and `foo/`) (default: false)  
};

```
return gulp.src('*')
    .pipe(cloudfront(cfSettings));

```

});
