Search code examples
amazon-web-servicesamazon-ec2aws-cloudformationposthog

When to use Cloud Formation and when EC2 instance


Today is the first day of setting up the cloud environment and I need some clarity here. I am confused as to whether I need to use AWS cloud formation or EC2 Ubuntu instance for setting up posthog. As a prerequisite I need to have Python, Yarn, PostgreSQL and Redis also installed. We will have a small amount of traffic to start with.

Thanks in advance for any input.


Solution

  • From What is AWS CloudFormation?:

    AWS CloudFormation is a service that helps you model and set up your AWS resources so that you can spend less time managing those resources and more time focusing on your applications that run in AWS. You create a template that describes all the AWS resources that you want (like Amazon EC2 instances or Amazon RDS DB instances), and CloudFormation takes care of provisioning and configuring those resources for you. You don't need to individually create and configure AWS resources and figure out what's dependent on what; CloudFormation handles that.

    For example, you can use CloudFormation to deploy an Amazon EC2 instance, selecting its Instance Type, networking properties and disk volumes. You can also provide a script to run when the instance first starts, which might load and configure software on the instance.

    CloudFormation is a great way to deploy such infrastructure in a repeatable manner. For example, you could deploy a Staging environment that exactly matches Production. It enables a 'cookie-cutter' approach to infrastructure deployment and forces the infrastructure to be "documented as code".

    The software packages you describe (Python, Yarn, etc) cannot be provisioned by CloudFormation, unless you provide a script that runs when the instance first starts, and that script does all the install. You would need to write that script. It will probably take a lot of attempts to get the script right, but this is worthwhile if you want to deploy similar infrastructure again in future.

    However, if your intention is to only create one such environment and you have no need to document exactly how to rebuild the environment, then feel free to launch an Amazon EC2 instance and manually install whatever software you want, without using CloudFormation. You could then backup your setup by creating an Amazon Machine Image (AMI), which is a backup of the disks in a manner that 'clones' of the instance can be launched in future.