https://www.udemy.com/aws-cloudformation-master-class/learn/v4/t/lecture/8139078?start=0
Section 4 Main Menu
Overview
https://www.udemy.com/aws-cloudformation-master-class/learn/v4/t/lecture/8139078?start=0
What are resources
- Resources are the core of your CF template
- They represent the different AWS components that will be created and configured.
- Resources are declared and can reference each other
- AWS figures out create, updates and deletes of resources for us.
- There are over 224 types of resources
- Resource type identifiers are of the form:
- AWS::aws-product-name::data-type-name
How do I find resources documentation
- AWS Resource Types Reference
- Example: EC2 Instance
- Remember, you can also locate these documents through the CF Designer!
Hands On
https://www.udemy.com/aws-cloudformation-master-class/learn/v4/t/lecture/8161728?start=0
EC2 Instance + Security Group + Elastic IP
---
Resources:
MyInstance:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: us-east-1a
ImageId: ami-a4c7edb2
InstanceType: t2.micro
SecurityGroups:
- !Ref SSHSecurityGroup
- !Ref ServerSecurityGroup
MyEIP:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html
Type: AWS::EC2::EIP
Properties:
InstanceId: !Ref MyInstance
SSHSecurityGroup:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 22
IpProtocol: tcp
ToPort: 22
ServerSecurityGroup:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: allow connections from specified CIDR ranges
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 192.168.1.1/32
Optional Atttributes (Advanced)
- DependsOn:
- Create a dependency between two resources.
- Only create and ECS (Elastic Container Service) cluster after creating an ASG (Auto scaling group)
- Create a dependency between two resources.
- DeletionPolicy:
- Protect resources from being deleted even if the cloudformation is deleted.
- Example: RDS Database
- Protect resources from being deleted even if the cloudformation is deleted.
- CreationPolicy:
- More details in the CFN init
- Metadata:
- Anything you want, get creative!
- Additional examples in the CFN init section.
Frequently Asked Questions
https://www.udemy.com/aws-cloudformation-master-class/learn/v4/t/lecture/8139084?start=0
- Can I create a dynamic amount of resources?
- No. Everything in the CF template has to be declared. You cannot perform code generation there.
- There is a work around using the troposphere library
- Is every AWS service supported?
- Almost. Only a select few niches are not ready yet.
- This can be worked around using Lambda Custom Resources.
Quiz
How many type of resources are available in CloudFormation
- Less than 20
- Between 20 and 100
- Between 100 and 200
- Over 200
How do I learn about a specific Resource type?
- …ask Thomas, he knows everything!
- Use the documentation