When configuring the AWS cloudwatch agent, you can include in the {instance_id}
inside awslogs.conf
[/var/log/cfn-hup.log]file = /var/log/cfn-hup.loglog_group_name = my-log-grouplog_stream_name = {instance_id}/cfn-hup
Is there a way to do this within AWS::CloudFormation::Init?
Specifically I'm looking to add my Instance ID with the files section
Resources: MyLaunchConfig: Type: AWS::AutoScaling::LaunchConfiguration Metadata: AWS::CloudFormation::Init: config: files: /opt/someconfig.conf: content: | INSTANCE_ID={instance_id} mode: "000644" owner: "root" group: "root"
My work around was to append the INSTANCE_ID
to my config file after the cfn-init
command by running:
echo "INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)">> /opt/someconfig.conf
Is there a better way to do this?