Display AWS Cloudformation logs in pipelines

Using cloudformation is great, it gives you insane super powers but there are some small things that annoy me when using it in pipelines. My biggest issue is that it is not displaying the steps it takes in kind of real time’ish to stdout, so that’s where the following snippet will help.

The code

What the output looks like

[
    {
        "StackId": "arn:aws:cloudformation:eu-west-1:368341477005:stack/tech-blog/2b819be0-28fe-11ea-8ab3-06e58f87e324",
        "EventId": "5816a850-3333-11ea-83e6-02bbe9b74d60",
        "StackName": "tech-blog",
        "LogicalResourceId": "tech-blog",
        "PhysicalResourceId": "arn:aws:cloudformation:eu-west-1:368341477005:stack/tech-blog/2b819be0-28fe-11ea-8ab3-06e58f87e324",
        "ResourceType": "AWS::CloudFormation::Stack",
        "Timestamp": "2020-01-09T22:57:00.232Z",
        "ResourceStatus": "UPDATE_IN_PROGRESS",
        "ResourceStatusReason": "User Initiated"
    }
]


[
    {
        "StackId": "arn:aws:cloudformation:eu-west-1:368341477005:stack/tech-blog/2b819be0-28fe-11ea-8ab3-06e58f87e324",
        "EventId": "5af0ca60-3333-11ea-94ed-0655dfaca74c",
        "StackName": "tech-blog",
        "LogicalResourceId": "tech-blog",
        "PhysicalResourceId": "arn:aws:cloudformation:eu-west-1:368341477005:stack/tech-blog/2b819be0-28fe-11ea-8ab3-06e58f87e324",
        "ResourceType": "AWS::CloudFormation::Stack",
        "Timestamp": "2020-01-09T22:57:05.016Z",
        "ResourceStatus": "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS"
    }
]


[
    {
        "StackId": "arn:aws:cloudformation:eu-west-1:368341477005:stack/tech-blog/2b819be0-28fe-11ea-8ab3-06e58f87e324",
        "EventId": "5b481220-3333-11ea-ac13-02d3b89dc706",
        "StackName": "tech-blog",
        "LogicalResourceId": "tech-blog",
        "PhysicalResourceId": "arn:aws:cloudformation:eu-west-1:368341477005:stack/tech-blog/2b819be0-28fe-11ea-8ab3-06e58f87e324",
        "ResourceType": "AWS::CloudFormation::Stack",
        "Timestamp": "2020-01-09T22:57:05.588Z",
        "ResourceStatus": "UPDATE_COMPLETE"
    }
]



Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - tech-blog
section_end:1578610649:build_script

If you want it all and you want it now

This is the easiest way to use this snippet, I will try to keep functionality stable for this snippet but there are no guarantees that this wil work till the end of time.

#!/bin/bash

# pull in cfn_wrapper
source <(curl -s https://gitlab.com/snippets/1928583/raw)

# deploy
cfn_wrapper aws cloudformation deploy --template-file "cloudformation.yml" \
  --stack-name $STACK --capabilities='CAPABILITY_IAM' --no-fail-on-empty-changeset \
  --parameter-overrides \
  CfnParam="$CFN_PARAM" \
  CfnVar="$SOME_VAR"

Avatar
Stein van Broekhoven
Cloud & Open-Source magician 🧙‍♂️

I try to find the KISS in complex systems and share it with the world.

comments powered by Disqus

Related