cfn-init vs user-data

What’s the difference between using the cfn-init the UserData script?

Both approaches provide ways to bootstrap, configure, and install things on an EC2 Instance.

A key difference between the two approaches is that UserData will replace the EC2 instance entirely, whereas cfn-init will do an in-place update.

Using configsets provide the benefit of not fully replacing the EC2 instance. This allows you to deploy new changes incrementally. The bootstrap script will not start from scratch on a brand new instance, reinstalling everything.

Using configsets over UserData also reduces the amount of pollution in the UserData script.

Note: If you are using cfn-init with AutoScaling, CloudFormation will only replace the instance if you have a UpdatePolicy AutoScalingRollingUpdate configured. If you do not, then the EC2 instance will not be updated. In that case, You must manually terminate the instance, and AutoScaling will it the instance.

Are configsets reusable?

Normally, with CloudFormation, configs from AWS::CloudFormation::Init are not reusable. However, lono allows them to be reusable since lono dynamically adds them to the template as part of deployment. More details: Lono Configsets