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.