CloudFormation Modules
- https://aws.amazon.com/blogs/mt/introducing-aws-cloudformation-modules/
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/modules.html#modules-using.title
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html
- https://github.com/cfn-modules/docs
Old stuff
It is a part of amazon that permit to create templates and reuse many times.
I have seen this interesting video and take some notes.
https://www.brighttalk.com/webcast/9019/105175
It is possible also download the slides
Some key points:
- you use template and avoid to repete operations
- integrate with your development tools
- template in json format
- you can place your template in s3 bucket or other locations
- slides 52 - 53 reference can change at runtime
- parameter from command lime or from web console, is possible to evaluate the parameters
- slide 59 "conditional values" for example for difference region you can use specify different ami
- slide 63 it is possible run a script inside the json code, run command, create files , control linux service
- it si possible integrate with puppet or chef
- slides 74 examples wordpress in multiregion environments in template and settings, HPC is super advance case use
Get Started
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/GettingStarted.Walkthrough.html
and this page http://www.devopscloud.com/05.01.html
JSON to YAML Converter
https://blog.boltops.com/2017/09/16/json-to-yaml-one-liner
Resource Type
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html
Some examples
if possible find complicate examples of things built with cloudformation, but to start you need simple and working example
Nested templates
Best practice
Complex Template Generation
troposphere - library to create AWS CloudFormation descriptions
from the readme page https://github.com/cloudtools/troposphere
The troposphere library allows for easier creation of the AWS CloudFormation JSON by writing Python code to describe the AWS resources. troposphere also includes some basic support for OpenStack resources via Heat.
To facilitate catching CloudFormation or JSON errors early the library has property and type checking built into the classes.
Terraform , multiproviders not only cloudformation
Monsanto with scala
in this post of Monsanto http://engineering.monsanto.com/2015/07/10/cloudformation-template-generator/ they explain why didn't choose Terraform to generate template https://www.terraform.io/ and instead used a scala tool available here https://github.com/MonsantoCo/cloudformation-template-generator
Advanced Parameters usage
Functions Usage
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
Some Examples
- good example to use the Sub instead of other ones https://theburningmonk.com/2019/05/cloudformation-protip-use-fnsub-instead-of-fnjoin/
Json Examples amazon-cloudformation-syntax-json
YAML precious code pieces
It was not possible do it in one line
Outputs:
Printdebug:
Value: !Join
- ''
- - !Ref EFSFyleSystem
- .efs.
- !Ref 'AWS::Region'
- '.amazonaws.com:/'
Export:
Name: Printdebug
some import value
Subnets:
- {'Fn::ImportValue': !Sub '${PlatformPrefix}-PrivateSubnet1AID'}
- {'Fn::ImportValue': !Sub '${PlatformPrefix}-PrivateSubnet1BID'}
- {'Fn::ImportValue': !Sub '${PlatformPrefix}-PrivateSubnet1CID'}
VpcId: {'Fn::ImportValue': !Sub '${PlatformPrefix}-VPCID'}
use of condictions
Conditions:
HasS3Bucket: !Not [!Equals [!Ref ParentS3StackAccessLog, '']]
IsProd: !Equals [!Ref TargetAwsAccount, 'prod']
..........
RecordSets:
- Name: !If ['IsProd', !Join ['', ['phpldapadmin.', {'Fn::ImportValue': 'aaaa-domain'}]], !Join ['', ['phpldapadmin.', {'Fn::ImportValue': 'bbb-domain'}]]]
Type: A
getatt
Role: !GetAtt [LambdaGenericRole, Arn]