How can you install additional packages within your EKS launch template bootstrap script?

Viewed 116

I have this bootstrap script for my EKS node-group launch template and I added in some commands to try to install Apache. I tried a few variations and none would install the service. I'm able to do it manually if I ssh into my nodes, but haven't been able to accomplish it with my script

bootstrap.sh

Variation #1

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"

#!/bin/bash
set -ex
/etc/eks/bootstrap.sh ${cluster_name} \
  --container-runtime containerd

sudo su
yum update -y
yum install httpd -y
service httpd start

--==MYBOUNDARY==--

Variation #2

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"

#!/bin/bash
sudo su
yum update -y
yum install httpd -y
service httpd start
set -ex
/etc/eks/bootstrap.sh ${cluster_name} \
  --container-runtime containerd

--==MYBOUNDARY==--

Variation #3

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"

#!/bin/bash
set -ex
/etc/eks/bootstrap.sh ${cluster_name} \
  --container-runtime containerd

--==MYBOUNDARY==--

#!/bin/bash
sudo su
yum update -y
yum install httpd -y
service httpd start

I also tried with and without the sudo su and none of those worked either. Just seems like the commands aren't running at all

1 Answers

I simply used the below code in the userdata of the launch template & it was never a problem.

#!/bin/bash
/etc/eks/bootstrap.sh your_cluster_name_here
sudo adduser ssm-user
sudo usermod -a -G docker ssm-user
sudo adduser uua
sudo usermod -g wheel uua
sudo sed -i  's/^# %wheel/%wheel/' /etc/sudoers
sudo adduser uub

It's Under EC2 > Launch Templates > (your launch template) > Details > Advanced Details

Screenshot Reference AWS EC2 Launch Template User Data

Related