Amazon Cloudformation

CloudFormation Modules

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

https://blogs.aws.amazon.com/application-management/post/Tx1T9JYQOS8AB9I/Use-Nested-Stacks-to-Create-Reusable-Templates-and-Support-Role-Specialization

Best practice

http://harish11g.blogspot.ch/2014/08/amazon-cloudformation-templates-automation-Amazon-CFT-AWS-top-best-practices-tips.html

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

terraform

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

https://blogs.aws.amazon.com/application-management/post/Tx3DV2UYG9SC38G/Using-the-New-CloudFormation-Parameter-Types

Functions Usage

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html

Some Examples

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]
Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License