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
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
CloudFormation Parameters and more
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.
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.
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.
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
, equalsFn:Equals
, ifFn:If
etc
CloudFormation Rollbacks
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
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!
Top comments (0)