0

I'm trying to configure CW Agent using packer. I was able to install the CW Agent using packer but however when tried to start the agent it fails to create the image

I know the fact that temporary EC2 instance that packer create during the image creation process does not have necessary iam roles attached which allows to push metrics/logs to cloudwatch. I know that's why it fails to start the agent.

# Install CloudWacth Agent
wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
rm amazon-cloudwatch-agent.deb

But when I add below line to start the CW Agent, it fails to create the image

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-linux -s

Is there any way that I can achieve this? I need to be able to start the agent while setting up the image.

Mahela Wickramasekara
  • 603
  • 1
  • 11
  • 22
  • Installing an agent in a Packer image is normal. Starting an agent is unusual and often problematic. What is the reason for wanting to do this? – Matthew Schuchard Jul 16 '19 at 12:44
  • @MattSchuchard didn't wanted to ssh into the ec2 to started the CW Agent. tried to get everything automated. We have done so with services like mysql, mongodb and elasticsearch, etc. I know CWAgent is different case and there are dependencies. Just trying to see if this is achievable. – Mahela Wickramasekara Jul 16 '19 at 13:35
  • This would be easier and not cause uniqueness issues if you do it with `user_data` in Terraform. Have you considered that? – Matthew Schuchard Jul 16 '19 at 14:06
  • @MattSchuchard No I haven't used that one. it would be great if you could provide some guidance. Also I have a requirement to use different ssm parameters when starting CW agent for each environments we have(dev,qa,prod) for the purpose of having different log groups for each env. much appreciate your help on this Matt! – Mahela Wickramasekara Jul 16 '19 at 17:01
  • Any luck with this? Even I have the same requirement. I was thinking of using aws cli commands inside Packer provisioner, but not sure if it will work or not. – Ven Feb 06 '23 at 11:26

0 Answers0