Democratize data access through a self-service Data Platform – Part 1
11 February 2025 - 8 min. read
![Matteo Goretti](https://blog.besharp.it/wp-content/uploads/2021/11/mattteo-goretti.jpg)
Matteo Goretti
DevOps Engineer
#!/bin/bash apt update && \ apt install snapd && \ snap install aws-cli --classic && \ apt install -y apache2 && \ ufw allow 'Apache' && \ INSTANCE_ID="`wget -q -O - http://instance-data/latest/meta-data/instance-id`" && \ /snap/bin/aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --instance-id $INSTANCE_ID --lifecycle-hook-name test-hook --auto-scaling-group-name test-asg --region eu-west-1 || \ /snap/bin/aws autoscaling complete-lifecycle-action --lifecycle-action-result ABANDON --instance-id $INSTANCE_ID --lifecycle-hook-name test-hook --auto-scaling-group-name test-asg --region eu-west-1The User Data is going to install Apache Web Server on Ubuntu 18.04. When the installation is completed, it harvests the instance-id and uses it to complete the lifecycle action with CONTINUE result, which tells to the Auto Scaling group to put the instance into InService state.If anything goes wrong, complete-lifecycle-action command will be invoked with ABANDON result, telling the Auto Scaling group to terminate the instance.Take care of --lifecycle-hook-name and --auto-scaling-group-name parameters’ values used in the configuration script; they should correspond, respectively, to the name of the EC2 Auto Scaling Lifecycle Hook and to the name of the EC2 Auto Scaling group that you are going to create later.Firstly, you have to create a new Launch Template, specifying ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-20190722.1 as the source AMI and the configuration script, described above, as User Data field.Then, you can create a new Auto Scaling group based on the just created Launch Template. During the Auto Scaling group configuration, specify one or more subnets in which the EC2 instances will have internet access to. Otherwise, they will not be able to install Apache Web Server.Before moving on, make sure that the Auto Scaling group’s initial DesiredCapacity and min parameters’ values are set to zero; the initial max parameter’s value can be set to one.Move to the Auto Scaling group’s Lifecycle Hooks tab and click the Create Lifecycle Hook button. Configure the lifecycle hook as illustrated in the picture below.