AWS Professional : CloudFormation

What is an AWS CloudFormation Template?

Various of the cloudformation’s status

Parameters

Resource

#AWS::ProductIdentifier::ResourceTypeResources: 
LogicaId:
Type: AWS:S3:Bucket
"Parameters" : {
"Username": {
"Type" : "String"
}
}
"Resources" : {
"logical-ID" : {
"Type" : { "AWS::RDS::DBInstance" },
"Properties" : {
"MasterUsername" : {"Ref": "Username"}
}
}
}

Conditions:

isProduction: !Equals [ !Ref "Vpc", "production" ]#and this can be used for the decision of the resource creation:
GenericLogicalIDForSecurity:
Condition:
"isProduction" #Create the securityGroup just on Prod.
Type: "AWS::EC2::SecurityGroupIngress"

Outputs

#Where VPC is a Parameter of the stack{
"Resources" : {
"Bucket-LogicalID" : {
"Type" : "AWS::S3::Bucket"
}
},
"Outputs" : {
"BucketName" {
"Value" : {"Ref" : "Bucket-LogicalID"}
Export:
Name: !Join ["", [ !Ref "Vpc", "-export-this-logical-id"]]
}
}
}
## Those can now be called in other stacks e.g.
Fn::ImportValue:
!Sub "${Vpc}-export-this-logical-id"

Intrinsic Function & Conditionals

Fn::Base64
Fn::FindInMap
Fn::getAtt
Fn::getAzs
Fn::Join
Fn::Select
Ref
===== Conditional =====
Fn::And
Fn::Equals
Fn::If
Fn::Not
Fn::Or
{ "Fb::Base64" : "apt-get update && apt-get install" }
"Fn::Join" : [";",["1","2","3"]]
#Will return 1;2;3
#Get the first AZ returned from GetAZs
{ "Fn:::Select" : [ "0", { "Fn::GetAZs" : "" } ] }

Mapping

#Get the first AZ returned from GetAZs
Mappings:
RegionMap:
us-east-1:
AMI: ami-12312312
us-east-2:
AMI: ami-12312312
#Retrieve
!FindInMap["RegionMap", !Ref "AWS::Region", AMI]
#Different Syntax
!FindInMap
- RegionMap
- !Ref "AWS::Region"
- AMI

Metadata

Metadata:   
Instances:
Description: "Information about the instances"
Databases:
Description: "Information about the databases"

TIPS AND TRICKS

#/opt/aws/bin/cfn-signal -e $? — region ${AWS::Region} — stack ${AWS::StackName} — resource ECSAutoScalingGroup

Passionate about people management, effective coaching and IT development. Currently Head Of Development, Scrum Master, AWS Certified, Surfer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store