AWS Learn In Public Week 9, CloudFormation And CloudFront
Tags: aws, learninpublic, cloudformation, cloudfront
Published: 2021-04-26 08:05:44

---
title: AWS Learn In Public Week 9, CloudFormation And CloudFront
published: true
description: Using templates for provisioning your infrastructure and caching assets
tags:
- aws
- learninpublic
- cloudformation
- cloudfront
cover_image: https://user-images.githubusercontent.com/630705/116047719-4b9a1500-a66c-11eb-82ff-2fbc04f0f905.jpeg
canonical_url: https://www.harrisgeo.me/blogs/aws-learn-in-public-week-9-cloudformation-and-cloudfront
series: AWS Learn in public
---

This week we're going to talk about CloudFormation which is what we talked about in last week's Elastic Beanstalk blog that is used under the hood. After that, I also have a small introduction to CloudFront. Before I spoil anything else, let's get started.

## [CloudFormation](https://twitter.com/harrisgeo88/status/1384131934142431235)

This week we're going to talk about CloudFormation in AWS.

What is CloudFormation? It way for declaring what AWS infrastructure you want provision in a template. We can create, configure and delete AWS components and also reference them with each other.

The format is `AWS::Lambda::Function` or `AWS::EC2::Instance`

CloudFormation supports most AWS services and the full list can be found here

[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html](https://t.co/Fm29w2f2On?amp=1)

## [CloudFormation Parameters and more](https://twitter.com/harrisgeo88/status/1384866273646022657)

Let's talk about AWS CloudFormation parameters

- We can specify inputs insure our templates which are great for reusing templates and values of services that we want to use after they are created
- That way we won't have to re-upload templates all the time.

### Referencing

We can use referencing for using params anywhere within the template

The API name is `Fn:Ref` and in the yaml config it is shortened to `!Ref`

### Pseudo params

We can also use pseudo params for AWS related values that we do not want to store in our code and again use them at any time. These can be like the AWS account id with `AWS::AccountId`, the region with `AWS::Region` and more.

### Mappings

We also have mappings which are fixed variables useful when adding sets of hardcoded data in our code. An example is `FN:FindInMap` which allows us to search within maps.

![https://pbs.twimg.com/media/EzgG6yKXEAQm-ca?format=jpg&name=large](https://pbs.twimg.com/media/EzgG6yKXEAQm-ca?format=jpg&name=large)

### Outputs

Then we have outputs which are optional but work really well when we want to use the value of a service that was just created in order to reference it to another resource.

![https://pbs.twimg.com/media/EzgIB7QWYAEC5Qn?format=jpg&name=medium](https://pbs.twimg.com/media/EzgIB7QWYAEC5Qn?format=jpg&name=medium)

### Cross Reference

Then we have the cross stack reference where we create another template that uses a security group. We can reference that with `Fn::ImportValue`. Once a stack is referenced in another template, all the references need to be deleted first before deleting the first stack.

![https://pbs.twimg.com/media/EzurkNBWUAU6iRu?format=jpg&name=medium](https://pbs.twimg.com/media/EzurkNBWUAU6iRu?format=jpg&name=medium)

### Conditions

We can control the creation of resources based on conditions. Such conditions are environment stage, AWS region etc

- Conditions can reference other conditions, parameter values or mappings
- We have intrinsic function like and `Fn:And`, equals `Fn:Equals`, if `Fn:If` etc

![https://pbs.twimg.com/media/EzusprrXIAAHznE?format=jpg&name=medium](https://pbs.twimg.com/media/EzusprrXIAAHznE?format=jpg&name=medium)

## [CloudFormation Rollbacks](https://twitter.com/harrisgeo88/status/1385927266144718849)

Let's talk about AWS CloudFormation rollbacks

- If a stack creation fails, by default all underlying resources get deleted
- We also have an option to disable that and troubleshoot the error
- If a stack update fails it automatically rolls back to the previous state that was working
- Same as when creating, we have the ability to see in the logs and debug what exactly went wrong

## [CloudFront](https://twitter.com/harrisgeo88/status/1386397244530716674)

What is AWS CloudFront? It is a CDN (Content Delivery Network) formed of distributions and is mainly used to improve site’s performance as content is cached on multiple edge locations around the world.It provides DDOS protection and integrates with AWS firewall Shield

CloudFront can provide origins from:

- S3 buckets for distributing and caching files at the edge
- Other custom origins like ALB, EC2, S3 websites and any HTTP backend you want

Overall, clients send requests to any of the multiple edges around the world where the requests get forwarded to the origin along with any query params and headers. Then the origin responds with the available assets which then get cached in the edge location for future requests.

## Summary

Both CloudFormation and CloudFront are services that I have not used much in the past but I understand their importance in our AWS stack. CloudFormation is definitely a service that requires a deeper dive with some coding examples (maybe a future blog post) to really understand its value.

Next week we're finally going to talk about the most interesting service in AWS for being a developer. Shall I ruin the surprise? Whatever. Next week will be about AWS Lambda!