0
votes

I have a cloudformation stack right now that sets up a simple ec2 instance, and installs all of my python packages and files in the user data section. I never even mention cfn-init anywhere in my stack, nor do I have metadata. Is it possible to still use cfn-signal in order to alert my stack that setup of the ec2 instance is not yet done? Or must cfn-signal and cfn-init be used together?

Thank you.

1

1 Answers

0
votes

Nope, cfn-init and cfn-signal are two completely separate mechanics and can be used one without the other.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-signal.html

I use cfn-signal extensively in my Snowplow cloudformation template. Chucking here the relevant snippets...

Here's the snippet example of how I call cfn-signal by itself:

  EventCollectionGroup:
    Type: 'AWS::AutoScaling::AutoScalingGroup'
    Properties:
      LaunchConfigurationName: !Ref EventCollectionLc
    CreationPolicy:
      ResourceSignal:
        Count: 2
        Timeout: PT10M
    UpdatePolicy:
      AutoScalingRollingUpdate:
        MinInstancesInService: 1
        WaitOnResourceSignals: 'true'
        PauseTime: PT10M

  EventCollectionLc:
    Type: 'AWS::AutoScaling::LaunchConfiguration'
    Properties:
      UserData: !Base64 
        'Fn::Sub': |
          #!/bin/bash
          docker run -t --rm ${ContainerAwsUtil} cfn-signal -e $? --stack ${AWS::StackName} --resource EventCollectionGroup --region ${AWS::Region}
    UpdatePolicy:
      AutoScalingReplacingUpdate:
        WillReplace: 'true'

The above snippet have the extras trimmed out. You can find the template here:

https://github.com/Bit-Clouded/Glenlivet/blob/master/analytics/snowplow.template#L368

As you can see, I actually run the cfn-init in a container itself and do not install the util on the server even.

The docker container definition is here:

FROM alpine:3.6

RUN apk add --no-cache ca-certificates python py-pip groff less jq curl &&\
    pip install awscli &&\
    pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz

Again, with extras trimmed. Full file is here:

https://github.com/Bit-Clouded/Angostura/blob/master/utility/aws-util/Dockerfile


In fact, I personally have moved away from cfn-init altogether and moved all required binaries to be pulled in via docker instead. Just a bash script in the UserData section is far cleaner and easier to read.