Cloudformation

From Ever changing code
Jump to navigation Jump to search

Basic structure of Json and Yaml templates

Cloudformation template basic structure
YAML JSON
AWSTemplateFormatVersion: 2010-09-09
Description: Yaml string, version 1.0
Metadata: {}
Parameters: {}
Mappings: {}
Conditions: {}
Transform: {}
Resources: {}
Outputs: {}
{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "JSON string, version 1.0",
    "Metadata": {},
    "Parameters": {},
    "Mappings": {},
    "Conditions": {},
    "Transform": {},
    "Resources": {},
    "Outputs": {}
}

Structured template

Cloudformation template basic structure
YAML JSON
AWSTemplateFormatVersion: 2010-09-09
Description: JSON string
Metadata: {}
Parameters:
  InstanceTypeParameter:
    Type: String
    Default: t2.micro
    AllowedValues:
      - t2.micro
      - m1.smal
    Description: 'Enter t2.micro, m1.large'
Mappings: {}
# Mapping01:
#   Key01:
#     Name: Value01
#   Key02:
#     Name: Value02
Conditions: {}
Transform: {}
# AWS::serverless
# AWS::Include (reusing template snippets)
Resources:
  MyBucket:     #logicalID must be unique, can be reused within the template
  Type: 'AWS:S3::Bucket'  #type of resource to create
  Properties:  #additional options for a resource
    'Fn::Transform;:
      - Name: 'AWS::Include'
         Parameters:
         Location: s3://bucket/MyBucketName.yaml
Outputs: {}
# logicalID:
#   Descryption:
#   Value:
#   Export:
#     Name: Value to export
{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "JSON string",
    "Metadata": {},
    "Parameters": {
        "InstanceTypeParameter": {
            "Type": "String",
            "Default": "t2.micro",
            "AllowedValues": [
                "t2.micro",
                "m1.small"
            ],
            "Description": "Enter t2.micro, m1.small"
        }
    },
    "Mappings": {},
    "Conditions": {},
    "Transform": {},
    "Resources": {},
    "Outputs": {}
}

Intrinsic Functions (buildin)

Use intrinsic functions in your templates to assign values to properties that are not available until runtime.