INSTANCE_ID not available from "runcmd"

Bug #1760460 reported by Eric Dahl
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Wishlist
Unassigned

Bug Description

The AWS-related environment variable `INSTANCE_ID` is not populated within the context of a "runcmd", like it is for a "bootcmd". In "bootcmd", the value is set to the AWS EC2 instance id, as obtained from the metadata endpoint.

I reproduced this with a minimal cloud-init file:

```
#cloud-config

# bootcmd executes during the first boot only
bootcmd:
  - echo "INSTANCE_ID=$INSTANCE_ID" >> /tmp/bootcmd

# runcmd executes these lines during the initial boot
runcmd:
  - echo "INSTANCE_ID=$INSTANCE_ID" >> /tmp/runcmd
```

Tags: aws
Revision history for this message
Ryan Harper (raharper) wrote :

Thank you for filing a bug. Cloud-init does not provide the INSTANCE_ID env variable for runcmd as you say. You may be interested in using the instance-data.json in a jinja template. Please take a look:

https://cloudinit.readthedocs.io/en/latest/topics/instancedata.html#using-instance-data

Changed in cloud-init:
importance: Undecided → Wishlist
status: New → Triaged
Revision history for this message
James Falcon (falcojr) wrote :

instance-data is now the supported way to achieve this sort of behavior. This can be done with:

## template: jinja
#cloud-config

# bootcmd executes during the first boot only
bootcmd:
  - echo "INSTANCE_ID={{v1.instance_id}}" >> /tmp/bootcmd

# runcmd executes these lines during the initial boot
runcmd:
  - echo "INSTANCE_ID={{v1.instance_id}}" >> /tmp/runcmd

Changed in cloud-init:
status: Triaged → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.