postTemplateGeneration Lifecycle Event

The postTemplateGeneration lifecycle event is sent to a Stackery stack’s hook function near the end of the deployment preparation phase.

At the end of deployment preparation, an AWS CloudFormation template is generated. The hook function associated with the stack is then invoked with information about the stack, deployment, and generated CloudFormation template. The function can then modify the generated template and respond with a new template. This new template is then submitted to AWS to create a change set for the deployment.

Caution!

The postTemplateGeneration event allows for arbitrary modifications to the Stackery generated templates. It is possible to modify templates in ways that break built-in Stackery functionality. Please reach out to support@stackery.io if you have any questions or concerns about template modifications.

Event Schema

The postTemplateGeneration event has the following properties:

Property Type Value
event string “postTemplateGeneration”
stack.id string Stackery stack identifier
stack.name string Stackery stack name
stack.version string Stackery stack Git commit version
environment.name string Stackery environment name
deployment.namespace string Unique resource namespace in AWS based on combination of stack and environment
deployment.id number Stackery deployment identifier
template object Stackery generated CloudFormation template

Example

{
  "event": "postTemplateGeneration",
  "stack": {
    "id": "9832094822344",
    "name": "My Stack",
    "version": "bc4096ae06db95419bc0c6d2e6e97e0d74fd4956"
  },
  "environment": {
    "name": "development"
  },
  "deployment": {
    "namespace": "stackery-834597293",
    "id": 7489
  },
  "template": {
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Stackery Stack 'My Stack' Environment 'development'",
    "Outputs": {
      "DeploymentHistoryId": {
        "Description": "Stackery Deployment History ID",
        "Value": "366"
      }
    },
    "Resources": {  
      "72843118": {  
        "Type": "AWS::Lambda::Function",
        "Properties": {  
          "Code": {  
            "S3Bucket": "stackery-assetsbucket-98sdf7df87f",
            "S3Key": "deployments/498357384578/366/functions/72843118.zip"
          },
          "Environment": {  
            "Variables": {  
              "STACKERY_PORTS": {  
                "Fn::Sub":"[[]]"
              },
              "STACKERY_NODE": "{\"id\":\"72843118\",\"name\":\"72843118\"}"
            }
          },
          "FunctionName": "stackery-498357384578-72843118",
          "Handler": "__stackery_entry.handler",
          "MemorySize": 128,
          "Role": {  
            "Fn::GetAtt": [  
              "RoleForFunctions",
              "Arn"
            ]
          },
          "Runtime": "nodejs6.10",
          "Timeout": 60,
          "TracingConfig": {  
            "Mode":"Active"
          },
          "Tags": [  
            {  
              "Key": "Stackery Stack",
              "Value": "My Stack"
            },
            {  
              "Key": "Stackery Environment",
              "Value": "development"
            },
            {  
              "Key": "Stackery Node",
              "Value": "72843118"
            }
          ]
        }
      },
    }
  }
}

Response Schema

The hook function must respond with a message containing the template to be used for creating the change set for the deployment. The template can be modified as needed. The response must be an object with the following properties:

Property Type Value
template object CloudFormation template to provision

Example

In the following response we add a new tag to the AWS::Lambda::Function resource to denote the business unit for cost aggregation purposes.

{
  "template": {
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Stackery Stack 'My Stack' Environment 'development'",
    "Outputs": {
      "DeploymentHistoryId": {
        "Description": "Stackery Deployment History ID",
        "Value": "366"
      }
    },
    "Resources": {  
      "72843118": {  
        "Type": "AWS::Lambda::Function",
        "Properties": {  
          "Code": {  
            "S3Bucket": "stackery-assetsbucket-98sdf7df87f",
            "S3Key": "deployments/498357384578/366/functions/72843118.zip"
          },
          "Environment": {  
            "Variables": {  
              "STACKERY_PORTS": {  
                "Fn::Sub":"[[]]"
              },
              "STACKERY_NODE": "{\"id\":\"72843118\",\"name\":\"72843118\"}"
            }
          },
          "FunctionName": "stackery-498357384578-72843118",
          "Handler": "__stackery_entry.handler",
          "MemorySize": 128,
          "Role": {  
            "Fn::GetAtt": [  
              "RoleForFunctions",
              "Arn"
            ]
          },
          "Runtime": "nodejs6.10",
          "Timeout": 60,
          "TracingConfig": {  
            "Mode":"Active"
          },
          "Tags": [  
            {  
              "Key": "Stackery Stack",
              "Value": "My Stack"
            },
            {  
              "Key": "Stackery Environment",
              "Value": "development"
            },
            {  
              "Key": "Stackery Node",
              "Value": "72843118"
            },
            {
              "Key": "Business Unit",
              "Value": "Sales"
            }
          ]
        }
      },
    }
  }
}

Try Stackery For Free

Gain control and visibility of your serverless operations from architecture design to application deployment and infrastructure monitoring.